The regularize_geodataframe function is the primary entry point for regularizing polygon geometries in a GeoDataFrame. It aligns edges to be parallel, perpendicular, or (optionally) at 45-degree angles to their main direction. It handles reprojection, initial simplification, regularization, geometry cleanup, and can be run in parallel across multiple CPU cores.
Key capabilities:
- Edge Alignment: Aligns edges based on a
parallel_threshold. - Circle Detection: If
allow_circles is True, nearly circular polygons are replaced with perfect circles based on an IoU circle_threshold. - Neighbor Alignment: If
neighbor_alignment is True, it aligns polygons with their neighbors within a neighbor_search_distance and neighbor_max_rotation threshold. - Parallel Processing: Uses
num_cores to speed up processing (0 uses all available cores). - Metadata: Optionally includes regularization metadata (like
iou and main_direction) in the output.
import geopandas as gpd
from buildingregulariser.coordinator import regularize_geodataframe
# Load your data
gdf = gpd.read_file("buildings.shp")
# Regularize the geometries
regularized_gdf = regularize_geodataframe(
geodataframe=gdf,
target_crs="EPSG:3857",
simplify_tolerance=0.5,
allow_45_degree=True,
neighbor_alignment=True,
neighbor_search_distance=50.0,
include_metadata=True
)