【问题标题】:'str' object is not callable for GDAL proximity'str' 对象不可调用 GDAL 接近度
【发布时间】:2020-03-16 21:20:06
【问题描述】:

我对 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

【问题讨论】:

  • “继续获取 ''str' object is not callable' 错误消息。”Edit 你的问题并显示 完整回溯

标签: python string gis gdal


【解决方案1】:

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

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

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

gdal_proximity (proximityInput, proximityOutputPrj)

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

【讨论】:

  • 好的,谢谢!我愚蠢地认为我可以绕过我似乎无法理解的环境设置。当我删除该行时,我总是得到: NameError: name 'gdal_proximity' is not defined。我将处理我的环境设置并弄清楚。谢谢!
  • 我对@9​​87654324@了解不多,但如果你想在脚本中使用函数,你必须先导入它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
  • 2011-06-07
  • 2019-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多