“str”对象不能为GDAL邻近性调用

2024-10-02 16:33:31 发布

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

我对GDAL库非常陌生(实际上从今天起就开始尝试),我很难弄清楚我在这里做错了什么。我正试图从GDAL执行“接近度”函数,但不断获取“str”对象不可调用”错误消息。 谁能告诉我我做错了什么

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

Tags: pyimportoutputosopensepgdaltif
1条回答
网友
1楼 · 发布于 2024-10-02 16:33:31

在第三行代码中,您将gdal_proximity设置为以下字符串

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

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

gdal_proximity (proximityInput, proximityOutputPrj)

这会触发错误,因为它不是函数,它是字符串,所以不能作为函数调用

相关问题 更多 >