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

Include a function to load multiple rasters on overlapping extent #272

Closed
adehecq opened this issue May 18, 2022 · 2 comments · Fixed by #307
Closed

Include a function to load multiple rasters on overlapping extent #272

adehecq opened this issue May 18, 2022 · 2 comments · Fixed by #307
Assignees
Labels
enhancement Feature improvement or request invalid This doesn't seem right

Comments

@adehecq
Copy link
Member

adehecq commented May 18, 2022

Let's say we want to compare a large raster and a small raster covering only a subsample of the larger raster. If the large raster is too large to fit in memory, or simply it takes long to load, it would be interesting to load the two rasters only over common area. Currently, doing this would require several lines of code. This is not really implemented if the two rasters have different CRS.

Same CRS:

r1 = gu.Raster(file1, load_data=False)
r2 = gu.Raster(file2, load_data=False)
intersection = r1.intersection(r2)
r1 = gu.Raster(file1, load_data=intersection)
r2 = gu.Raster(file2, load_data=intersection)

Different CRS:

r1 = gu.Raster(file1, load_data=False)
r2 = gu.Raster(file2, load_data=False)
intersection = gu.projtools.merge_bounds([r1.bounds, r2.get_bounds_projected(r1.crs)], "intersection")
r1 = gu.Raster(file1, load_data=intersection)
# Need to convert intersection into r2's CRS, which is not straightforward
r2 = gu.Raster(file2, load_data=intersection_r2)

Another option is to modify the behavior of Raster.reproject to not work on self.data, but on the dataset directly. This may become difficult after PR #265.

@adehecq adehecq added enhancement Feature improvement or request invalid This doesn't seem right labels May 18, 2022
@adehecq
Copy link
Member Author

adehecq commented May 18, 2022

Need to convert intersection into r2's CRS, which is not straightforward

Actually, this can be done in one line as in Raster.get_bounds_projected:
rio.warp.transform_bounds(src_crs, dst_crs, left, bottom, right, top, densify_pts)

@adehecq
Copy link
Member Author

adehecq commented Sep 15, 2022

Closed via #307

@adehecq adehecq closed this as completed Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature improvement or request invalid This doesn't seem right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant