RasterIO 无法加载 VRT
我使用 rasterio 加载由 pymodis.convertmodis_gdal.createMosaicGDAL 生成的 VRT 文件。直到最近我重新安装了 Ubuntu OS 和 python 包,所以没问题,对于 rasterio。现在加载 VRT 文件时出现以下错误:
例如,我在MOD09A1__2018049__sur_refl_b01.vrt
ERROR 4: HDF4_EOS:EOS_GRID:/dev/sdf/MOD09A1/MOD09A1.A2000049.h20v04.006.2015136143235.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01: No such file or directory
Process ModisBaseGraph-4:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/rasterio/mask.py", line 182, in mask
out_image = raster.read(window=window, out_shape=out_shape, masked=True)
File "rasterio/_io.pyx", line 330, in rasterio._io.DatasetReaderBase.read
File "rasterio/_io.pyx", line 591, in rasterio._io.DatasetReaderBase._read
OSError: Read or write failed
该文件/dev/sdf/MOD09A1/MOD09A1.A2000049.h20v04.006.2015136143235.hdf
是有效路径,因此该文件确实存在!
虽然 GDAL-Python 可以加载它
当我使用 pyModis 将 HDF MODIS 切片镶嵌为 VRT 文件时,我验证了 .vrt 文件的优点。为此,我使用 python-gdal 加载文件并读取光栅数组。Python GDAL 一切顺利。我假设 rasterio 也基于 GDAL,所以我不明白为什么它会抛出上述异常。
In [1]: from osgeo import gdal
In [2]: ds = gdal.Open('MOD09A1__2018049__sur_refl_b01.vrt')
In [3]: band = ds.GetRasterBand(1)
In [4]: array = band.ReadAsArray()
VRT 文件示例
<VRTDataset rasterXSize="4800" rasterYSize="2400">
<SRS>PROJCS["unnamed",GEOGCS["Unknown datum based upon the custom spheroid",DATUM["Not specified (based on custom spheroid)",SPHEROID["Custom spheroid",6371007.181,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Sinusoidal"],PARAMETER["longitude_of_center",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]</SRS>
<GeoTransform>1111950.519667, 463.3127165279167, 0, 6671703.118, 0, -463.3127165279165</GeoTransform>
<VRTRasterBand dataType="Int16" band="1">
<NoDataValue>-28672</NoDataValue>
<ColorInterp>Gray</ColorInterp>
<ComplexSource>
<SourceFilename relativeToVRT="0">HDF4_EOS:EOS_GRID:/dev/sdf/MOD09A1/MOD09A1.A2018049.h20v03.006.2018060011348.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="2400" RasterYSize="2400" DataType="Int16" BlockXSize="2400" BlockYSize="32" />
<SrcRect xOff="0" yOff="0" xSize="2400" ySize="2400" />
<DstRect xOff="2399" yOff="0" xSize="2400" ySize="2400" />
<NODATA>-28672</NODATA>
</ComplexSource>
<ComplexSource>
<SourceFilename relativeToVRT="0">HDF4_EOS:EOS_GRID:/dev/sdf/MOD09A1/MOD09A1.A2018049.h19v03.006.2018060011204.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="2400" RasterYSize="2400" DataType="Int16" BlockXSize="2400" BlockYSize="32" />
<SrcRect xOff="0" yOff="0" xSize="2400" ySize="2400" />
<DstRect xOff="0" yOff="0" xSize="2400" ySize="2400" />
<NODATA>-28672</NODATA>
</ComplexSource>
</VRTRasterBand>
</VRTDataset>
操作系统和软件包版本
Ubuntu 16.04,Python 3.5.2 RasterIO 1.0a12 pyModis 2.0.9
以前当 rasterio 工作正常时,我使用 Python 2.7。我不确定迁移到 Python 3.5 是否是主要原因。