A Python library to convert OSM and Overpass JSON responses into valid GeoJSON. Version 0.3.2 is the latest stable release. The library is actively maintained, with recent bug fixes for polygon hole handling and blacklist/whitelist rules. Releases are sporadic.
pip install osm2geojsonVerified import paths — ran on the pinned version, not inferred.
Converts an OSM JSON dict (e.g., from Overpass API) into a GeoJSON FeatureCollection.
Ensure you pass a dict via json.loads() if reading from a string.
Validate your Overpass JSON structure before passing to osm2geojson.
Use json2geojson instead of overpass2geojson.
Post-process with a polygon winding fixer if required by your GeoJSON consumer.
Use osm2geojson.json2geojson(data) instead of osm2geojson.overpass2geojson(data).
Check your JSON structure; ensure it has an 'elements' list. If from Overpass, use the raw response (the JSON output from the API).
Pass the dict directly to osm2geojson.json2geojson(dict). If you have a string, do: geojson = osm2geojson.json2geojson(json.loads(json_string)).