NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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.

image
img photo hosting

My main goal is to get boundary coordinates of all locations of Bangladesh in a JSON file.

Thank you.

asked 04 May '20, 09:16

hotmailbelike's gravatar image

hotmailbelike
16113
accept rate: 0%

edited 05 May '20, 07:43


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.

permanent link

answered 05 May '20, 17:34

H_mlet's gravatar image

H_mlet
5.4k1781
accept rate: 13%

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.

permanent link

answered 04 May '20, 14:18

H_mlet's gravatar image

H_mlet
5.4k1781
accept rate: 13%

Thank you, but this query does not return boundary coordinates

(05 May '20, 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.

permanent link

answered 05 May '20, 16:25

H_mlet's gravatar image

H_mlet
5.4k1781
accept rate: 13%

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?

permanent link

answered 05 May '20, 16:37

hotmailbelike's gravatar image

hotmailbelike
16113
accept rate: 0%

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.

permanent link

answered 05 May '20, 16:45

H_mlet's gravatar image

H_mlet
5.4k1781
accept rate: 13%

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

permanent link

answered 05 May '20, 17:06

hotmailbelike's gravatar image

hotmailbelike
16113
accept rate: 0%

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!

permanent link

answered 05 May '20, 17:48

hotmailbelike's gravatar image

hotmailbelike
16113
accept rate: 0%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×144
×129
×28
×4

question asked: 04 May '20, 09:16

question was seen: 3,659 times

last updated: 05 May '20, 17:48

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum