Creating an extract of a city in Openstreetmap

I have been rendering maps of my local city [Cleveland, Ohio] recently. Because of Cleveland’s administrative borders, I had to extract the city of Cleveland using a large bounding box that included a lot of data outside of the city of Cleveland. As a result, I had to manually remove many ways and nodes (via josm) outside the city’s borders before I later used this data within the city’s boundaries for rendering in osmarender, and as a postgis db in tilemill and mapnik.

To automate this, I had been looking to create an extract of my city (and hopefully to be able to replicate this with other cities). This extract would only contain data within the city’s administrative boundaries.

I found a similar project to mine, The Extractotron – which is a great project, but its extracts are for cities including areas outside a city’s administrative borders.

UPDATE: March 2013; I finally figured out how to do this:

(this tutorial expects that you know OSM pretty well, how to use osmosis, and that you’re running OS X or linux).

1. Obtain the id for the relation of the boundary. (You can do this in josm by clicking on the boundary and then press cntrl + shift + i).

the way that is displayed in the webpage IS NOT the entire boundary for the city, it’s only a part of it. Instead, go down to the bottom of the new webpage and find “Part of: Relation: Name (THISID####)”

2. Obtain the .poly for this file. There’s multiple ways to do this, I find overpass, although powerful, the server can be overloaded, so I use this tool…

2A] Open this great tool by jocelyn.

Enter in the relation ID that you just found. Click, boom. Click Poly.

new window will appear, copy its contents into a new file, name it whatever you’d like with .poly at the end. for example, summit.poly

Use this polygon for the –bounding-polygon file=nameofyourpolygon.poly parameter in osmosis.

For example, if you just want the administrative boundaries within that area, you could you do:

osmosis --read-pbf file=ohio.osm.pbf --bounding-polygon file=summitcounty.poly --tf accept-ways boundary=administrative --used-node --write-xml summit.osm

or generally, if you want everything within it, do: osmosis --read-xml file="planet-latest.osm" --bounding-polygon file="county.poly" --write-xml file="australia.osm"

Voila, you’re done and have your OSM file.
(This is my old, original post and I left it up for posterity).

I have unsuccessfully tried the following:

1] Created an extract that contains the administrative borders of my city in its entirety from a larger extract (in my case, my state) from geofabrik

bzcat ohio.osm.bz2 | osmosis\

–read-xml enableDateParsing=no file=-\

–bounding-box top=41.606 left=-81.88 bottom=41.3903 right=-81.5323 clipIncompleteEntities=true –write-xml file=-\

| bzip2 > extracted.osm.bz2

2.] Filtered the extract again in osmosis to only contain the administrative boundaries [and highway motorway link as a reference for me]

Specifically I did:

osmosis –read-xml extracted.osm –way-key-value keyValueList=”highway.motorway_link,boundary.administrative” –used-node –write-xml entireclevelandboundingbox.osm

4. Opened the file in josm, selected the multipolygon that consisted of the city’s administrative boundary, and then right-clicked on it, Selected Members, and copied it to a new layer

5. In the new layer, Removed the tags from the city’s boundaries and then combined all of them into one single way [in one direction] and saved it as a new osm file.

6. Used osm2poly to create a polygon:

perl ./ clevelandboundaryonly-dell.osm > clevelandboundaryonly-dell.poly

polygon can be found:

7. Use the polygon as the boundary from the first large extract [from the state of ohio].

bzcat ohio.osm.bz2 | osmosis\

–read-xml enableDateParsing=no file=-\

–bounding-polygon file=clevelandboundaryonly-dell.poly clipIncompleteEntities=true –write-xml file=-\

| bzip2 > extracted.osm.bz2

An example of these broken boundaries can be can see in a screenshot of josm at

In this screenshot, the underlying gray line is an inactive layer in josm and the same OSM file that I used to create the polygon in Step 5. The

administrative boundary, shown as orange dashed line in the screenshot, is from the extract in step 7 and should be over the gray line.

Although we were unsuccessful, thank you to stereo in #osm for troubleshooting this with me yesterday.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s