stems.gis.coords module

Coordinate and geotransforms

stems.gis.coords.coords_to_bounds(y, x, center=True, assume_unique=True)[source]

Calculate the BoundingBox of the coordinates

If the Affine transform of the data is known, it can be provided. Otherwise this function runs coords_to_transform() to determine the pixel sizing.

Parameters
  • y (array-like) – Y coordinates (latitude, y, etc)

  • x (array-like) – X coordinates (longitude, x, etc)

  • center (bool, optional) – Are coordinates provided pixel center (True) or upper-left (False)

  • assume_unique (bool, optional) – Assume coordinates are sorted and unique. Otherwise, will run np.unique on each

Returns

Bounds expressed as left, bottom, right, top

Return type

BoundingBox

stems.gis.coords.coords_to_transform(y, x, center=True, assume_unique=True)[source]

Calculate Affine transform from coordinates

Note: y/x will be loaded into memory

Parameters
  • y (array-like) – Y coordinates (latitude, y, etc)

  • x (array-like) – X coordinates (longitude, x, etc)

  • center (bool, optional) – Are coordinates provided pixel center (True) or upper-left (False)

  • assume_unique (bool, optional) – Assume coordinates are sorted and unique. Otherwise, will run np.unique on each

Returns

Affine transformation

Return type

affine.Affine

stems.gis.coords.transform_to_bounds(transform, height, width)[source]

Return a BoundingBox for some transform and shape

Parameters
  • transform (affine.Affine) – Affine transformation

  • height (int) – Height in pixels

  • width (int) – Width in pixels

Returns

left, bottom, right, & top bounding box coordinates

Return type

BoundingBox

stems.gis.coords.transform_to_coords(transform, bbox=None, width=None, height=None, center=True)[source]

Return the coordinates for a given transform

This function needs to know how many pixels are in the raster, so either a rasterio.coords.BoundingBox or height and width arguments must be supplied.

Parameters
  • transform (affine.Affine) – Affine transform

  • bbox (BoundingBox) – Return the coordinates for this transform that are contained inside the provided bounds (left, bottom, right, up). Coordinates will be aligned/spaced according to the transform and will not necessarily match the upper-left of this bbox

  • height (int) – Number of pixels tall

  • width (int) – Number of pixels wide

  • center (bool, optional) – Return coordinates for the center of each pixel

Returns

y, x – Y/X coordinate pairs (e.g., latitude/longitude)

Return type

tuple[np.ndarray, np.ndarray]

stems.gis.coords.transform_to_res(transform)[source]

Return the resolution from a transform

Parameters

transform (affine.Affine) – Affine transform

Returns

Width and height

Return type

tuple[float, float]