Convert OpenStreetMap data into GIS and mobile mapping file formats.
Project description
OSM Export Tool
This project is under development. 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 theubuntugis
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.
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 asgpkg,shp
. Defaults to just gpkg.--omit-osm-ids
: By default, every table will have anosm_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
- Valid examples:
- More examples can be found in the mappings directory.
- if the
types
key is omitted, it defaults topoints
,lines
andpolygons
. - 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 theselect
ed keys are present. - if
where
is a list of SQL, it is equivalent to joining each SQL in the list withOR
.
Output formats
- 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.
- 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.
- 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.
-
Maps.ME (coming soon)
-
OsmAnd (coming soon)
-
Garmin (coming soon)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for osm_export_tool-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7906e5449e70405e535acea88bc43ae8a8fe836e943c5008b1d5a7dcad718719 |
|
MD5 | afb671a98499f006a0560f647763914f |
|
BLAKE2b-256 | 3771d5675e59377b51aece3ee0186e671b1e34e748aa4d6da36447c05974f4c5 |