为什么gdal不能打开geotiff?

2024-09-25 00:30:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python和地理处理的新手。我正在写一些程序来计算ndwi。为此,我尝试用gdal打开geotiff数据集,但无法打开dataset。我试图打开不同的tiff文件(Landsat8多个数据、Landsat7复合数据等),但dataset总是没有。 这可能是什么原因?或者我怎么才能知道呢?在

以下是部分代码:

import sys, os, struct
import gdal, gdalconst

from gdalconst import *
import numpy as np
from numpy import *

class GDALCalcNDWI ():

  def calcNDWI(self, outFilePath):

    gdal.AllRegister()
    # this allows GDAL to throw Python Exceptions
    gdal.UseExceptions()

    filePath = "C:\\Users\\Daria\\Desktop.TIF\\170028-2007-05-21.tif"

    # Open
    dataset = gdal.Open(filePath, gdal.GA_ReadOnly)
    # Check
    if dataset is None:
      print ("can't open tiff file")
      sys.exit(-1)

谢谢


Tags: 数据fromimport程序numpysysopen地理
1条回答
网友
1楼 · 发布于 2024-09-25 00:30:57

每当您有一个著名的文件读取器返回None,请确保文件的路径是正确的。我怀疑您是否有一个名为Desktop.TIF的目录,我想您只是在源代码中犯了一个错误。您可能希望C:\\Users\\Dara\\Desktop\\TIF\\170028-2007-05-21.tif作为路径(请注意,Desktop.TIF==>;Desktop\\TIF)。在

最安全的做法是右键单击该文件,转到properties,然后将该路径复制/粘贴到python源代码中。在

相关问题 更多 >