raptorstats.io module

raptorstats.io.open_raster(source, *, affine=None, nodata=None, band=1, crs=None)[source]

Yield a rasterio.DatasetReader no matter what the caller passes.

Parameters:
  • source (str | Path | rasterio.io.DatasetReader | np.ndarray)

  • affine (Affine, required if source is a NumPy array)

  • nodata (float, optional override (ignored for open readers that already match))

  • band (int specifying the bad to read)

  • crs (dict or str, CRS for in-memory arrays)

Yields:

ds (rasterio.io.DatasetReaderBase)

raptorstats.io.open_vector(vectors: str | Path | shapely.geometry.base.BaseGeometry | Sequence[shapely.geometry.base.BaseGeometry] | dict | geopandas.GeoDataFrame, *, layer: int | str = 0, crs=None, affine: Affine | None = None) geopandas.GeoDataFrame[source]

Normalise vectors into a GeoDataFrame.

Parameters:
  • vectors (many flavours, see type hint above.)

  • layer (layer name or index when reading multi-layer files.)

  • crs (CRS to assign if the input has none (e.g. Shapely geom).)

  • affine (Affine of the raster (optional). If crs is None and you) – pass an Affine with EPSG info (pyproj 3.6+ Affine.crs), that CRS will be used. But don’t quote me on that, this might fail.

Returns:

gdf – Always contains at least a ‘geometry’ column and a CRS.

Return type:

GeoDataFrame

raptorstats.io.validate_is_north_up(transform)[source]
raptorstats.io.validate_raster_vector_compatibility(raster: rasterio.DatasetReader, vector: geopandas.GeoDataFrame)[source]