Crop image based on polygon
Opened this issue · 2 comments
steinmetz commented
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?
Line 60 in 5ece4a5
I wanted to generate something like this (with transparent background):
mdmaas commented
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.
mdmaas commented
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)