Interesting Tech Projects
Getting US Government Shapefiles Into OpenStreetMap
I recently embarked on the process of adding the shapefiles for Region 3 of the US Forest Service into OpenStreetMap (OSM). This post describes the method I used. First a bit of background.
OSM is a free street level map of the world. Just like Wikipedia is a encylopaedia that anyone can edit, OSM is a map that anyone can edit. The data is licensed under Creative Commons by attribution, which is a very liberal license.
In the US currently most of the data came from a mass import of the US Government’s TIGER data. This data has numerous problems, such as streets being in the wrong places and regions like forests are missing completely.
Fortunately some regions of the US Forest Service make good quality shapefiles available of the forest boundaries and I live in one of those regions – the Southwestern Region. It’s just a matter of converting the shapefiles into the correct format, adding some descriptions and uploading them to the OSM server.
There are several challenges with getting the data into OSM. Firstly the shapefiles are in the Lambert Conformal Conic projection, which is not what OSM uses. Secondly OSM doesn’t use Shape Files, it uses it’s own XML data format. Thirdly the data has to be “tagged” in the correct way for the forests to be rendered correctly. This becomes more complex if there are holes in the forest.
The first stage is to find the shapefiles and what projection they are in. In my case the US Forest Service provided the projection information with the data files. I then reprojected the data and converted to a OSM file format using the following steps:
- Open the shapefile in MapWindow GIS
- Use the GIS Tools menu to reproject the data to WGS84
- Save
- Open the reprojected data in GPS TrackMaker
- Save as GPX file
- Use GPSBabel to convert from GPX to OSM
gpsbabel -i gpx -f smallpiece.gpx -o osm -F smallpiece.osm
Currently the best editor to use for OSM is JOSM. This is a Java application that allows data to be added, edited, deleted and tagged. Don’t use the default memory allocation, instead allocate more using:
java -jar -Xmx256M josm-latest.jar
There are some essential plugins that are required. Install utilsplugin, validator and waydownloader. Here are the steps I used to edit and tag the data. There may be mistakes, so use at your own risk.
- Open in JOSM
- Simplify using Shift-Y
- Select all nodes in a single ring (closed loop) and choose Combine Way
- Select all outer ways
- Add way tags (see below)
- Select all inner ways and delete all tags
- Select all ways with no holes
- Create a relation
- Add the selected ways to the relation
- To the left of the way in the dialog window set the role to “outer” for all ways. Click on each way to see which it is on the map
- Add the tags for the relation (see below), setting the type to “boundary”
- Select each way with holes in turn, along with the holes
- Create a relation
- Add the selected ways to the relation
- To the left of the way in the dialog window set the role to “outer” for outside rings. Set the role to “inner” for inside rings.
- Add the tags for the relation (see below), setting the type to “multipolygon”
- Split large ways into smaller ways of 2,000 nodes or less
- Validate and fix errors. Ignore warnings about unclosed ways.
The tags I use for ways are:
- uuid: username_yyyymmddn
- attribution: US Forest Service
- boundary: national_park
- landuse: forest
- leisure: nature_reserve
- name: Coronado National Forest (example)
- wood: mixed
The tags I use for relations are:
- uuid: username_yyyynnddn
- name: Coronado National Forest (example)
- landuse: forest
- type: multipolygon (when there are holes)
- type: boundary (where there are no holes)
- boundary: national_park
Do not add tags to inner ways or the nodes. GPSBabel automatically adds tags, so delete those.
The uuid’s are a unique identifer that I can use to search for this particular set of data later, if needed. It is constructed from my OSM user name, the date and the upload number for the day. For example:
FooBar_200907104
would be the fourth upload for July 10th 2009 by the user FooBar. I use this scheme because I can work out the uuid’s from just an upload date and it is very unlikely that someone else would use the exact same uuids.
Print article | This entry was posted by Andy on July 10, 2009 at 10:28 am, and is filed under Mapping. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.
about 15 years ago
Interesting stuff. I’ve linked this blog post from here: http://wiki.openstreetmap.org/wiki/Shapefiles …so far we dont have much information on shapefile->osm conversion
I guess landuse polygons are a relatively simple type of shapefile to make use of. Going via GPX is a sneaky solution!
about 14 years ago
I had no idea gpsbabel could ouput to OSM format! That makes things much simpler for importing from external data types. Thanks!