1

I dont fully understand how to use the "geom" parameter in python geocube library with crs different than 4326, described here: https://corteva.github.io/geocube/stable/geocube.html#make-geocube

Could anyone please show me, how to use the geom parameter with crs 3857, while taking the bbox from other raster layer, or set of coordinates? I can't seem to get the syntax of specifying the different crs right... I think the documentation is missing a clear and simple example. I am rasterizing a point gdf and need the raster to be snapped to some other raster with the given bbox...

bbox = (-9907392, 5160736, -9795746, 5311946)

geo_grid = make_geocube(
       vector_data=gdf,
       measurements=["rasterize"],
       geom = json.dumps(mapping(box(???))),
       output_crs="epsg:3857",
       resolution=(-2, 2),
       fill=0
   )```

1 Answer 1

0

geocube docs

bbox = (-9907392, 5160736, -9795746, 5311946)
geom = mapping(box(*bbox))
geom["crs"] = {"properties": {"name": "EPSG:3857"}}
geo_grid = make_geocube(
   vector_data=gdf,
   measurements=["rasterize"],
   geom=geom,
   output_crs="epsg:3857",
   resolution=(-2, 2),
   fill=0
)
3
  • Thanks, it isn't really clear from the documentation.
    – XDOLK009
    Commented Jul 19, 2022 at 7:17
  • Contributions are always welcome to improve the documentation.
    – snowman2
    Commented Jul 19, 2022 at 15:40
  • Is this not possible if the CRS can't be represented by an EPSG code?
    – mikoontz
    Commented Nov 27 at 21:56

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.