mdmaas/p4rs

Crop image based on polygon

Opened this issue · 2 comments

Hi!
Thank you for your tutorials, they are really good!

Do you know how I could crop the generated PNG based on the geometry instead of using bbox?

lat_north, lon_west = Transf.transform(bbox[3], bbox[0])

I wanted to generate something like this (with transparent background):
2021-06-24_17-25

Hi! Thanks.

I don't know if I would do that at the RasterIO Window level. After all, COGS are still an image format, and all image formats I know are based on rectangles...

Something that could be done is to trim the data before converting it into a PNG file, applying rasterio.mask. See, for example, this thread.

I didn't try this, but my guess is that something like this line should work:

out_image, out_transform = rasterio.mask.mask(subset, geometry, filled = True)

show(out_image)