I have below python in order to reclassify many raster files such that a certain range of values are changed to 1 and the rest to NoData. The threshold value that determines which values should be changed to 10 or NoData are contained in an DBF file. A column in the DBF file contains the corresponding name of the raster files and its threshold. But the python was written in ARCGIS version 9.0. I have changed code in order to read in ARCGIS 10.0 but it has many errors. Anyone could help me to convert the python to ARCGIS 10.0? Thanks in advance.
inputDir = "c:\\tmp\\gis\\rasterReclass\\" # where all the rasters are located outputDir = "c:\\tmp\\gis\\rasterReclass\\" # where the output rasters are to be savedoutputPrefix = "R_" # prefix of the output rastersreclassTable = r"c:\tmp\gis\rasterReclass\reclassTable.dbf" # the reclass data tablefieldRasterName = "RASTERNAME" # column with the name of the rasterfieldRasterThreshold = "THRESHOLD" # column with the threshold valueimport win32com.client, sysGP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")GP.RefreshCatalog(inputDir)GP.RefreshCatalog(outputDir)total = 0ok = 0tableRows = 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 !"
أكثر...
inputDir = "c:\\tmp\\gis\\rasterReclass\\" # where all the rasters are located outputDir = "c:\\tmp\\gis\\rasterReclass\\" # where the output rasters are to be savedoutputPrefix = "R_" # prefix of the output rastersreclassTable = r"c:\tmp\gis\rasterReclass\reclassTable.dbf" # the reclass data tablefieldRasterName = "RASTERNAME" # column with the name of the rasterfieldRasterThreshold = "THRESHOLD" # column with the threshold valueimport win32com.client, sysGP = win32com.client.Dispatch("esriGeoprocessing.GPDispatch.1")GP.RefreshCatalog(inputDir)GP.RefreshCatalog(outputDir)total = 0ok = 0tableRows = 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 !"
أكثر...