arcpy中批量读取多个矢量文件的属性表

利用arcpy实现批量读取矢量文件属性表:(1)读取每个矢量文件包含多少个对象 (2)读取每个矢量文件每个字段对应的值。

#导入包
>>> import os
>>> import arcpy
#设置默认的工作环境
>>> arcpy.env.workspace=r"******"
#读取默认工作环境中得所有要素文件(.shp)文件,并将文件名保存为列表List
>>> List=arcpy.ListFeatureClasses()
#读取文件夹中得第一个shp文件得所有字段名称
>>>for i in List[0:1]:
...     fields=arcpy.ListFields(i)
...     for f in fields:
...         print(f.name)
输出结果:
FID
Shape
GRIDCODE
Area
#说明shp文件属性表中有FID、Shape 、GRIDCODE和Area四个字段
#依次读取shp文件中Area字段的值
for i in List:
...     shpfields=["Area"]
...     shp_List = []
...     shprows = arcpy.SearchCursor(i, shpfields)
...     while True:    
...         shprow = shprows.next()
...         if not shprow:
...             break
...         shp_List.append(shprow.Area)
...     for j in range(0,len(shp_List)):
...         print(i,shp_List[j])
输出结果:
(u'20181002t025539_20181002t025937_t50tmk.shp', 142027662.006)
(u'20181005t030549_20181005t030637_t50tmk.shp', 143648362.606)
(u'20181007t025601_20181007t030202_t50tmk.shp', 142296982.028)
(u'20181017t025711_20181017t030259_t50tmk.shp', 143914358.642)
(u'20181027t025811_20181027t030402_t50tmk.shp', 146175457.06)
......
(u'20220419t025551_20220419t030348_t50tmk.shp', 161952378.851)
(u'20220502t030551_20220502t031405_t50tmk.shp', 159937453.891)
(u'20220522t030551_20220522t031519_t50tmk.shp', 157370909.99)
(u'20220601t030551_20220601t031520_t50tmk.shp', 157310955.682)
(u'20220623t025529_20220623t030357_t50tmk.shp', 157979052.551)

参考资料

https://blog.csdn.net/gognzixiaobai666/article/details/112666377

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值