-2147221231,'ClassFactory无法提供请求的类',无,无

时间:2013-06-05 17:14:08

标签: python-2.7

我使用以下代码使用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文件。 在此感谢您提供任何急需的帮助/ 克里斯汀

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 !"

0 个答案:

没有答案