In my previous question, FelixIP answered with the following script :
# Description:# muliple watersheds# ---------------------------------------------------------------------------# Import arcpy moduleimport arcpyfrom arcpy import envfrom arcpy.sa import Watershed# things to changepourPoints=r'd:\scratch\pour_points.shp'fDir=r'd:\scratch\fdir'outFolder=r'd:\aerials\images'radius=1000nPoints=3nProcessors=4env.workspace = outFolderenv.pyramid='NONE'env.rasterStatistics = 'NONE'fDir=arcpy.Raster(fDir)env.snapRaster = fDircSize=fDir.meanCellHeightenv.cellSize = cSizeext=arcpy.Describe(fDir).extentextract,wshed,rdlayer='xtrct','wshed','RL'def function(inputs): fid,pnt=inputs suffix=str(fid).zfill(4) quer='"FID" = '+str(fid); thePoint='layer'+suffix arcpy.MakeFeatureLayer_management(pourPoints,thePoint,quer) outFile='wshed_'+suffix+'.shp' i,nTotal=radius,1 while True: bFirst=cSize*i arcpy.AddMessage('Trying buffer %i' %bFirst) buf=pnt.buffer(bFirst) buf=buf.clip(ext) anExtent=buf.extent env.extent=anExtent envelope='%f %f %f %f' %(anExtent.XMin, anExtent.YMin, anExtent.XMax, anExtent.YMax,) arcpy.Clip_management(fDir,envelope,extract,buf) oneGrid=Watershed (extract, thePoint, "FID") oneGrid.save(wshed) lmax=arcpy.Raster(wshed) arcpy.MakeRasterLayer_management(lmax, rdlayer) tbl=arcpy.da.TableToNumPyArray(rdlayer,("value","count")) fLine=tbl[0] newTotal=fLine[1] if newTotal==nTotal: break nTotal=newTotal i=2*i arcpy.RasterToPolygon_conversion(lmax, outFile, "NO_SIMPLIFY", "Value") for elm in [extract,wshed]: arcpy.Delete_management(elm) arcpy.AddMessage ('Processed %i' %fid) return outFileif __name__ == "__main__": g = arcpy.Geometry() geometryList=arcpy.CopyFeatures_management(pourPoints,g) for i in range(0,nPoints,nProcessors): bList,m = [],0 for j in range(i,min(i+4,nPoints)): m+=1; bList.append([j,geometryList[j]]) for elm in bList: out=function(elm)It returns in the Output (of both PyScripter and ArcGIS the following error :
How can I fix this?
It's basically my fist time using Python, so I have no clue.
أكثر...
# Description:# muliple watersheds# ---------------------------------------------------------------------------# Import arcpy moduleimport arcpyfrom arcpy import envfrom arcpy.sa import Watershed# things to changepourPoints=r'd:\scratch\pour_points.shp'fDir=r'd:\scratch\fdir'outFolder=r'd:\aerials\images'radius=1000nPoints=3nProcessors=4env.workspace = outFolderenv.pyramid='NONE'env.rasterStatistics = 'NONE'fDir=arcpy.Raster(fDir)env.snapRaster = fDircSize=fDir.meanCellHeightenv.cellSize = cSizeext=arcpy.Describe(fDir).extentextract,wshed,rdlayer='xtrct','wshed','RL'def function(inputs): fid,pnt=inputs suffix=str(fid).zfill(4) quer='"FID" = '+str(fid); thePoint='layer'+suffix arcpy.MakeFeatureLayer_management(pourPoints,thePoint,quer) outFile='wshed_'+suffix+'.shp' i,nTotal=radius,1 while True: bFirst=cSize*i arcpy.AddMessage('Trying buffer %i' %bFirst) buf=pnt.buffer(bFirst) buf=buf.clip(ext) anExtent=buf.extent env.extent=anExtent envelope='%f %f %f %f' %(anExtent.XMin, anExtent.YMin, anExtent.XMax, anExtent.YMax,) arcpy.Clip_management(fDir,envelope,extract,buf) oneGrid=Watershed (extract, thePoint, "FID") oneGrid.save(wshed) lmax=arcpy.Raster(wshed) arcpy.MakeRasterLayer_management(lmax, rdlayer) tbl=arcpy.da.TableToNumPyArray(rdlayer,("value","count")) fLine=tbl[0] newTotal=fLine[1] if newTotal==nTotal: break nTotal=newTotal i=2*i arcpy.RasterToPolygon_conversion(lmax, outFile, "NO_SIMPLIFY", "Value") for elm in [extract,wshed]: arcpy.Delete_management(elm) arcpy.AddMessage ('Processed %i' %fid) return outFileif __name__ == "__main__": g = arcpy.Geometry() geometryList=arcpy.CopyFeatures_management(pourPoints,g) for i in range(0,nPoints,nProcessors): bList,m = [],0 for j in range(i,min(i+4,nPoints)): m+=1; bList.append([j,geometryList[j]]) for elm in bList: out=function(elm)It returns in the Output (of both PyScripter and ArcGIS the following error :
How can I fix this?
It's basically my fist time using Python, so I have no clue.
أكثر...