Converting/shp to osm using grass and gpsbabel

From OpenStreetMap Wiki
Jump to navigation Jump to search

two merging arrows

It has been proposed that this page or section be merged with Converting map data between formats. (Discuss)

exclamation mark

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. Imports/automated edits which do not follow these guidelines might be reverted!

Required software:

In this example, the used files are stored in "C:\OSM\SHP\": kommunal.shp, kommunal.dbf, kommunal.sbn, kommunal.sbx, kommunal.prj.
"kommunal.shp" contains a street-network with very high accuracy - JOSM couldn't handle this...

Generalisation using GRASS:

Main article Simplifying OSM Shapefiles using GRASS (merge?)

  1. Put your shapefile including all belonging data (dbf etc.) to a fixed directory.
  2. Switch to command-line (start - run - cmd).
  3. Switch to GRASS-binary directory, e.g. cd C:\GRASS\bin\
  4. Remove possible existing maps (be careful): g.remove vect=OSM
  5. Load the shapefile to a GRASS-map: v.in.ogr -o dsn=C:\OSM\SHP\kommunal.shp out=OSM
  6. Reduce the amount of nodes: v.generalize input=OSM output=OSM_douglas_reduction method=douglas_reduction threshold=0 reduction=50 -c
  7. Write a new shapefile: v.out.ogr input=OSM_douglas_reduction dsn=C:\OSM\SHP\reduced olayer=kommunal_reduced
  8. Remove the GRASS-map: g.remove vect=OSM

Conversion to .osm using GPSBabel

  1. Switch to GPSBabel-binary directory, e.g. cd C:\GPSbabel\
  2. Check the shapefile's databse for street-names or other important data: gpsbabel.exe -i shape,name=? -f C:\OSM\SHP\reduced\kommunal_reduced.shp
    • Here, STR_NAME contains the name of the streets. (This may not work if the field name is "name"?)
  3. Write an OSM-file: gpsbabel.exe -i shape,name=STR_NAME -f C:\OSM\SHP\reduced\kommunal_reduced.shp -o OSM -F C:\OSM\SHP\reduced\kommunal.osm
    • This shapefile is already in EPSG:4326 = WGS84 and can be read by JOSM.
  4. Remove GPSBabel's tag from OSM file to save memory:
    • Open your OSM-file with notepad
    • Remove this tag: <tag k='created_by' v='GPSBabel-1.3.5'/>