Using OSRM API, I found the coordinates of the intersections along a route.
I want to know what are the corresponding node IDs.
Is there any API to find the node IDS from the coordinate points?
Is there any API to find the node IDS from the coordinate points?
Yes. You need to pass annotations=nodes as additional query parameter. routes[i].legs[j].annotations.nodes will be an array of OSM IDs that you can use to link the data with OSM.
Linking this to the coordinates in the step is a little bit complicated: You would need to concatenate all RouteStep.geometry and remove the duplicated coordinates (steps[i].geometry[-1] == steps[i+1].geometry[0]).
Related
I'm trying to count how many subway stations each zip code in NYC has. I have the longitudes and latitudes of each station but am wondering how I can relate this to zip codes? Thank you for your help!
Subway Stations on default map
You'll need some spatial data source that contains the boundaries of each zip code, such as a ESRI shapefile, GeoJSON file, KML etc. Tableau's built-in geocoding can display zip code boundaries visually, but they are not accessible for computation (unless you find a way to hack the geocoding files that ship with Tableau)
It should not be hard to find a shapefile of zip code boundaries for NYC.
Once you have that use a spatial join with the INTERSECTS operator to combine the zip code boundary data with your subway station data. If your station data is not in a spatial format, you'll need to use the MAKEPOINT() function in Tableau to convert the latitude and longitude coordinates into a spatial geometry datatype that can be used to specify your join condition.
This sounds like more work that it really is. In the end, the INTERSECTS operator will do all the work to assign each station to the correct zip code.
I'm new to OSM and would like to know if my approach for finding the next intersection ahead is possible when doing it offline.
The goal is to get the coordinates (latitude/longitude) of the next intersection on the street I'm currently driving on. For that I have my actual position (lat/lon coordinates) and heading (w.r.t. the north-pole) at disposition.
My current approach right now is to first use my coordinates for getting the name of the street/way/trace in which I am driving; then use that name for knowing which are the next intersections on that street (to both sides); and then use the heading for knowing which direction is the one I should pay attention to.
Once I have the intersection, I would get its coordinates and continue with the program.
My questions are then, is it possible to do all of that offline, i.e. with a .osm file (or similar)?
And, do you know a better approach for getting the coordinates of the next intersection ahead?
Thanks a lot in advance!
PS. I was able to get the name of the street by using nominatim and to get all the intersections of a street by using Overpass turbo, but this solutions would need internet; or is there a way of using them offline?
I have two Open Street Map node IDs. Is there any API provided by Mapbox or Leaflet which could draw a PolyLine or LineString given the two node IDs?
I am not able to find any reference to OSM IDs anywhere in Mapbox documentation, apart from here and it does not detail how to use the OSM IDs for ourselves to draw lines on the map.
What I want to do is given 2 OSM IDs, I want to highlight the road segment connecting those OSM IDs. I can't go for things like Leaflet routing machine since the number of such lines are too many, with small distances. I can't run routing for all the edges.
Since you say "I can't go for things like Leaflet routing machine since the number of such lines are too many, with small distances. I can't run routing for all the edges." I'm excluding all solutions calling an external routing API, instead you can do your own internal routing.
Use the OSM Overpass API to get the long,lat points for those nodes
In Mapbox GL JS fitBounds to those two nodes and do map.querySourceFeatures to get the roads as GeoJSON LineStrings
then compute a network graph from this and use Dijkstra's algorithm to get the shortest path between your two OSM nodes.
Say I keep getting a set of Geo coordinates from a moving vehicle.
There is a predefined route that the vehicle needs to follow from Point A to Point B.
The route will be defined by giving the user the option to select points A and B and also selecting the WayPoints in between and letting the Google API select the best route.
As the vehicle moves I need to check whether the vehicle has deviated more than 50 m from the predefined route.
My solution (not fully tested)
When the user has selected the start and the end points and the waypoints in between, I can make a call to the Google Directions API which would give me all the points on the road in between
(The polyline property inside the steps gives you the exact points on the road which the UI uses to draw the lines. You can call the following URL to see the polyline response
https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA
)
and store these points in some database (Mongo) with a route id.
When I get the geo cordinates from the vehicle I can make a query to Mongo asking for all those points with the route id and whose distance is less than 50m from the vehicle coordinates. And if there are non then the vehicle has deviated from the route.
Is there a better way of doing this?
How to get the coordinates of the polygon area:
http://wikimapia.org/#lang=en&lat=49.964473&lon=36.262436&z=12&m=b&show=/20421408/Chervonozavodsky-district
You need to use the place.Search function of The Wikimapia API and enter the latitude, longitude and the name of the place as parameters.
The API returns a lot of data separated in blocks. The one you are interested in is the geometry.
You can make tests with the Wikimapia API to filter the results to your needs. With the lat lon parameters and the district name you provided I was able to get the area you needed as the first result.
The places[0].polygon is what you need. A JSON array of coordinates.
HereĀ“s the url I used to get the results:
http://api.wikimapia.org/?key=example&function=place.search&q=Chervonozavodsky-district&lat=49.964473&lon=36.262436&format=json&pack=&language=en&data_blocks=geometry%2C&page=1&count=1
Note that in this example i made the request for a JSON result. But you can also ask for a XML if you prefer.
Hope it helps!