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

[POC] Simplify the creation of an ROI for a user. #602

Open
adebardo opened this issue Oct 14, 2024 · 3 comments · May be fixed by GlacioHack/geoutils#642
Open

[POC] Simplify the creation of an ROI for a user. #602

adebardo opened this issue Oct 14, 2024 · 3 comments · May be fixed by GlacioHack/geoutils#642

Comments

@adebardo
Copy link

adebardo commented Oct 14, 2024

Context

The goal of this task is to enable the creation of an ROI (Region of Interest) in PIXEL when loading a DEM. Although this ticket is proposed in the xDEM repository, the developments are intended for implementation in the geoUtils project.

To achieve this, we propose adding a parameter to the DEM creation [here](https://github.com/GlacioHack/xdem/blob/main/xdem/dem.py#L94). Using rasterio's Window option, we will load only the desired area. The resulting API would look like this:

dem = xdem.DEM("path/to/dem", roi={"left": "xmin", "bottom": "ymin", "right": "xmax", "top": "ymax"})

Code

  1. Modify the RASTER class

    • Add the parameter self._ROI, which can be either a dictionary or None.
    • Handle cases where the file is on disk: here.
    • Case 2 : DEM as dictionnary, add ROI if existing and adapt Raster.from_array .
    • Case 3 : If already a raster, add ROI if existing and adapt.
  2. Update data loading

    Example of window creation:

    w = src.read(1, window=Window(0, 0, 512, 256))

Tests + Documentation Update**

Tests and documentation must be updated to reflect these changes.

@adebardo adebardo added the [POC] Conception stuck The issue conception is stopped label Oct 14, 2024
@rhugonnet
Copy link
Member

The functions I was mentioning from GeoUtils that could be used to create an RIO in any CRS using a bounding box from any another CRS:
https://github.com/GlacioHack/geoutils/blob/5d4fab11483f7269e613e7ce18850cc45c67f9ad/geoutils/projtools.py#L404 (footprint) and https://github.com/GlacioHack/geoutils/blob/5d4fab11483f7269e613e7ce18850cc45c67f9ad/geoutils/projtools.py#L338 (bbox)
And (you probably know this well) the Rasterio bounding box is generally created this way:
https://github.com/GlacioHack/geoutils/blob/5d4fab11483f7269e613e7ce18850cc45c67f9ad/geoutils/raster/raster.py#L2537

@adebardo adebardo removed the [POC] Conception stuck The issue conception is stopped label Dec 13, 2024
@adebardo
Copy link
Author

@vschaffn , as planned, I’ve drafted an initial outline for implementing an ROI pixel. I estimate it will take you about two days of development work. If you’d like, you can first refine this version or alternatively propose one with a georeferenced ROI, in which case I believe you’ll need the full five days.

@vschaffn
Copy link
Contributor

Example of the desired API:

The geographical coordinates of the ROI should be defined with keys (left, bottom, right, top) with an optional crs.

# Georeferenced ROI
dem = xdem.DEM("path/to/dem", roi={"left": 40.5, "bottom": 38.0, "right": 44.0, "top": 41.0,  "crs": "EPSG:32718"})

The pixel-based coordinates of the ROI should be defined with keys (x, y, w, h) where (x, y) top-left corner coordinates and (w, h) the dimensions (width, height) in pixels.

# Pixel-based ROI
dem = xdem.DEM("path/to/dem", roi={"x": 50, "y": 100, "w": 1000, "h": 500})

Code

  1. Handle Georeferenced ROI:
  • If a georeferenced ROI is provided, convert the georeferenced coordinates into pixel indices using the raster's transform and CRS.

Tests

  • Add a test test_raster_with_roi to verify the correct behavior when loading raster data with a ROI.
    This should includes testing both pixel-based and georeferenced ROIs to ensure the raster is properly cropped and the data matches the expected output.

  • Update tests test_init and test_from_array to validate behavior when a ROI is proided for rasters initialized from array or raster.

Documentation

  • Update raster documentation to explain the new roi parameter in the Rasterclass.

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

Successfully merging a pull request may close this issue.

3 participants