分享

在Zonal Statistics工具中使用重叠的区

 昵称QAb6ICvc 2013-01-31
 Howto: 在Zonal Statistics工具中使用重叠的区

文章编号: 39516

软件:  ArcGIS - ArcEditor 9.3, 9.3.1, 10 ArcGIS - ArcInfo 9.3, 9.3.1, 10 ArcGIS - ArcView 9.3, 9.3.1, 10

操作系统: N/A


摘要:

提供的脚本用于对相互重叠的区进行Zonal Statistics计算。
当使用多边形要素作为Zonal Statistics工具的区时,该工具会将多边形要素栅格化。如果多边形要素存在的重叠,栅格化会导致数据丢失。
Zonal Statistics中的这一缺陷,可以通过使用python逐一处理单个要素来解决。

内容:


# 导入系统模块
import arcgisscripting, os

# 创建Geoprocessor对象
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = 1

# 检查许可
gp.CheckOutExtension("Spatial")

#设置默认工作空间
gp.workspace = "C:/Data"

# 设置变量
raster = "measurements.tif"
inFC = "zone_features.shp"
outTable = "zonal_stats.dbf"
DBF_dir = "dbf" #folder for temp dbf outputs

if not os.path.exists(DBF_dir):
os.mkdir(DBF_dir)

#循环处理要素
inRows = gp.searchcursor(inputFC)
inRows.reset()
inRow = inRows.next()

while inRow:
# Zone_ID is the assumed name of the zone field
print "{0} is being processed".format(inRow.Zone_ID)
lyr = "Zone {0}".format(inRow.Zone_ID)
gp.MakeFeatureLayer_management(inFC, lyr, '"FID" = {0}'.format(inRow.FID))
tempTable = "{0}/DBF_{1}.dbf".format(DBF_dir, inRow.Test)
gp.ZonalStatisticsAsTable_sa(lyr, "Zone_ID", raster, tempTable, "DATA")
inRow = inRows.next()

#设置临时DBF文件的存储路径
gp.workspace = DBF_dir
TableList = gp.ListTables("*")

#合并临时DBF文件
gp.Merge(TableList, outTable)
 


 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多