voxcity.geoprocessor.conversion¶
Conversion utilities between GeoJSON-like features and GeoPandas GeoDataFrames, plus helpers to filter and transform geometries for export.
Functions¶
|
Filter a GeoDataFrame by a bounding rectangle and convert to GeoJSON format. |
|
Convert a list of GeoJSON-like dict features into a GeoDataFrame. |
|
Convert a GeoDataFrame to a list of dicts similar to GeoJSON features. |
Module Contents¶
- voxcity.geoprocessor.conversion.filter_and_convert_gdf_to_geojson(gdf, rectangle_vertices)[source]¶
Filter a GeoDataFrame by a bounding rectangle and convert to GeoJSON format.
This function performs spatial filtering on a GeoDataFrame using a bounding rectangle, and converts the filtered data to GeoJSON format. It handles both Polygon and MultiPolygon geometries, splitting MultiPolygons into separate Polygon features.
- Parameters:
gdf (GeoDataFrame) – Input GeoDataFrame containing building data Must have ‘geometry’ and ‘height’ columns Any CRS is accepted, will be converted to WGS84 if needed
rectangle_vertices (list) – List of (lon, lat) tuples defining the bounding rectangle Must be in WGS84 (EPSG:4326) coordinate system Must form a valid rectangle (4 vertices, clockwise or counterclockwise)
- Returns:
- List of GeoJSON features within the bounding rectangle
Each feature contains: - geometry: Polygon coordinates in WGS84 - properties: Dictionary with ‘height’, ‘confidence’, and ‘id’ - type: Always “Feature”
- Return type:
list
- Memory Optimization:
Uses spatial indexing for efficient filtering
Downcasts numeric columns to save memory
Cleans up intermediate data structures
Splits MultiPolygons into separate features
- voxcity.geoprocessor.conversion.geojson_to_gdf(geojson_data, id_col='id')[source]¶
Convert a list of GeoJSON-like dict features into a GeoDataFrame.
This function takes a list of GeoJSON feature dictionaries (Fiona-like format) and converts them into a GeoDataFrame, handling geometry conversion and property extraction. It ensures each feature has a unique identifier.