Re: returning subset of raster data via API

Sean Gillies

Hi Tom,

On Mon, Aug 3, 2020 at 5:32 PM Tom Kralidis <tom.kralidis@...> wrote:

(sorry, just getting back to this!)

Thanks Sean. Indeed the MemoryFile strategy works as expected:

import sys

import rasterio
from import MemoryFile

with[1]) as src:
    with MemoryFile() as memfile:
        profile = src.profile
        with**profile) as dest:

Are there any known issues with reading/subsetting, and writing back a NetCDF via MemoryFile? Traceback:

(pygeoapi) (base) tomkralidis@aruba:~/Dev/pygeoapi/pygeoapi-tomkralidis$ python tests/data/ 
Traceback (most recent call last):
  File "rasterio/_io.pyx", line 1135, in rasterio._io.DatasetWriterBase.__init__
  File "rasterio/_err.pyx", line 205, in rasterio._err.exc_wrap_pointer
rasterio._err.CPLE_OpenFailedError: Unable to create netCDF file /vsimem/fa663a74-d548-494d-a2ab-880bdff831c4/fa663a74-d548-494d-a2ab-880bdff831c4. (Error code 2): No such file or directory .

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 9, in <module>
    with**profile) as dest:
  File "/Users/tomkralidis/opt/miniconda3/lib/python3.7/site-packages/rasterio/", line 382, in wrapper
    return f(*args, **kwds)
  File "/Users/tomkralidis/opt/miniconda3/lib/python3.7/site-packages/rasterio/", line 136, in open
    nodata=nodata, sharing=sharing, **kwargs)
  File "rasterio/_io.pyx", line 1139, in rasterio._io.DatasetWriterBase.__init__
rasterio.errors.RasterioIOError: Unable to create netCDF file /vsimem/fa663a74-d548-494d-a2ab-880bdff831c4/fa663a74-d548-494d-a2ab-880bdff831c4. (Error code 2): No such file or directory .


>>> import rasterio
>>> rasterio.__version__
>>> rasterio.gdal_version()



I don't use netcdf files with GDAL often and have never tried to write a netcdf file to vsimem. It could be that there is a combination of creation or config options required that I don't know about. I see some mention about platform requirements in but am not sure what to make of that.

Sean Gillies

Join to automatically receive all group messages.