Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crop image based on polygon #2

Open
steinmetz opened this issue Jun 8, 2022 · 2 comments
Open

Crop image based on polygon #2

steinmetz opened this issue Jun 8, 2022 · 2 comments

Comments

@steinmetz
Copy link

steinmetz commented Jun 8, 2022

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

@mdmaas
Copy link
Owner

mdmaas commented Jun 8, 2022

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
Copy link
Owner

mdmaas commented Jun 8, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants