- 积分
- 25445
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-12-13
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
近期需要用到种子蔓延分析,做基于DEM的有源洪水淹没分析。简单即是下:有源淹没是指水流收到地表起伏特征的影响,某些地方即使处于低洼处,也可能由于地形阻隔而不会被淹没。也就是说不仅要考虑哪些地方地势低还要考虑这些地方是否联通。而种子蔓延算法指给定空间中一点,从它周围的四个方向或8个方向,考虑:一周围点的地势是否低于种子点;二地势低于种子点的点是否联通;
简单说这些,我找到网上已有的代码:http://cadesign.cn/bbs/thread-742-1-1.html
先在此感谢作者,但由于是草稿,未做优化,在使用中出现了问题。主要问题即是,代码运行效率低,很长时间没有运行结果。现将代码复制如下,请各位大神帮帮忙:
- import arcpy
- from arcpy import env
- from arcpy.sa import *
- import copy
-
- #original_para
- worksapce_path=r"D:\GISForDesign_2\data"
- submerge_dem=r"D:\GISForDesign_2\data\DemMerge_Clip.tif"
- submerge_region=r"D:\GISForDesign_2\data\submergesAreaSmall.shp"
- seed=r"D:\GISForDesign_2\data\seed.shp"
- env.overwriteOutput=True
-
- #environment
- env.workspace=worksapce_path
- env.overwriteOutput=True
-
- submergeAreaName=worksapce_path+r"\submergeArea.tif"
- submergeArea=arcpy.Clip_management(submerge_dem,"",submergeAreaName,submerge_region,"","ClippingGeometry")
-
- floodLevel=1200
-
- #arcpy.SetProgressor("step", "submergeCal...",0, fc_count, 1)
-
- elevationCell={}
- #rowCount=arcpy.GetRasterProperties_management(submergeArea,"ROWCOUNT")
- #columnCount=arcpy.GetRasterProperties_management(submergeArea,"COLUMNCOUNT")
- cellXSzie=arcpy.GetRasterProperties_management(submergeArea,"CELLSIZEX")
- cellYSzie=arcpy.GetRasterProperties_management(submergeArea,"CELLSIZEY")
- leftPosition=arcpy.GetRasterProperties_management(submergeArea,"LEFT")
- topPosition=arcpy.GetRasterProperties_management(submergeArea,"TOP")
- bottomPosition=arcpy.GetRasterProperties_management(submergeArea,"BOTTOM")
-
- rstArray=arcpy.RasterToNumPyArray(arcpy.Raster(submergeArea))
- rows,cols=rstArray.shape
- for rowNum in xrange(rows):
- for colNum in xrange(cols):
- elevationCell[(rowNum,colNum)]=[rstArray.item(rowNum,colNum),False]
-
-
- for row in arcpy.da.SearchCursor(seed,["SHAPE@XY"]):
- seedXY=row[0]
- del row
-
- #seedValue=arcpy.GetCellValue_management(submergeArea,"%s %s" % seedXY)
- #originalCordi=arcpy.ExportRasterWorldFile_management (submergeArea)
-
-
-
- XNum=(seedXY[0]-float(leftPosition[0]))//float(cellXSzie[0])
- YNum=(seedXY[1]-float(topPosition[0]))//float(cellYSzie[0])
- seedCoordi=(int(abs(XNum)),int(abs(YNum)))
-
-
- def floodCal(floodList,floodLevel):
- #if len(floodList)>0:
- x=floodList[0][0]
- y=floodList[0][1]
- elevationCellCopy[floodList[0]][1]=True
- floodList.pop(0)
- for i in range(x-1,x+2):
- for j in range(y-1,y+2):
- if ((i,j) in positionKeys and elevationCellCopy[(i,j)][1]==False and elevationCellCopy[(i,j)][0]<=floodLevel):
- elevationCellCopy[(i,j)][1]=True
- floodList.append((i,j))
-
- '''
- def recursion(floodList,floodLevel):
- if len(floodList)==0:
- return 1
- else:
- floodCal(floodList,floodLevel)
- return recursion(floodList,floodLevel)
- '''
-
- #import sys
- #sys.setrecursionlimit(1000)
-
- elevationCellCopy=copy.deepcopy(elevationCell)
- positionKeys=elevationCellCopy.keys()
- floodList=[]
- if elevationCell[seedCoordi][0]<=floodLevel:
- floodList.append(seedCoordi)
-
- while True:
- if (len(floodList)==0):break
- floodCal(floodList,floodLevel)
-
- for rowNum in xrange(rows):
- for colNum in xrange(cols):
- rstArray[(rowNum,colNum)]=elevationCellCopy[(rowNum,colNum)][1]
-
-
-
- resultSubmerge=arcpy.NumPyArrayToRaster(rstArray,arcpy.Point(leftPosition[0],bottomPosition[0]),float(cellXSzie[0]),float(cellYSzie[0]))
-
-
-
- #recursion(floodList,floodLevel)
-
-
-
-
- '''
- for i in range(x-1,x+2):
- for j in range(y-1,y+2):
- if ((i,j) in positionKeys and elevationCellCopy[(i,j)][1]==False and elevationCellCopy[(i,j)][0]<=floodLevel):
- print((i,j),elevationCellCopy[(i,j)])
-
-
-
- FalseRaster=arcpy.sa.Con(submergeArea,0,0,"Value>=0")
- FalseRaster=submergeArea+FalseRaster
-
- demToPointsName=worksapce_path+r"\demToPoints.shp"
- demToPoint=arcpy.RasterToPoint_conversion(submergeArea,demToPointsName,"Value")
- '''
复制代码
|
|