Software comparison/Import a shapefile

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.

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 our guidelines for imports and our code of conduct of automated edits for more information. Imports/automated edits which do not follow these guidelines might be reverted!

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

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.

Potlatch 2

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

iD

Intermediate: Manipulating shapefiles

To make a shapefile more suitable for adding to OSM, you may first have to manipulate the file.

Filtering shapefiles

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.

Using QGIS:
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 MapPlugins/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 divergeIn a tab "Modules Tree/Vector/Toolset for cleaning topology of vector map/v.clean.bpol"

Export new layerLayer->Save As...

Generalization

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.

Convert Coordinate Reference Systems

We received Shapefiles with Gauss-Krüger coordinates from our municipality which couldn't be handled by the JOSM OpenData plugin (JOSM either displayed nothing or crashed when opening). I could fix it by using QGIS to convert them to GPX files with WGS84:

The tool can convert many layers (represented by many shape files) to one OSM output file.

The tool supports the following geometries: Polygon, LineString and Point. A Polygon will be mapped to a Closed OSM Way, a LineString to a OSM Way and a Point to a OSM Node.

With certain limits the tool can convert geometry types (Polygon to Point, LineString to Point), if so wanted.

The tool supports a flexible Tag generation. The Tag values can be constant or read out of the shape file fields.

SHPtoOSMBoundaries python script. If the SHP contains Administrative Boundaries and you want to transform them into OSM in order to autogenerate and join the multiple boundary relations before importing.