pygeoutils._utils#

Some utilities for manipulating GeoSpatial data.

Module Contents#

pygeoutils._utils.get_gtiff_attrs(resp, ds_dims=None, driver=None, nodata=None)#

Get nodata, CRS, and dimension names in (vertical, horizontal) order from raster in bytes.

Parameters:
  • resp (bytes) – Raster response returned from a wed service request such as WMS

  • ds_dims (tuple of str, optional) – The names of the vertical and horizontal dimensions (in that order) of the target dataset, default to None. If None, dimension names are determined from a list of common names.

  • driver (str, optional) – A GDAL driver for reading the content, defaults to automatic detection. A list of the drivers can be found here: https://gdal.org/drivers/raster/index.html

  • nodata (float or int, optional) – The nodata value of the raster, defaults to None, i.e., is determined from the raster.

Returns:

Attrs – No data, CRS, and dimension names for vertical and horizontal directions or a list of the existing dimensions if they are not in a list of common names.

Return type:

Attrs

pygeoutils._utils.get_transform(ds, ds_dims=('y', 'x'))#

Get transform of a xarray.Dataset or xarray.DataArray.

Parameters:
  • ds (xarray.Dataset or xarray.DataArray) – The dataset(array) to be masked

  • ds_dims (tuple, optional) – Names of the coordinames in the dataset, defaults to ("y", "x"). The order of the dimension names must be (vertical, horizontal).

Returns:

rasterio.Affine, int, int – The affine transform, width, and height

Return type:

tuple[rasterio.Affine, int, int]

pygeoutils._utils.transform2tuple(transform)#

Convert an affine transform to a tuple.

Parameters:

transform (rio.Affine) – The affine transform to be converted

Returns:

tuple – The affine transform as a tuple (a, b, c, d, e, f)

Return type:

tuple[float, float, float, float, float, float]

pygeoutils._utils.xd_write_crs(ds, crs=None, grid_mapping_name=None)#

Write geo reference info into a dataset or dataarray.

Parameters:
  • ds (xarray.Dataset or xarray.DataArray) – Input dataset(array)

  • crs (pyproj.CRS or str or int, optional) – Target CRS to be written, defaults to ds.rio.crs

  • grid_mapping_name (str, optional) – Target grid mapping, defaults to ds.rio.grid_mapping

Returns:

xarray.Dataset or xarray.DataArray – The dataset(array) with CRS info written.

Return type:

XD