Re: issue with opening/closing datasets
Amine Aboufirass <amine.aboufirass@...>
I am slightly confused. You state the following:
The following will work if you are calling the two functions in the same module.
I have two issues with the above statement:
To be more explicit, can I do something like this?:
with rasterio.open(filename) as dataset:
def do_stuff_to dataset(dataset):
If so, then what are the disadvantages of using the with block inside a function and returning the object to be used outside? Is this good practice? If not what is the recommended way to write functions which use the rasterio library? This also extends to with blocks containing rasterio.Env(). Should I nest the with statement inside the function as stated above?
I ask because I would like to avoid writing a dataset to physical file until I am done modifying it. For instance, geopandas uses the GeoDataFrame construct which is stored in memory, and not attached to any physical file. Memory files in rasterio come close, but they are still attached to a temporary file.
It seems that in rasterio defining a raster object must be via 3 disjoint entities (numpy array, affine transform and CRS ). It would be nice to have one object which groups all these entities and is somehow detached from physical/temporary files. A sort of glorified numpy array with metadata (a "GeoNumpy" array), just like geopandas glorifies the pandas Dataframe with metadata.
Of course this is just a naive (but hopefully constructive) suggestion, and perhaps also due to the fact that I do not completely understand how the library works :).
On Tue, Mar 26, 2019 at 2:56 PM Sean Gillies <sean.gillies@...> wrote: