satellogic / telluric

telluric is a Python library to manage vector and raster geospatial data in an interactive and easy way
MIT License
87 stars 18 forks source link

Minimum handling of rasters without CRS and avoid meaningless RecursionError #291

Closed marcronq closed 3 years ago

marcronq commented 3 years ago

It is known that GeoRaster2 class is not designed to support non-geographic rasters.

Right now if you try to copy a raster without CRS it raises a RecursionError because it tries to read over and over a None attribute. This can be triggered with the next lines:

import telluric
raster = telluric.GeoRaster2.open(
    "/vsicurl/https://github.com/satellogic/telluric/blob/master/tests/data/raster/no_georef.png?raw=true")
raster_copy = raster.copy_with()
print(raster_copy.crs)

To avoid this exception which is not really informative, I propose to differentiate between a crs not yet read (None) and one already read from file but non-existing or void which can be a rasterio.crs.CRS() instance without init arguments. This empty crs allows upper lines to work.

In the future, if a proper exception wants to be raised with the message that some method is not supported for this kind of rasters, the rasterio.crs.CRS property is_valid can be checked, which for an empty instance returns False.

I can create the PR with the proposal if maintainers think the idea is worth it.