urbanity.geom¶
Geometric utility functions for working with urban spatial data. These are low-level helpers used internally and can also be called directly.
Coordinate & CRS Utilities¶
get_utm_crs¶
Returns the appropriate UTM CRS EPSG code for a GeoDataFrame based on its centroid location. Useful for projecting to a metric CRS before distance calculations.
project_to_utm¶
Projects a GeoDataFrame from geographic coordinates (WGS84) into the best-fit UTM zone.
Spatial Operations¶
buffer_geometry¶
Buffers all geometries in a GeoDataFrame by distance metres (after projecting to UTM).
| Parameter | Type | Description |
|---|---|---|
gdf |
GeoDataFrame |
Input geometries. |
distance |
float |
Buffer radius in metres. |
cap_style |
int |
Shapely cap style: 1 = round, 2 = flat, 3 = square. |
compute_voronoi¶
Computes Voronoi polygons for a set of point geometries, clipped to the convex hull of the input.
snap_points_to_network¶
Snaps each point to the nearest edge in the network within threshold metres. Returns the points GeoDataFrame with added nearest_edge_id and distance_to_edge columns.
Geometry Helpers¶
get_polygon_bounds¶
Returns (minx, miny, maxx, maxy) bounding box for a GeoDataFrame in WGS84.
polygon_to_bbox¶
Converts a Shapely polygon to an {"north", "south", "east", "west"} bounding-box dict compatible with OSM query APIs.
split_polygon_grid¶
Splits a large polygon into a regular grid of smaller cells (cell size in metres). Useful for tiling large-area data downloads.