Re: issue with opening/closing datasets
Amine Aboufirass <amine.aboufirass@...>
Dear Sean, 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?: def open_dataset(filename): with rasterio.open(filename) as dataset: return dataset def do_stuff_to dataset(dataset): dataset.write() return modified_dataset def get_info_from_dataset(dataset): dataset.information return information 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 :). Regards, Amine On Tue, Mar 26, 2019 at 2:56 PM Sean Gillies <sean.gillies@...> wrote:
|
|