[gdal-dev] ERROR when requesting raster data outside coverage of VRT
Even Rouault
even.rouault at spatialys.com
Wed Apr 26 02:27:15 PDT 2017
On mercredi 26 avril 2017 09:16:49 CEST Casper Børgesen wrote:
> Hi,
>
> I am trying to read some floating point data from a VRT file. The VRT file
> references a set of VRT files which again references a set of GeoTIFF
> files.
>
> Using Python I call dataset.ReadAsArray(x, y, width, height) to request the
> data. In my case I end up requesting data which is outside the bounds of
> the VRT file resulting in the following error:
>
> ERROR 5: my.vrt, band 1: Access window out of range in RasterIO().
> Requested (1129975,637475) of size 2550x2550 on raster of 1132500x885000.
>
> If I was working with a normal GeoTIFF file I could calculate if I was
> outside the bounds and crop my request accordingly.
Well, a VRT dataset is a GDAL dataset, so there's no difference from API usage when
requesting a VRT or a GeoTIFF
You can use ds.RasterXSize / ds.RasterYSize to know the VRT dimensions and check if x +
width > ds.RasterXSize or y + height > ds.RasterYSize
> But since I am working
> with a VRT file I don't know how to determine if the VRT file has coverage
> or not. I vaguely remember a similar issue with gdal_translate which was
> fixed to allow requesting data partially and completely outside the bounds
> of the VRT file and just return zero (?) on the cells outside.
This is indeed a conveniency of gdal_translate itself. Using ReadAsArray() you must stick to
the dataset dimensions.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170426/d23382e6/attachment.html>
More information about the gdal-dev
mailing list