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

Cropping GeoImages #11

Closed
lematt1991 opened this issue Apr 10, 2017 · 2 comments
Closed

Cropping GeoImages #11

lematt1991 opened this issue Apr 10, 2017 · 2 comments

Comments

@lematt1991
Copy link

Would it be possible to add functionality to crop a GeoImage? It would be great if you could specify either the indices of the subset that you would like to crop out or even the bounds in lat/lon coordinates. Cropping out the data would be trivial, but the projection information would also need to be updated.

@longbotham
Copy link
Contributor

passing return_location=True to get_data or the iter_xxx functions should do what you're asking for. You can then either use the new geo_transform info directly in python or write the pixels back to a file on disk with create_geo_image. You can also pass a geom directly to get_data if you have a single geometry you want to cut to - see the code for iter_vector under the example below for details.

import geoio
import dgsamples

vec_str = dgsamples.wv2_longmont_1k_vectors.poly_geojson_utm
img = geoio.DGImage(dgsamples.wv2_longmont_1k.ms)

for x in img.iter_vector(vec_str, return_location=True):
        fname = 'tmp'+'_'.join([str(p) for p in x[1]['upper_left_pixel']])+'.tif'
        dtype = geoio.constants.DICT_NP_TO_GDAL[x[0].dtype]
        geoio.base.create_geo_image(fname,
                                    x[0],
                                    'GTiff',
                                    x[1]['geo_transform'],
                                    img.meta.projection_string,
                                    dtype)

@lematt1991
Copy link
Author

Yep, that's exactly what I was looking for. Thanks!

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