Re: tempfile.NamedTemporaryFile behaving as /vsimem and eating all the machine memory
toggle quoted messageShow quoted text
This is expected (if not well-documented) behavior. tempfile.NamedTemporaryFile() returns an open Python file object, not a filename. GDAL can't use a Python file object, so in that case rasterio.open reads all the bytes from the file object, copies them to the vsimem filesystem, and opens that vsimem file.
I think what you want do do is pass the name of the temp file object to GDAL. Like this:
with tempfile.NamedTemporaryFile() as temp:
with rasterio.open(temp.name) as dataset:
No copy in the vsimem filesystem will be made.
On Tue, Apr 16, 2019 at 6:55 AM <vincent.sarago@...> wrote:
While working on https://github.com/cogeotiff/rio-cogeo/pull/75 we noticed strange behaviors with `vsimem` driver (this could be a GDAL but TBH).