Import/Shapefile

From OpenStreetMap Wiki
Jump to: navigation, search

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.


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 Layers pane

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

Merkaartor has support for reading and converting shapefiles.

iD

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.

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):

  1. 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".
  2. 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"
  3. Export new layer
    Layer->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.


Advanced: Conversion tools

There are multiple tools for converting shapefiles into .osm format suitable for importing. These include:

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".

See also