Skip to main content

Convert OpenStreetMap data into GIS and mobile mapping file formats.

Project description

OSM Export Tool

This project is in a usable state on Linux and Mac. The current Export Tool web service repository is at hotosm/osm-export-tool.

Motivation

This program filters and transforms OpenStreetMap data into thematic, tabular GIS formats. Filtering of features is specified via SQL embedded in a YAML mapping file, for example:

buildings_with_addresses:  # creates a thematic layer called "buildings_with_addresses"
  types:
    - polygons
  select:
    - building
    - height
    - addr:housenumber
  where:
    - building = 'yes' and addr:housenumber IS NOT NULL

It can also create files in non-tabular formats such as those for Garmin GPS devices or the OSMAnd Android app. (coming soon)

Installation

  • install via pip install osm-export-tool. Python 3 and a working GDAL installation are required. GDAL can be installed via Homebrew on Mac or the ubuntugis PPAs on Ubuntu.

PyOsmium is used to read OSM files and GDAL/OGR is used to write GIS files, so this program should be reasonably fast and light on memory. There is a built-in OSM reader available for GDAL/OGR, but this program is much more flexible.

This library will not automatically install GDAL because it needs to match the version on your system. You will need to separately run pip install GDAL==2.3.2 (change 2.3.2 to match gdalinfo --version)

Running with Docker

If you want to avoid installing the right version of GDAL on your system you can run the program as a docker container instead.

To build the docker image, use the following command.

docker build -t osm-export-tool .

To run the tool as a container, using your current directory as working directory, use the following command.

docker run -it --rm -v $(pwd):/work osm-export-tool INPUT_FILE.pbf OUTPUT_NAME

Example usage

osm-export-tool INPUT_FILE.pbf OUTPUT_NAME

will create OUTPUT_NAME.gpkg.

All the below flags are optional.

  • -m, --mapping : specify a mapping YAML. Defaults to osm_export_tool/mappings/defaults.yaml, which is a very broad selection of OSM tags ported from the imposm3 defaults.
  • -f, --formats : a comma-separated list of formats such as gpkg,shp. Defaults to just gpkg.
  • --omit-osm-ids: By default, every table will have an osm_id column. Relation IDs are negative.
  • --clip <file>: either a .poly or GeoJSON file.
    • The GeoJSON must be either a Polygon or MultiPolygon geometry, or a FeatureCollection with one Polygon or MultiPolygon feature.
    • Clipping is performed by Shapely and can be slow. It is recommended to filter the input PBF with a tool like osmium-tool.

YAML Mapping

  • SQL statements must be comparisons of keys to constants with the key first.
    • Valid examples:
      • height > 20
      • amenity='parking' OR (building = 'yes' and height > 5)
    • Invalid examples:
      • 20 < height
      • building > height
  • More examples can be found in the mappings directory.
  • if the types key is omitted, it defaults to points, lines and polygons.
  • At least one tag is required as a child of the select key.
  • If the where key is omitted, it defaults to choosing all features where any of the selected keys are present.
  • if where is a list of SQL, it is equivalent to joining each SQL in the list with OR.

Output formats

  1. OGC GeoPackage (gpkg)
  • This is the default export format, and the most flexible for modern GIS applications.
  • tables will be created with the wkbUnknown geometry type, which allows heterogeneous geometry types.
  1. Shapefile (shp)
  • Each layer and geometry type is a separate .SHP file. This is because each .SHP file only supports a single geometry type and column schema.
  1. KML (kml)
  • Each layer and geometry type is a separate .KML file. This is because the GDAL/OGR KML driver does not support interleaved writing of features with different geometry types.
  1. Maps.ME (coming soon)

  2. OsmAnd (coming soon)

  3. Garmin (coming soon)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osm-export-tool-0.0.26.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

osm_export_tool-0.0.26-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file osm-export-tool-0.0.26.tar.gz.

File metadata

  • Download URL: osm-export-tool-0.0.26.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for osm-export-tool-0.0.26.tar.gz
Algorithm Hash digest
SHA256 dbed26b6adb891f57e58a52b450c55e8e4246596343e15b972698ea4ec9de489
MD5 bc04be3053dc2a6e6ecfaf7883acd442
BLAKE2b-256 cb4a79a5a8e5fc23415e58be677087c15376a4d37d2955f4831526116271fe9a

See more details on using hashes here.

File details

Details for the file osm_export_tool-0.0.26-py3-none-any.whl.

File metadata

  • Download URL: osm_export_tool-0.0.26-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for osm_export_tool-0.0.26-py3-none-any.whl
Algorithm Hash digest
SHA256 e25b555a7828086fc6c764dc95c9a66df531cc8ede473f0f4110c3dc55b27df1
MD5 8f33161deaa394563ab8107624d569c8
BLAKE2b-256 7d3d8d84aad5e7fefe554f77e3db28e8b8b496be666f24572e40f89bf2da184d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page