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.
Shapefile data should not be uploaded to OSM until consideration has been given to making the data topologically correct. If data are uploaded without reviewing for compatibility they may need to be removed to avoid other contributors having to spend many hours making them topologically correct. The mere fact that data are in shapefile format does not mean that they are of high quality (e.g. those describing the PGS coastline lack the fine resolution required by OSM). When adding shapefiles to OSM, specific care should be taken to avoid duplicate node issues.
|Scripted imports and automated edits should only be carried out by those with experience and understanding of the way the OpenStreetMap community creates maps, and only with careful planning and consultation with the local community.
See Import/Guidelines and Automated Edits/Code of Conduct for more information.
Basic: Opening shapefiles in OSM editors
Basic shapefile support has been added to the main OSM editors. When opening shapefiles the attributes are converted into tags. It is highly likely that these will not be suitable for OSM, so care should be taken to remove unwanted tags and apply new tags following the tagging guidelines.
JOSM is able to open shapefiles using the OpenData plugin. The individual files that make up a shapefile must use a common file name and be in the same directory or contained within a zip file. Simply open the .shp or .zip file using File->Open...
To add a shapefile feature to the OSM data, copy from the shapefile layer and paste into the OSM data layer. To switch between active layers use the "Layers" side pane (clicking just to the left of the visibility eye makes the layer active - green tick).
- Note: Only attempt this with shapefiles with a small file size.
It is possible to add shapefiles as a vector background layer in Potlatch 2. To pull a feature through from the background layer to the main map simply Alt-Click (Shift-Ctrl-Click in Linux). Please note the shapefile must use the WGS-84 (EPSG:4326), NAD83, or Ordnance Survey GB projection.
For step by step instructions, see Richard's guide (remember to select "shapefile" rather than "OSM").
Merkaartor has support for reading and converting shapefiles.
iD does not currently support shapefiles
Intermediate: Manipulating shapefiles
To make a shapefile more suitable for adding to OSM, you may first have to manipulate the file.
Shapefiles can be very large (over 100 MB) and include thousands of individual features. Files of this size are not suitable for the regular OSM editors and a subset should, therefore, be extracted before attempting to open in JOSM or Potlatch.
Open the shapefile in QGIS using Layer->Add Vector Layer... (the projection should be automatically detected, if not it can be set via Layer->Set CRS of Layer). Select just the features you wish to keep. This can be done in several ways:
- Select single features or features within a area using View->Select.
- Select features by their attributes (tags) using Layer->Open Attribute Table, where each row represents a individual feature.
Export the selected features using Layer->Save Selection as Vector File... (also allow export to other vector formats and different projections).
Dealing with polygons sharing the same boundary
Polygons (closed ways) that share part of their boundary with a neighbouring polygon can be broken into a net of polylines (ways). This helps when working with administrative boundaries, for example, as it enables us to import polylines between net nodes instead of polygons with overlapping boundaries.
In QGIS (with the GRASS plugin):
- Convert to GRASS Vector Map
Plugins/GRASS/New mapset. Then 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".
- Break Polygons at the nodes where they first diverge
In a tab "Modules Tree/Vector/Toolset for cleaning topology of vector map/v.clean.bpol"
- Export new layer
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.
Advanced: Conversion tools
There are multiple tools for converting shapefiles into .osm format suitable for importing. These include:
- Merkaartor — simply import the shp, export the osm.xml.
- shp2osm (and polyshp2osm) — require some programming skill, but very flexible
- shp-to-osm.jar — less flexible, but requires only a simple configuration file
- shape2osm — a Python script that will convert a POINT shapefile to OSM XML
- ogr2osm (ogr2osm) — a new script to convert any OGR supported vector format into .osm format, with emphasis in converting polygon boundaries into relations
- Using QGIS & GPX Editor to convert to GPX
- 1) Menu "Plugins/ Manage Plugins..." enable ,,GPS Tools".
- 2) Menu "Plugins/GPS Tools/Create new GPS layer"
- 3) Select feature(s) in the default layer. Copy, paste into a GPS tracks layer, save the changed layer.
- 4) In GPX Editor open the gpx file. Menu "Edit/ OpenStreetMap Tools/ Anonymize time".