Import/Shapefile
| Scripted imports and automated edits should only be carried out by those with experience and understanding of the way the OpenStreetMap community create maps, and only with careful planning and consultation. See Import/Guidelines and Automated Edits/Code of Conduct |
This article is about importing ESRI Shapefiles into OSM. A shapefile is a popular geospatial vector data format for geographic information systems software. Shapefiles spatially describe geometries: points, polylines, and polygons.
Depending on the origin of the shape file, it may be necessary to not only convert but also simplify the shapes from the shapefile (a.k.a. "generalization") because it has many more nodes than we can actually use. Also shapefile data should not be uploaded to OSM until consideration has been given to making the data topologically correct. If data is uploaded without reviewing for compatibility it may need to be removed to avoid other contributors having to spend many hours making it topologically correct. Duplicate node issues are a significant concern in this respect.
Other shapefiles, e.g. those describing the PGS coastline, lack the fine resolution which we'd like them to have. The mere fact that data is in shapefile format does not mean that it contains high-quality data. Some contain data which was traced from small-scale paper maps.
Conversion to osm format
There are multiple tools for converting shapefiles into .osm format suitable for importing. These include:
- shp2osm (and polyshp2osm) -- require some programming skill, but very flexible
- shp-to-osm.jar -- less flexible, but requires only a simple configuration file
- PostGIS
- convert shp to osm using grass and gpsbabel
- Load the shapefile into PostGIS first, using shp2pgsql (feature of PostGIS) May be helpful as first conversion step
- ogr2osm (ogr2osm) - new script to convert any OGR supported vector format into .osm format, with emphasis in converting polygon boundaries into relations
- Merkaartor has support for reading and converting shapefiles.
- QGIS, GPX Editor and JOSM
- 1) If a shapefile is a polygon it may be better to convert it into a net of lines to import lines between net nodes instead of polygons with overlapping boundaries. In QGIS: ,,Menu Plugins/GRASS/New mapset". Then ,,Menu Plugins/GRASS/Open GRASS Tools". In a tab ,,Modules Tree/File management/Import vector into GRASS/" by v.in.ogr.qgis for example. In a module tab click ,,Show advanced options" and tick ,,Import area boundaries as lines".
- 2) In a tab ,,Modules Tree/Vector/Toolset for cleaning topology of vector map/v.clean.bpol"
- 3) Menu ,,Plugins/ Manage Plugins..." enable ,,GPS Tools".
- 4) Menu ,,Plugins/GPS Tools/Create new GPS layer"
- 5) Select feature(s) in the cleaned layer. Copy, paste into a GPS tracks layer, save the changed layer.
- 6) In GPX Editor open the gpx file. Menu ,,Edit/ OpenStreetMap Tools/ Anonymize time".
- 7) In JOSM install JOSM/Plugins/Reverter just in case. Open the gpx file.
See also
- Running the coastline upload for a description on how to process PGS shapefiles into coastlines.
- John Reiser's Export_to_OSM.py script is an ArcToolbox script that allows ArcGIS users to save feature classes (and shapefiles) as .OSM files.
- Andy Ayre's blog describes using "GPS TrackMaker" to create a .osm file
- WikiProject Corine Land Cover/Corine Data Import