py4sci

Table Of Contents

Previous topic

osm2hydro

Next topic

map2shape

This Page

osm2shp

osm2shp - convert an osm|pbf file to a set of shapefiles using ogr2ogr. Filtering with tags is controlled by a .ini file.

Usage:

osm2shp.py [-h][-c configfile] -O my_osm_file.osm|pbf -o outputdir

-O osm_file - the osm|pbf file
-o outputdir - the directory to store the output in
-h - show this information
-c configfile (default is osm2shp.ini)
-M maxproc - maximum number of ogr2ogr processes to start (default = 2)

dependencies

  • ogr2ogr (tested with gdal >= 1.10.0)
  • the OSM_CONFIG_FILE environment var should be set and point to a valid gdal osmconf.ini file

ini file

The ini file has a section for each shape file created:

[lu_roads_sec]
type=lines
highway=motorway_link,secondary,"road"
aeroway='runway','taxiway'
    
[lu_roads_main]
type=lines 
highway='motorway','trunk','primary'
    
    
[lu_roads_small]
type=lines
highway='footway','path','pedestrian','residential','service','tertiary','track','unclassified','cycleway'
    
[lu_water]
type=multipolygons
natural='water','reservoir','basin','salt_pond'
landuse='water','basin','reservoir','salt_pond'

$Author: $ $Id: $ $Rev: $

osm2shp.configget(log, config, section, var, default)

Gets a string from a config file (.ini) and returns a default value if the key is not found. If the key is not found it also sets the value with the default in the config-file

Input:
  • config - python ConfigParser object
  • section - section in the file
  • var - variable (key) to get
  • default - default string
Returns:
  • string - either the value from the config file or the default value
osm2shp.configset(config, section, var, value, overwrite=False)

Sets a string in the in memory representation of the config object Deos NOT overwrite existing values if overwrite is set to False (default)

Input:
  • config - python ConfigParser object
  • section - section in the file
  • var - variable (key) to set
  • value - the value to set
  • overwrite (optional, default is False)
Returns:
  • nothing
osm2shp.extractlayers_new(config, osmfile, outputdir, maxprocesses=2, ogr2ogr='ogr2ogr')

http://stackoverflow.com/questions/4992400/running-several-system-commands-in-parallel

osm2shp.iniFileSetUp(configfile)

Reads .ini file and sets default values if not present

osm2shp.main(argv=None)

Main function, processes the command-line options, reads the config file and starts the extract function.

osm2shp.mkogr2ogrstr(config, sec)

Create the ogr2ogr string from a ini file to select data using sql statements - one statement for each section - multiple tags per feature using a comma separated list