python - '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
解决方案
在您设置(覆盖)gdal_proximity
为以下字符串 的第三行代码中
gdal_proximity = "C:\\anaconda3\\envs\\geo_py37\\Scripts\\gdal_proximity.py"
然后,您尝试将其作为函数调用。
gdal_proximity (proximityInput, proximityOutputPrj)
这会触发您的错误,因为它不是函数,而是字符串,因此不能作为函数调用。
推荐阅读
- c++ - 如何修复未实现的纯虚方法错误?
- html - 显示与部署页面不同的 Google Cloud Shell 预览页面
- java - 非常基本的 Java 程序错误(“Hello world”)
- c# - 在特定时间过去后更新 UI 控件
- php - Laravel SoftDeletes 与 UpdateOrCreate 函数冲突
- reactjs - NextJs 项目版本从 9.0.1 升级到 9.0.4 的问题
- c# - 使用 Xml 文档 Member.Name 获取方法的 MethodInfo 的通用方法
- python - 将 Google 趋势图保存为静态图像?
- arrays - 为什么字节打印的列表不显示列表中每个数字的完全相同的十六进制数字?
- php - 检查未定义的php变量的最佳实践?