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

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.

Related

How to clean up *.osm.pbf files (Removing unwanted nodes, relationships, ways) with osmosis or osmium

I've recently began to dig deeper into manipulation raw osm data and later convert them to *.mbtiles to serve vector tiles to my web application. As the map only needs to be of low detail (is mainly used for displaying aviation data), I don't need buildings but want to keep some details (parks, airports, waterways etc. for aesthetic reasons).
So far I've tried using osmium and osmosis with okayish results. It still takes forever processing just one country (I'd need the whole of europe for now).
Removing buildings in osmosis produces a smaller file than in osmium? Probably my settings are wrong. Maybe there's even an other tool which might be better for the job?
Can you please point me in the right direction? I think having streets, water, airports placelabels and parks/forests present would be sufficient for now.
So far I've tried it with the commands below which still takes forever to import with openmaptiler in a c4.large instance on aws.
osmosis --read-pbf germany.osm.pbf --tf reject-ways building=* --used-node --write-pbf germany-wo-buildings.osm.pbf
My second approach was using osmium
osmium tags-filter -i germany.osm.pbf nrw/building=* -o germany-wo-buildingsg.osm.pbf
I'd really appreciate some help here to get a better understanding of working with osm data.
Thanks a lot!

Mapbox: Is there a way to retrieve all coordinates for a specific feature ID?

I'm building a feature where I need to extract all coordinates of a selecetd road/path in Mapbox when it's clicked on. I've attempted to use the queryRenderedFeatures method, but it seems the result list is fragmented. By "fragmented" I mean that if you have a road or path which is clearly just one long path/road when rendered on the map, it often consists up of 4-5-6 or more features, and you cannot really work out from the feature collection how they're supposed to be connected (in order)
I then tried to use the Tilequery API, but it doesn't return any coordinates for LineStrings.
Is there any API - server or client side - in Mapbox, where you can provide an ID of a feature and retrieve the all coordinates for a road or path?
Thanks in advance :-)
I think you're really asking: "is there a way to access complete LineString features for data in Mapbox's tilesets", to which the answer is, no, not really - other than trying to reassemble them in the way you have tried.
For your own data, you could host it using Mapbox's Datasets, rather than Tilesets.

Accessing nested properties of a TileSet

I am trying to access all the features of a specific tileset generated threw MapBoxStudio.
Reading the API doc I guess I should be able to get all the nested parameters from the method :
map.querySourceFeatures(IdOfMyLayer);
However, the output of this is empty.
map.querySourceFeatures('words');
Where 'words' is the ID of the layer I got from map.getStyle().layers
I would expect to get access to the properties of this particular layer.
However, I get an empty result.
Sorry for the noob question but I am missing something crucial here in the way MapBox is working, any help from you would be very much appreciated.
If you are trying to access all the features of a tileset that you created in Studio, you should probably consider a different workflow. By definition, a tileset is a transformation of a dataset optimised for displaying a map, not querying.
If you use a Mapbox dataset rather than a tileset, you can access the whole dataset as a clean GeoJSON object - assuming it's small enough to load into the browser. Alternatively, you could create a GeoJSON by some other means, then upload it.
If querySourceFeature() is returning [], then most likely no features have loaded in the current viewport (yet). Perhaps you need to trigger the call at a later time, when the source data has loaded.
I get it now.
The proper way to retrieve all the features of a dataset is to use the DataSet API:
https://docs.mapbox.com/api/maps/#retrieve-a-dataset
This is what I've done :
$.ajax({
url: 'https://api.mapbox.com/datasets/v1/*****/{dataset_id}/features?limit=50&access_token=********',
type:'GET',
success:function(data){console.log(data)},
error:function(error){console.log('ERROR')}
})
With the {dataset_id} taken from mapboxStudio.
I can limit and store the variable to process the JSON response.
Thanks a lot :)

Routing network from OSM

I'm looking for some good tool to import map.osm to postgres and next create some routes which will be displayed by geoserver. I need route, with some text information about vertexes (e.g. city, address, address number, and so on...)
I found this:
osm2pgrouting - Import OSM data into pgRouting Database
osm2postgis -Import OSM data to PostGIS
osm2po - tool to convert OSM data into a routable format
osm4routing - OpenStreetMap data parser to turn them into a nodes-edges adapted for routing applications
I do not have many experiences with GIS, so how tool is the best for me? I try osm2pgrouting, but in result I have tables, which do not contains data about vertexes(only lat. and alt.) Thanks for answers.
UPDATE App Info:
I will be have web and android client where user enter text value of start and end node, and next over geoserver get wms with vertexes of entered route for example
My result from could be be some edges and nodes like this like this:
sequence_num, edge_distance, and informations about edge vertexes like osm_id, some text value, lat alt, etc...
I think you have a lot of work to do before you get to a complete solution, but here are some pointers. I suggest you break down your project into smaller chunks and ask specific questions on any bits you might get stuck on.
First, you need to import your data. Then you'll need some pre-processing / cleaning. Then you need your routing queries and, finally, a way to use the outputs (with this last part determining to some extent the previous steps).
Import OSM data
As I described in an answer to your previous question here, you can use OGR2OGR to import OSM data to Postgis. You can use other programs, as you mention above, but I guess you'll get much the same results. I think the difference between the OGR2OGR tables and the osm2postgis ones is that some of the columns in the latter appear in the other_tags column. However, the data is still there, you just need slightly different queries.
Preparing data
I'm assuming you'll use pgrouting for the routing, but whatever you use, you'll need a network suitable for routing (in short, the edges have a start and end node, and the end nodes must connect with other start nodes). Pgrouting has tools to create what you need and validate it. E.g. you create integer columns source and target and the function pgr_createtopology will populate the columns for you.
OGR2OGR gives you tables "lines", "points", "multipolygons", "multilinestrings". I suggest you read up on OSM to understand exactly what is in these tables, but, roughly speaking, the lines contain your roads and the multipolygons contain, amongst other things, buildings with e.g. addresses. The addresses are in a hstore column called "other_tags".
The lines do not contain addresses! (although they do contain street names). So, if you want to do address-to-address routing you need to do some preparation. You can skip this if you can live with the street names.
Create your network (e.g. if you're routing for cars, you'll want to
throw out pedestrian routes and so on)
Extract the desired addresses (including coordinates)
Either snap the addresses to the nearest node, or otherwise
relate the address to the nearest node
Pgrouting will return the edges in your route, so you need the above to relate back to your addresses.
Routing
Your app is going to send to your server (in an as-yet unspecified way) a pair of addresses or coordinates and you need postgis to return the route. With pgrouting, that's quite easy and there are plenty of examples out there, for example here. You will need to write queries that join the output to your address table to give you the desired output.
pgrouting creates a vertices table. You can get the nearest vertex with the following query:
select id from vertices_pgr
order by the_geom <-> st_setsrid(st_point(lon,lat),4326)
limit 1
Using the output
Using WMS from geoserver is unlikely to be a good choice - you won't have the information on individual edges without a lot of messing about. You might consider geoJSON, which can be read by e.g. OpenLayers, Leaflet, or you can manipulate in Javascript. Postgres has lots of useful functions for working with json and geojson.
Conclusion
That's quite a lot of work and probably new stuff if you have little GIS knowledge, and it, er, basically recreates what you'd get from Graphhopper! Are you sure that's not a better way to go?
If you do decide to go this (or similar) route break things down into manageable chunks! First, figure out exactly what you're trying to achieve, then work backwards from there. If you do decide to use OSM / pgrouting, then play with the data and pgrouting first so you understand how it works before trying address matching etc.
The tools you listed are only for producing data, but I think you actually need a routing engine.
Try Graphhopper: https://graphhopper.com
Using the WEB Api (more likely what you need), you don't need the import the data in your database. This is the easiest solution. You will have not control over the input openstreetmap data but this is fine if you don't have special requirements.
Import data and implement/integrate a routing engine directly in your application would be much more complicated.

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.