PatchGeoref#

class rapidtools.data_sources.orthomosaic_reader.PatchGeoref(transform: Affine, crs: CRS, width: int, height: int)[source]#

Bases: object

Native georeferencing of an image patch read from a raster.

A patch’s WGS84 bounding box is only an envelope: for a projected or rotated raster the patch edges are not lines of constant latitude and longitude, so mapping pixels through that envelope stretches and skews the result. This record keeps the exact pixel-to-CRS affine transform of the window that was read so masks drawn on the patch can be vectorized in the raster’s own grid and then reprojected.

Variables:
  • transform (affine.Affine) – Affine transform from patch pixel coordinates to crs.

  • crs (CRS) – The raster’s coordinate reference system.

  • width (int) – Patch width in pixels when it was read.

  • height (int) – Patch height in pixels when it was read.

Example

>>> from rasterio.crs import CRS
>>> from rasterio.transform import Affine
>>> georef = PatchGeoref(Affine(0.5, 0, 500000, 0, -0.5, 4100000),
...                      CRS.from_epsg(32611), 100, 100)
>>> georef.transform_for(50, 50).a
1.0
>>> PatchGeoref.from_dict(georef.to_dict()) == georef
True

Methods

from_dict

Rebuild the record from to_dict() output.

to_dict

Return a JSON-friendly representation (see from_dict()).

transform_for

Return the affine transform for a resampled copy of the patch.

transform_for(width: int, height: int) → Affine[source]#

Return the affine transform for a resampled copy of the patch.

Parameters:
  • width – Width in pixels of the array being georeferenced.

  • height – Height in pixels of the array being georeferenced.

Returns:

Affine – transform rescaled so the array still covers the same ground footprint.

to_dict() → dict[str, Any][source]#

Return a JSON-friendly representation (see from_dict()).

classmethod from_dict(data: dict[str, Any]) → PatchGeoref[source]#

Rebuild the record from to_dict() output.