Skip to main content

OpenStreetMap GeoJSON Exporter

Project description

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".

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

osmexp-0.2.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osmexp-0.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file osmexp-0.2.0.tar.gz.

File metadata

  • Download URL: osmexp-0.2.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for osmexp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b854076dfba8f79e35a1b84922513d7e49862f7de3da98128925615cb86be91a
MD5 1d84d104ea199c223a6796c3150b24d1
BLAKE2b-256 398d85b77563e44ae4459bb5fe5d091928e3329707d962e95eb4c28548e96157

See more details on using hashes here.

File details

Details for the file osmexp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: osmexp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for osmexp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81cf114151c128e330303b9d60c32e18ec57a15d3fb71b628568ee1975635e86
MD5 72f20cc1a3aa50e9a93630ce8c20f585
BLAKE2b-256 4f722fac63f0be210e9f8a9f5ed4859f233afcce2c390e58019ba09ef151f9b8

See more details on using hashes here.

Supported by

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