regularize_footprint

regularize_footprint#

rapidtools.processing.postprocessing.footprints.regularize_footprint(polygon: BaseGeometry, orientation: float | None = None, orientation_hints: Sequence[float] = (), *, min_feature: float | None = None, rectangle_iou: float = 0.92, min_iou: float = 0.82, hole_min_area: float = 12.0, return_info: bool = False) → Any[source]#

Turn a mask-traced footprint into a building-like outline.

Parameters:
  • polygon – The footprint in a planar CRS in meters (Polygon; for a MultiPolygon the largest part is used).

  • orientation – Wall direction in radians to use instead of estimating one.

  • orientation_hints – Further directions to try, such as the one shared by neighboring buildings. The direction whose outline overlaps the footprint best wins, with ties going to the hints.

  • min_feature – Width in meters below which bulges, dents and steps are removed. Defaults to a value that grows with the building, from 0.6 m for a shed to 1.5 m for large buildings.

  • rectangle_iou – A footprint whose oriented rectangle overlaps it at least this well (intersection over union) becomes the rectangle.

  • min_iou – The regularized outline must overlap the smoothed footprint at least this well; otherwise a simplified outline is returned.

  • hole_min_area – Interior rings smaller than this (m^2) are filled.

  • return_info – Also return a dictionary with 'method' ('rectangle', 'rectilinear' or 'simplified'), 'orientation' (radians) and 'iou'.

Returns:

Polygon | None – The regularized footprint (None for empty or degenerate input), or (polygon, info) with return_info=True.

Example

>>> from shapely import affinity
>>> from shapely.geometry import box
>>> wobbly = affinity.rotate(box(0, 0, 12, 8), 25).buffer(0.4)
>>> clean = regularize_footprint(wobbly)
>>> len(clean.exterior.coords) - 1
4