次のコードを使用して、Python を使用して一度に複数のラスターを再分類しています。「GP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")」行の後に、次のエラーが表示されます。
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
GP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")
File "C:\Python27\ArcGIS10.1\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\ArcGIS10.1\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\ArcGIS10.1\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221231, 'ClassFactory cannot supply requested class', None, None)
問題が何であるかを知っている人はいますか?また、reclassTable の下では、.dbf ではなく .csv の Excel ファイルを使用しています。それが理由でしょうか?.dbf ファイルの作成方法がわかりません。必要な助けをありがとう/ Kristin
コード
inputDir = "c:\\tmp\\gis\\rasterReclass\\" # where all the rasters are located
outputDir = "c:\\tmp\\gis\\rasterReclass\\" # where the output rasters are to be saved
outputPrefix = "R_" # prefix of the output rasters
reclassTable = r"c:\tmp\gis\rasterReclass\reclassTable.dbf" # the reclass data table
fieldRasterName = "RASTERNAME" # column with the name of the raster
fieldRasterThreshold = "THRESHOLD" # column with the threshold value
import win32com.client, sys
GP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")
GP.RefreshCatalog(inputDir)
GP.RefreshCatalog(outputDir)
total = 0
ok = 0
tableRows = GP.SearchCursor(reclassTable)
tableRow = tableRows.Next()
while tableRow:
print ""
total = total + 1
rasterName = tableRow.GetValue(fieldRasterName)
threshold = tableRow.GetValue(fieldRasterThreshold)
sourceRaster = inputDir + rasterName
print "Processing " + rasterName + " with threshold value " + str(threshold)
if GP.Exists(sourceRaster):
expression = "SetNull(\"" + sourceRaster + "\" < " + str(threshold) + ", 1)"
outputRaster = outputDir + outputPrefix + rasterName
try:
GP.SingleOutputMapAlgebra(expression, outputRaster)
print "... done"
ok = ok + 1
except:
print "... " + rasterName + " failed"
else:
print rasterName + " does not exists"
tableRow = tableRows.Next()
print "--------------------------"
print str(ok) + " out of " + str(total) + " rasters sucessfully reclassified !"