sertit / eoreader

Remote-sensing opensource python library reading optical and SAR sensors, loading and stacking bands, clouds, DEM and spectral indices in a sensor-agnostic way.
https://eoreader.readthedocs.io/en/latest/
Apache License 2.0
278 stars 22 forks source link

ENH: Allow geographic-projected custom stacks #170

Open remi-braun opened 2 months ago

remi-braun commented 2 months ago

We could easily allow custom stacks with a geographic projection

Here is the code to create a VRT from the given input path:


# If we have an EPSG:4326 custom stack, reproject it
with rasterio.open(input_path) as ds:
    if ds.crs.is_geographic:
        utm_crs = gpd.GeoDataFrame(geometry=[geometry.from_bounds_to_polygon(*ds.bounds)], crs=ds.crs).estimate_utm_crs()
        with rasterio.vrt.WarpedVRT(ds, **{"crs": utm_crs.to_epsg()}) as vrt:
            utm_name = path.get_filename(input_path) + f"_{utm_crs.to_epsg()}.vrt"
            utm_path = str(output_folder / utm_name)
            rasterio.shutil.copy(vrt, utm_path, driver="vrt")
            input_path = utm_path

# Open the custom stack
prod = reader.open(
    input_path, 
    custom=True,
    sensor_type="OPTICAL",
    band_map=custom_band_map,
    pixel_size=pixel_size,
    remove_tmp=True
)