OSM package

OpenStreetMap data import and GeoJSON conversion module.

Provides Overpass API integration for downloading OSM data and converting it to GeoJSON format for district heating network planning.

author:

Dipl.-Ing. (FH) Jonas Pfeiffer

districtheatingsim.osm.import_osm_data_geojson.build_query(city_name, tags, element_type='way')[source]

Build Overpass API query for OSM data download.

Parameters:
  • city_name (str) – City name for OSM query

  • tags (list of tuple) – List of (key, value) tuples to filter OSM elements

  • element_type (str) – OSM element type (‘way’ or ‘building’)

Returns:

Overpass API query string

Return type:

str

districtheatingsim.osm.import_osm_data_geojson.download_data(query, element_type)[source]

Download OSM data via Overpass API and convert to GeoJSON.

Parameters:
  • query (str) – Overpass API query string

  • element_type (str) – OSM element type (‘way’ or ‘building’)

Returns:

GeoJSON FeatureCollection with OSM data

Return type:

geojson.FeatureCollection

Raises:

OverpassError – If API query fails

Note

Ways create LineString geometries, buildings create Polygon/MultiPolygon.

districtheatingsim.osm.import_osm_data_geojson.json_serial(obj)[source]

JSON serializer for non-standard objects.

Parameters:

obj (any) – Object to serialize

Returns:

Float representation for Decimal objects

Return type:

float

Raises:

TypeError – If object type is not serializable

districtheatingsim.osm.import_osm_data_geojson.save_to_file(geojson_data, filename)[source]

Save GeoJSON data to file.

Parameters:
  • geojson_data (geojson.FeatureCollection) – GeoJSON data to save

  • filename (str) – Output file path