As I'm using multiple functions in one process, I would like to pass results of each function to the next one using an In-memory File. I'm using Rasterio and I saw that there is a way to create In-memory files in the documentation, but unfortunately it seems like it's not working like usual files. I cannot use open(temporaryfile).meta.copy()
to get infos (GTIFF in my case) of the file.
Is there a way to correctly store everything as in a Gtiff file but in a memory file or do I have to process in another way ?
Best Answer
You may pass instances of
MemoryFile
or datasets opened from them to functions. For example:Note well that when the idented
with
block ends, the in-memory file is deleted. This is to give you control over memory allocation on your computer. The Rasterio dataset object is also closed at this point.If you pass them to functions after this, they can't be operated on. Keep your memory file open in your main program and all will be fine.