# 关于arcpy中批处理栅格及矢量文件的总结

0 篇文章 0 订阅

for root, dirs, folders in os.walk(path):
for folder in folders:
if (folder.endswith('.shp')):


import arcpy
from arcpy import env

env.workspace = arcpy.GetParameterAsText(0)
field = "VALUE"
outputworkspace = arcpy.GetParameterAsText(1)
files = arcpy.ListRasters("*","tif")
for file in files:
pos=file.index('.')
outfile=file[0:pos]
year=file[6:10]
outPolygons =outputworkspace + "/" + year + "/" + outfile
arcpy.RasterToPolygon_conversion(file, outPolygons, "SIMPLIFY", field)
print "finish"


for root, dirs, folders in os.walk(path):
for folder in folders:
if (folder.endswith('.shp')):
out_feature= outpath + "/" + folder #输出数据
upcur = arcpy.da.UpdateCursor(folder, “id”) #遍历数据字段“id”的所有行
for row in upcur:
if (row[0] == 0 or row[0] == 32767): #找出“id”中数字为0和32767的行
upcur.deleteRow() #删除行，即删除要素
arcpy.Clip_analysis(folder, outline_feature, out_feature, "") #剪切数据
arcpy.Delete_management(outline_feature) #删除矢量数据，根据自己需要选择这个功能
##添加面积字段


for root, dirs, folders in os.walk(path):
for folder in folders:
if (folder.endswith('.shp')):
#计算多边形面积
#arcpy.CalculateField_management(folder, "Areakm2", "!shape.geodesicArea@SQUAREKILOMETERS!", "PYTHON_9.3")
#将属性表内容读取并输出至TXT文档中
cursor2 = arcpy.da.SearchCursor(folder, ["name", "Areakm2"])
for row in cursor2:
f.write(str(row[0]) + " ")
f.write(str(row[1]) + '\r\n')


• 3
点赞
• 17
收藏
• 打赏
• 0
评论
11-21 129
01-07 2406
08-18 421
03-13 2908
05-13 6885
08-18 4150
01-07 1896
01-02 4044
10-27 1万+
12-19 3万+

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

weixin_42055454

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。