mask_to_wgs84_polygons

mask_to_wgs84_polygons#

rapidtools.processing.vectorize.mask_to_wgs84_polygons(mask: Any, georef: PatchGeoref | None = None, wgs84_bounds: tuple[float, float, float, float] | None = None, threshold: float = 0.5) → list[Polygon][source]#

Vectorize a binary mask into valid WGS84 polygons.

Parameters:
  • mask (array-like) – A 2D mask (boolean, integer or float). Values above threshold are foreground. Leading singleton dimensions are squeezed away.

  • georef (PatchGeoref | None) – The native georeferencing of the patch the mask was drawn on. When given, shapes are extracted in the raster’s own grid (scaled to the mask size) and reprojected to WGS84, which is correct for projected and rotated rasters.

  • wgs84_bounds (tuple[float, float, float, float] | None) – (min_lon, min_lat, max_lon, max_lat) of the patch. Used only when georef is None; it maps pixels linearly to the envelope, which is exact only for north-up WGS84 rasters.

  • threshold (float) – Foreground cut-off for float masks. Defaults to 0.5.

Returns:

list[shapely.geometry.Polygon] – Valid, non-empty polygons, one per connected foreground region.

Raises:

ValueError – If the mask is not 2D after squeezing, or neither georef nor wgs84_bounds is given.