Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting city boundaries from openstreetmap

I'm developing a website and I need to get all the boundaries of an area given depending on the user input. For example, the user want to know the boundaries of a city named x. How should I get it from openstreetmap? I've heard of xapi and osmosis but couldnt find any examples anywhere. Thanks!

like image 398
marey Avatar asked Mar 27 '13 12:03

marey


People also ask

How do you extract data from an OpenStreetMap?

Go to openstreetmap.org and zoom to the extent of your area of interest using the search box or the mouse. Click on Export Data in the sidebar on the left to bring up the Export pane. If you are satisfied with the visible extent, click Export.

Does OpenStreetMap have an API?

OpenStreetMap has an editing API for fetching and saving raw geodata from/to the OpenStreetMap database — this is the entry page for the documentation. If you just want to embed a map into a webpage, you don't want this API. Use a web map library instead.

What data is available in OpenStreetMap?

OpenStreetMap represents physical features on the ground (e.g., roads or buildings) using tags attached to its basic data structures (its nodes, ways, and relations). Each tag describes a geographic attribute of the feature being shown by that specific node, way or relation.


1 Answers

I took a stab at doing this with JavaScript here: https://github.com/pgkelley4/city-boundaries-google-maps

Basically it comes down to finding the relation that OpenStreetMap stores the city boundaries as.

I used something like the following query to get the area:

area[name="Seattle"]["is_in:state_code"="WA"];foreach(out;);

Or if that doesn't find anything, going through the node to find any associated areas:

node[name="New York"][is_in~"NY"];foreach(out;is_in;out;);

To get the relation ID, subtract 3600000000 from the area ID returned by the above queries. Then get the relation from its ID:

(relation(" + relationID + ");>;);out;

You can test out queries here, mine could probably be improved on: http://overpass-api.de/query_form.html

That is how to get the city boundaries, processing them is another matter as nothing is in order within the relation. For that see my GitHub project and: http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm

Also I would note that the OpenStreetMap data for city boundaries is spotty. It is missing for big cities like Dallas and LA from what I can tell.

like image 170
pgkelley Avatar answered Sep 21 '22 17:09

pgkelley