Hello, Can anyone please help me get the array of boundary coordinates (lat and lng) of a certain location? Attached with this post is an example showing a screenshot that shows the boundary of the district, "Munshiganj" of Dhaka City in Bangladesh. I want to extract the boundary coordinates of this location and other locations as well in a JSON file. My main goal is to get boundary coordinates of all locations of Bangladesh in a JSON file. Thank you. asked 04 May, 09:16 hotmailbelike |
These queries use the Overpass QL language. Please read about. I think that you should run the query once, store the GeoJSON, and extracts the array of coordinates from there. It will be way more efficient that calling the crowded overpass API each time, to get exactly the same data. This becomes a JS (or whatever language you're using) problem, just look at the structure of the GeoJSON file. Otherwise, here is a query that will return you only the coordinates of the nodes of the border of a specific district. Really close, this one returns the geometry of the relation, as an array of coordinates ! The geom keyword is the key here. To combine the first and last approach, you can download all the bangladesh's borders with this query. The result should be easier to use that the first proposition, as the geometry is included is each object. Regards. answered 05 May, 17:34 H_mlet |
You can use Overpass turbo, with this query for example. You can then export in JSON. It's quite hard on the browser, you might want to filter a bit. Regards. answered 04 May, 14:18 H_mlet Thank you, but this query does not return boundary coordinates
(05 May, 07:42)
hotmailbelike
|
Sorry, it seems that comments are unusable... So, to answer your comment, what do you mean by "boundary coordinates" ? The query I gave you display the boundary, so it returns all the necessary coordinates. In OSM boundaries are usually relations, composed of ways, in turn composed of nodes. Only the nodes have coordinates. When you export as GeoJSON, this hierarchy gets flattened. Depending on your needs this can be a good thing or not. Please read some doc about OSM data model. answered 05 May, 16:25 H_mlet |
Yes, but is there a way to get the coordinates of the boundaries instead of the ways and nodes? Or, is there a way to extract the coordinates from the nodes and ways? answered 05 May, 16:37 hotmailbelike |
Of course, just recurse on the members (ways) of the relations, and then the members (nodes) of the ways, and then get lat and lon from nodes. Or as I said, the GeoJSON (and other formats) exports flatten this, so the coordinates of the nodes are duplicated in every relation. Without more context about your application, there's no way to give you a more precise answer to your question. Regards. answered 05 May, 16:45 H_mlet |
I am sorry I don't know very well about how to use the OSM queries. Can you tell me how to recurse the members of the relations and then the members of the ways, and then get lat and lon from nodes? About the application I am working on; I need to get the border as an array of coordinates when user searches for an area answered 05 May, 17:06 hotmailbelike |
Thank you so much @H_mlet ! I have been stuck with this problem for weeks and finally you gave me a lead! Truly, Thank you so much! answered 05 May, 17:48 hotmailbelike |