首页 > 解决方案 > 'str' 对象不可调用 GDAL 接近度

问题描述

我对 GDAL 库非常陌生(实际上从今天开始尝试),我很难弄清楚我在这里做错了什么。我正在尝试从 GDAL 执行 'proximity' 函数,但不断收到 ''str' object is not callable' 错误消息。谁能指出我做错了什么。

import os
from osgeo import gdal, osr
gdal_proximity = "C:\\anaconda3\\envs\\geo_py37\\Scripts\\gdal_proximity.py"


proximityInput = gdal.Open(folderPath + os.sep + "proximity_input.tif")
outputTemplate = gdal.Open(folderPath + os.sep + "output_template.tif")

######## Raster properties based on 'outputTemplate' ################
projection = outputTemplate.GetProjection()
ncols = outputTemplate.RasterXSize
nrows = outputTemplate.RasterYSize
bandCount = outputTemplate.RasterCount
upx, xres, xskew, upy, yskew, yres = outputTemplate.GetGeoTransform()
#####################################################################

driver = gdal.GetDriverByName('Gtiff')
proximityOutput = driver.Create(folderPath + os.sep + "proximity_output.tif", ncols, nrows, bandCount, gdal.GDT_Float32)
proximityOutput.SetGeoTransform([upx, xres, xskew, upy, yskew, yres])
proximityOutputPrj = distanceRaster.SetProjection(projection)

gdal_proximity (proximityInput, proximityOutputPrj)

追溯:

Traceback (most recent call last):
  File "C:/Users/antoi/.PyCharmCE2019.3/config/scratches/Radial_Linear_Mean.py", line 22, in <module>
    gdal_proximity(proximityInput, proximityOutputPrj)
TypeError: 'str' object is not callable

标签: pythonstringgisgdal

解决方案


在您设置(覆盖)gdal_proximity为以下字符串 的第三行代码中

gdal_proximity = "C:\\anaconda3\\envs\\geo_py37\\Scripts\\gdal_proximity.py"

然后,您尝试将其作为函数调用。

gdal_proximity (proximityInput, proximityOutputPrj)

这会触发您的错误,因为它不是函数,而是字符串,因此不能作为函数调用。


推荐阅读