Data-joins with Mapbox free country Boundaries - mapbox

I'm trying to style MapBox countries based on a specific rating that varies from 1-5. So the idea is to use that rating to set a different colour for each rating:
MapBox.map.addLayer({
id: 'country-layer',
type: 'fill',
source: 'countryTiles',
'source-layer': 'country_boundaries',
paint: {
'fill-color':
[
'match',
['get', 'travelRiskRating'],
1, '#90C388',
2, '#D3B446',
3, '#F0682B',
4, '#F22F2F',
5, '#741106',
'#5FE9D0'
]
}
})
So basically to achieve it I would need to use the setFeatureState(link) function to add that property to the source feature (country). This is a concept described by MapBox as Data-Joins and it's really well described in their tutorial.
As described in the tutorial:
Using feature state requires knowing the unique feature id property for each boundary in the vector tiles to manipulate its rendering. In the Mapbox Boundaries lookup tables, feature_id is this unique integer-only identifier.
Also in the Feature lookup tables it says:
The Mapbox Boundaries lookup tables are JSON and CSV files that are
delivered to you when you buy access to Boundaries. They provide extra
information about features that is not directly available in the
vector tiles.
So, it's nice to know that this extra data will come with other boundaries when I buy them, the problem is that the country boundaries (mapbox.country-boundaries-v1) are free and there is no way to find that feature_id. I've searched everywhere and tried many ways to somehow give an additional value to the country feature without success. The best I could achieve was to somehow log the features of the countries that come with the boundaries (thanks to this post), just to discover some id (of the feature?) to be equal to undefined
I wonder if I'm missing something, how to get it, or achieve what I'm trying to achieve. I wonder if this feature_id or lookup tables are provided already somewhere, or will be provided if I pay for this "free" version of country boundaries?
I will appreciate any help or clarifications here.

Related

Tableau Map Report

I am working on creating a map sales report to show the sales by product for various territories. The territories are based upon zip codes and are custom territories that overflow into multiple states or are partially in a state. I have gotten everything set up and it looks good for the most part...EXCEPT 2 areas.
1.) one of the sales numbers shows up in Alaska which is not viewable if a user is zoomed in on the USA (we are US-based so it's only relevant to show anyways). Is there a way to force a sales number to show up on a user-defined location? For instance, can I show this on the State of Washington instead of Alaska or can it only default to the largest (area) part of a user-created territory map?
2.) being that we are US-based is there a way to move the states Alaska and Hawaii closer to the US? I know that utilizing the dashboard is a workaround, but it does not look good.
I'm not sure this could be a complete answer, but I think this question has more than one take.
That being said, if your worksheet is based on zip codes in order to create a map, I don't think you can force Tableau to visualize data out of their original position based on the specific geographic role.
The only thing that come to my mind is switching your approach from geographical role (country, state, city, zip, etc) to a more generic lat/long coordinates.
Doing so, you can manually match your Alaska zip codes to lat/long more "continental" areas.
Anyway this would require a lot of data manipulation prior to Tableau.
An alternative way of accomplish something similar to what you say in your second point could lead you to use 3 seperate worksheets in a single dashboard: continental, Alaska, Hawaii.
I did something on US data and I was facing the same problem for Hawaii, so I decided to use a floating worksheet putting it on the bottom left corner of the continental map.

How to plot a JSON file generated by osrm for route optimization into an OSM map

I am a complete newbie to computation of gps, gis and all these geoinformatical stuff. First I describe my lessons learned to arrive at gps data. You can skip this and go to the last two paragraphs where I explain my problem with osrm and how to map a route onto an OSM map via qgis or similar tools.
I tried to do some route optimization for a bunch of addresses to support my son's paper deliverer job. I was able to generate a list of gps data by using the Nomatim engine that is available via geopy.geocoders. It's kind of a Travelling Salesman problem (TSP).
By using geopy's distance calculator and the or-tools from Google to Generate a shortest list recommendation. That worked well but it was only a TSP solution for air line :-(.
Then I was looking for route optimization toolkits but i struggled to get one for free. I thought osrm could be the right tool. I followed the descriptions given at Github, see here. I was able to generate a JSON file - at least I supposed that it's kind of a JSON file. But I was unable to project this back onto a map in QGis or any online tool from OSM. Can anyone help me?
The file with such JSON-like formatting:
{"code":"Ok","waypoints":[{"hint":"Jh4BgEUzI4BhAAAACwAAAKIAAABZAAAAkLAjQgpyikBay4dCWsuHQmEAAAALAAAAogAAAFkAAAArAAAAxwB4AARI3AI3AXgAWEbcAgIADwXVhXd1","location":...
Due to privacy issues I cannot post it here with any locations. Sorry for this. But does anyone have kind of a recipe / step-by-step guide what I need to do to plot it? I even have no idea how to "open" a map within qgis. You need to do this as kind of a database but this is totally new for me. I would prefer to work with an easier method to plot it.
Thanks in advance for any help.
Please follow the API documentation here. From that documentation
hint Unique internal identifier of the segment (ephemeral, not
constant over data updates) This can be used on subsequent request to
significantly speed up the query and to connect multiple services.
E.g. you can use the hint value obtained by the nearest query as hint
values for route inputs.
You can get the geometry in many ways. Widely GeoJSON is being used by developers. OSRM returns a very clean GeoJSON which can easily be used with Leaflet, Mapbox or other Map APIs. You need to send steps parameter true to get the full step by step direction. You can get the each segments of steps in legs. So call the GeoJSON within the geometries of every legs with loop. You can also get the geometry without passing the steps parameter true. For that you will get full geometry in a single GeoJSON within the routes property.

Meaning of the spatialite scheme generated by the spatialite_osm_map tool

I used the spatialite_osm_map tool to generate a spatialite database from an .osm.pbf file. After the process was finished, a series of tables were generated in the database as shown in the image.
I noticed that there were 3 groups of tables based on the prefixes of their names: In_, pg_ and pt_. I also noticed that the rest of the name corresponded to a key defined in OpenStreetMap.
Can someone explain to me how the information is distributed in each of these groups and tables? I've searched for a site that explains the resulting schema after the conversion, but I've only found information on how to use the tool.
I think you have already identified the key points of this scheme.
It's main purpose is to offer the data from OSM in a way who could be more direct and intuitive for a GIS user. The data is splited according to OSM tags (aerialway, aeroway, amenity, etc., you can change the list of tags to be used if you don't need all of them) and according to the type of geometry (pt_* for points, ln_* for lines, and pg_* for polygons) so these tables (which could be directly seen as "layers" by a GIS user) can quickly be styled (for example in a GIS desktop application such as QGIS) with simple rules due to this simple schema (for example one can set rules like green for pg_natural, blue for ln_waterway and pg_waterway, or just click on the "pg_building" layer to toggle its visibility). That schema doesn't preserve all the objects from the OSM database, but only those requested to build the tables for the requested tags.
Contrary to the original way of storing OSM objects, with this kind of extraction you will lose the relationships between objects (for example in OSM the same node can be used, let's say, as part of the relationship describing an administrative boundary and as part of a road; here you will get a road line in ln_road and a polygon in pg_boundary but you will loose the information that they were maybe partially sharing nodes). Notably due to this last point, the weight of the OSM extractions can be relatively high compared to the original file.
So I guess that this kind of scheme (which is one amongst other existing ways to transform OSM data) offers an interesting abstraction for those who are not accustomed to the OSM schema which use Node, Way and Relation elements (eg, in OSM, buildings can be represented as closed way or as relation, here you get "simply" polygons for these various buildings).

How can i find certain types of buildings in OpenStreetMap?

i'm trying to make a list of all the police stations that are in OpenStreetMap.org so i can compare it with mine (a full one with all the police stations in the country) and add the ones that are not there. at the moment i'm doing it one by one, searching from my list and if it is not in the map i add it. but i want to now if there is a way to make the map show me all the police stations that are in a country or a region. if someone who knows about OSM could help me that would be great
To find the policestations you can use e.g. OverPass-API (I recommend TURBO). The more complex way is to use the planet.osm dump / extracts and process it using filterers (e.g. osmosis). Last one is more complex, but allows you to controll the area more precise.
Please be aware that building is the wrong feature. Some mappers prefer to map the amenity / usage as a seperate POI and some policestations are mapped as are for the whole site of the station. Be also aware that the community is skeptical about imports and quality of external datasets.
You can use e.g. Overpass to query OpenStreetMap for features. Here is the query that you need to retrieve all police stations.
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“amenity=police”
*/
[out:json][timeout:25];
// gather results
(
// query part for: “amenity=police”
node["amenity"="police"]({{bbox}});
way["amenity"="police"]({{bbox}});
relation["amenity"="police"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
You can run the query with Overpass Turbo, here. First position the map over the area you are interested in, then press "Run".
You can use any of the export options to download the results, instead of viewing them on the map
I forgot to mention that a police station is not really a building type in OpenStreetMap, it is considered an amenity. More information about the correct tagging can be found on the OpenStreetMap wiki, but this system does not allow me to post more links to help you further.

Tiled OSM's - find the bounds of given city/state

I used the overpass api to downloaded a couple of tiled pieces of USA's map and now that I have the USA map locally, I would like to obtain the bounds of a given city (or state) without involving the API.
Should I search for certain tags, or relations? I assume I'll have to start from a node tagged (k=name, v=city_name) and (k=place, v=city), and based on it's id to find a way node.
Is my assumption correct? If yes, can you give me some directions on what should I look for once I have the node corresponding to the city?
Note. I went through the OSM wiki and studied a little bit the OSM XML format, however I was not able so far to have a whole picture of the OSM XML structure, so perhaps someone who has more experience with this can help me.
Administrative boundaries are mapped as ways or relations with a boundary=administrative tag. The boundary type is specified by an admin_level. The admin_level value for cities differs from country to country and can even include multiple values. But for most countries, admin_level values for cities range from 6 to 8 (for the US it starts even from 5). In contrast, US states have an admin_level of 4. With the help of these keys you can construct a Overpass query for specific cities/stares, or even query for all cities and states. Here is an example for Denver:
[out:json][timeout:25];
// gather results
(
way["boundary"="administrative"]["admin_level"~"6|7|8"]["name"="Denver"];
relation["boundary"="administrative"]["admin_level"~"6|7|8"]["name"="Denver"];
);
// print results
out body;
>;
out skel qt;
You can see that it will yield multiple results. Look at the place and admin_level tags to determine the importance of your results.
Alternatively you can use a geocoder as for example Nominatim. Here is an example for Denver. In contrast to Overpass API, Nominatim will weight the results by importance. It also supports multiple output formats and can return polygons (which you can use for determining the bounds). Please read about Nominatim's usage policy when using the instance at nominatim.openstreetmap.org.
And also see search engine results.