-1

I have created rasterized a geodataframe using geocube make_geocube. The resulting xr.Dataset now has the extent of the underlying geodataframe vector data. Say, the bounding box would be covering Europe. However, I would love to have the xr.DataSet at global extent, i.e. covering all cells from -180 to 180 longitude and -90 to 90 latitude at the spatial resolution used in make_geocube.

Is there a way to do that without using GDAL functions directly, perhaps by using the geom argument in make_geocube?

1 Answer 1

0

Yes, the geom argument for make_geocube does what you're looking for. All you need to do is pass a Shapely geometry with the global extent:

from geocube.api.core import make_geocube
from shapely.geometry import box


geocube = make_geocube(
  vector_data=your_geodataframe,
  # 1 grid cell per degree
  resolution=(-1, 1),
  # Global extent in degrees of longitude and latitude
  geom=box(minx=-180, miny=-90, maxx=180, maxy=90),
)

print(geocube.dims)
# Frozen({'y': 180, 'x': 360})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.