【问题标题】:Error reloading tif while exporting raster to tif using gdal in python在 python 中使用 gdal 将栅格导出到 tif 时重新加载 tif 时出错
【发布时间】:2016-07-12 17:45:13
【问题描述】:

我想通过以下步骤将我处理的栅格图层导出为 tif,在使用驱动程序创建 out.tif 栅格后,我无法将创建的 tif 文件加载回 python。我试图将“gdal.GDT_Int32”更改为其他类型,但没有成功。我也尝试使用而不是 'inds.GetDriver' 'GetDriverByName('GTiff') 但这也没有做任何更改,消息如下:

In [13]: driver.Create('out.tif', cols, rows, 1, gdal.GDT_Int32)
Out[13]: <osgeo.gdal.Dataset; proxy of <Swig Object of type 
'GDALDatasetShadow *
' at 0x000000000F437360> >

In [18]: outds=gdal.Open('out.tif')
-----------------------------------------------------------------------
RuntimeError                            Traceback (most recent call last)
<ipython-input-18-82ed958ff66e> in <module>()
----> 1 outds = gdal.Open('out.tif')

RuntimeError: `out.tif' not recognised as a supported file format.

或

In [14]: outds = gdal.Open('out.tif')
ERROR 4: `out.tif' not recognised as a supported file format.

我的代码:

#load inds for processing
inds = gdal.Open('in.tif', gdal.GA_ReadOnly)

cols = inds.RasterXSize
rows = inds.RasterYSize
driver = inds.GetDriver()


driver.Create('out.tif', cols, rows, 1, gdal.GDT_Int32)
**#The step with errors!**
**outds = gdal.Open('out.tif')**
outband = outds.GetRasterBand()
data = inds.GetRasterBand().ReadAsArray()

outds.SetGeoTransform(inds.GetGeoTransform())
outds.SetProjection(inds.GetProjection())

outband = outds.GetRasterBand()
outband.WriteArray(data)

【问题讨论】:

    标签: python-2.7 tiff raster gdal


    【解决方案1】:

    这个问题的解决方法与本次讨论中使用的方法相同: python-GDAL Write Array-issue

    通过这种方式修改代码:

    outds = driver.Create('day.tif', cols, rows, 1, gdal.GDT_Int32)
    

    而不是在预览帖中:

    driver.Create('out.tif', cols, rows, 1, gdal.GDT_Int32)
    outds = gdal.Open('out.tif')
    

    错误已解决。

    【讨论】:

      猜你喜欢
      • 2014-10-11
      • 1970-01-01
      • 2020-12-04
      • 2012-05-29
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      相关资源
      最近更新 更多