xee.fit_geometry

xee.fit_geometry(geometry, *, geometry_crs='EPSG:4326', buffer=0, grid_crs='EPSG:4326', grid_scale=None, grid_scale_digits=None, grid_shape=None)

Derive grid parameters that cover a geometry.

You must specify exactly one of grid_scale (pixel size) or grid_shape (pixel count). When a scale is provided the output pixel shape is computed to fully cover the buffered geometry. When a shape is provided the scale is inferred uniformly over the geometry’s bounding box.

Parameters:
  • geometry (BaseGeometry) – Shapely geometry defining the area of interest (in geometry_crs units).

  • geometry_crs (str) – CRS of the input geometry (default WGS84).

  • buffer (float) – Optional positive distance in CRS units to expand the geometry.

  • grid_crs (str) – Target CRS for the output grid.

  • grid_scale (tuple[float, float] | None) – Optional (x_scale, y_scale) in grid_crs units. y may be negative for north-up orientation.

  • grid_scale_digits (int | None) – If provided with grid_shape workflow, round inferred scales to this number of decimal places.

  • grid_shape (tuple[int, int] | None) – Optional (width, height) pixel count.

Returns:

PixelGridParams dictionary usable with xarray.open_dataset.

Raises:
  • ValueError – If both or neither of grid_scale / grid_shape provided.

  • TypeError – If grid_scale is malformed.

Return type:

PixelGridParams