Skip to main content

osmexp - OpenStreetMap GeoJSON Exporter

The OSM API uses a specific format for their geometric primitive types based on nodes, ways and relations; and those unfortunately don’t translate 1:1 with GeoJSON types, thus a conversion is needed.

Installation:

Make sure you have at least Python 3.11, and install it with:

$ pip install osmexp

The only requirements are Requests and Shapely.

Usage

For all exports, this is the format:

$ osmexp [element_type] [element_id]

Where element_type can be node, way or rel (for "relation"). And the ID is the numerical identifier used by OSM, if you don’t know how to get the OSM ID, follow this article.

The output is set to STDOUT, and it is recommended to be piped into a file or another command. On failure, an error message is sent to STDERR and the process exits with a non-zero status.

Exporting Nodes:

$ osmexp node 9589344640 > outdoor_seating.geojson

This returns a GeoJSON with a Point as a root type.

Exporting Ways:

$ osmexp way 398987317 > canal_grande.geojson

This returns a GeoJSON with a LineString as a root type if the line is “open” or Polygon if the line is “closed”.

Exporting Relations:

$ osmexp rel 4817103 > venice.geojson

This returns a GeoJSON with a FeatureCollection as a root, and the internal features as LineString or Polygon, depending if they can self-close, or fail the polygon transformation by other means (self crossing, etc).

Development

Clone the repository and install in editable mode with the dev extras (tests, linter):

$ pip install -e '.[dev]'

All dependencies are declared in pyproject.toml; there are no separate requirements files.

Run the test suite (it replays recorded HTTP responses, so no network is needed):

$ pytest

Lint and format with Ruff:

$ ruff check .
$ ruff format .

License

This library is released under the 3-Clause BSD License.

tl;dr: "free to use as long as you credit me".

Release files for osmexp 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osmexp 0.2.0
File Size Uploaded
osmexp-0.2.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osmexp 0.2.0
File Interpreter ABI Platform
osmexp-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / osmexp-0.2.0.tar.gz

Download URL osmexp-0.2.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b854076dfba8f79e35a1b84922513d7e49862f7de3da98128925615cb86be91a
BLAKE2b-256 checksum
How to use checksums
398d85b77563e44ae4459bb5fe5d091928e3329707d962e95eb4c28548e96157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / osmexp-0.2.0-py3-none-any.whl

Download URL osmexp-0.2.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81cf114151c128e330303b9d60c32e18ec57a15d3fb71b628568ee1975635e86
BLAKE2b-256 checksum
How to use checksums
4f722fac63f0be210e9f8a9f5ed4859f233afcce2c390e58019ba09ef151f9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page