OSM package
OSM area-selection helpers (GUI-free).
Pure geometry helpers shared by the OSM street and building download dialogs: resolve a user-selected area (city name, buildings CSV, GeoJSON polygon, or a polygon drawn on the map) into a WGS84 shapely geometry, and build the OSMnx highway filter string.
These were extracted from the two near-identical worker methods in
gui/LeafletTab/osm_dialogs.py so the logic lives in one tested place and so the
download threads no longer touch the GUI: a missing CSV column now raises
ValueError (caught by the download thread → error signal) instead of calling
QMessageBox from a worker thread.
- author:
Dipl.-Ing. (FH) Jonas Pfeiffer
- districtheatingsim.osm.area_selection.build_highway_filter(selected_types) str[source]
Build an OSMnx
custom_filterstring from selected highway types.
- districtheatingsim.osm.area_selection.polygon_from_csv(csv_file, project_crs, buffer_m)[source]
Build a buffered WGS84 polygon around building points from a CSV file.
- Parameters:
- Returns:
WGS84 (EPSG:4326) polygon covering the buffered points.
- Return type:
shapely.geometry.base.BaseGeometry
- Raises:
ValueError – If the CSV lacks
UTM_X/UTM_Ycolumns.
- districtheatingsim.osm.area_selection.polygon_from_geojson(geojson_file)[source]
Read a polygon GeoJSON file and return it as a single WGS84 geometry.
- Parameters:
geojson_file (str) – Path to a GeoJSON file containing one or more polygons.
- Returns:
WGS84 (EPSG:4326) union of the file’s geometries.
- Return type:
shapely.geometry.base.BaseGeometry
- districtheatingsim.osm.area_selection.resolve_area_polygon(area_params, buffer_m)[source]
Resolve an area-selection parameter dict to a WGS84 polygon.
Dispatches on
area_params['area_type']: a buildings CSV (buffered bybuffer_m), a GeoJSON polygon file, or a polygon drawn on the map. The city-name area type produces no polygon (the caller downloads by place name).- Parameters:
- Returns:
WGS84 polygon for the selected area.
- Return type:
shapely.geometry.base.BaseGeometry
- Raises:
ValueError – For the city-name or an unknown area type (no polygon).
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.
- districtheatingsim.osm.import_osm_data_geojson.download_data(query, element_type)[source]
Download OSM data via Overpass API and convert to GeoJSON.
- Parameters:
- 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.