Update:
Here's how to obtain all of the OSM data within your city's boundaries. This assumes you are a linux or Mac OS X user and have JOSM and [osmosis](http://wiki.openstreetmap.org/wiki/Osmosis) installed.
1. Download an extract of your state or country. Geofabrik posts extracts for each US state and Canadian Province on a [http://download.geofabrik.de/north-america.html](daily basis).
2. Obtain the OSM_id for the relation of your city's boundary. I do this by downloading a small area of my city and its border in JOSM, selecting part of your boundary, and then pressing cntrl + shift + i). This will open a new window in your web browser containing the tags for a portion of your boundary.
Now the way id that you brought up IS NOT the entire boundary for the city, it's only a part of it as ihighlighted in the map. You need the osm_id for the city's entire boundary. You can obtain this by going to the bottom of that webpage and find "Part of: Relation: Name of the city (THE_OSM_ID)" This is the_OSM_id of your city's entire boundary. For example, "Relation Cleveland (182130) (as outer)" Copy this You will need it for Step #2.
3. Obtain the .poly for your city's entire boundary. I prefer to use this tool by Jocelyn at http://osm102.openstreetmap.fr/~jocelyn/polygons/index.py
Paste in the THE_OSM_ID from step #1 into the uppermost text box and hit enter.
In the new window, right-click and save the .poly file and choose whatever you'd like.
This will new window will appear, copy its contents and choose its file name, name.poly
4. Use osmosis to filter out the administrative boundaries.
osmosis --read-pbf file=ohio-latest.osm.pbf --bounding-polygon file=cleveland.poly --used-node --write-pbf cleveland.osm.pbf
Customize the command above to the your file names. Make sure that the poly file is in the same directory as your PBF extract.
If you have a very small town and want to examine the data in JOSM first, you can
osmosis --read-pbf file=ohio.osm.pbf --bounding-polygon file=cleveland.poly --used-node --write-xml cleveland.osm
Voila, you have your extract :)
==========================================================================
Original post test, kept for posterity.
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 mapbik.
To automate this, I have 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,
https://github.com/migurski/Extractotron The Extractotron - which is a great project but its extracts are for cities including areas outside a city's administrative borders.
I have unsuccessfully tried the following:
1] Created an extract that contains the administrative borders of my city in its entirity 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.
http://dl.dropbox.com/u/17003223/clevelandboundaryonly-dell.osm
6. Used osm2poly to create a polygon:
perl ./osm2poly.pl clevelandboundaryonly-dell.osm > clevelandboundaryonly-dell.poly
polygon can be found:
http://dl.dropbox.com/u/17003223/clevelandboundaryonly-dell.poly
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
http://dl.dropbox.com/u/17003223/extracted-dell.osm
This last osm file results in administrative boundaries are broken and incomplete.
An example of these broken boundaries can be can see in a screenshot of josm at http://i.imgur.com/Tw8Ba.png
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.
Any idea why the boundaries are broken in my new extract ?
Although we were unsuccessful, thank you to stereo in #osm for troubleshooting this with me yesterday
Location: