如何遍历mxd中图层的字段列表

需求:

如何遍历mxd(工程文档)中图层(layer)的字段列表以及获取字段的名称、类型和字段长度等信息


脚本如下:

# -*- coding:utf-8 -*-

import arcpy

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"D:\data\listfiled\test.mxd")
layers = mapping.ListLayers(mxd)
for lyr in layers:
    print(lyr.name)

    descFC=arcpy.Describe(lyr)
    flds = descFC.fields
    for fld in flds:
        print "Field: " + fld.name
        print "Type: " + fld.type
        print "Length: " + str(fld.length)

结果:

D:\\app\\desktop108\\Python27\\ArcGIS10.8\\python.exe D:/java/pycharmExample/ArcpyExample/ArcMapPython32/Listfields.py

AAAAA风景名胜区

Field: OBJECTID

Type: OID

Length: 4

Field: Shape

Type: Geometry

Length: 0

Field: Name

Type: String

Length: 320

Field: 游客人数

Type: Integer

Length: 4

Field: 旅游收益

Type: Integer

Length: 4

北京

Field: OBJECTID

Type: OID

Length: 4

Field: SHAPE

Type: Geometry

Length: 0

Field: PAC

Type: Integer

Length: 4

Field: NAME

Type: String

Length: 60

Field: 地区生产总值_2017

Type: Double

Length: 8

Field: 人口_2017

Type: Single

Length: 4

Field: 人口_2010

Type: Single

Length: 4

Field: SHAPE_Length

Type: Double

Length: 8

Field: SHAPE_Area

Type: Double

Length: 8

Field: height

Type: SmallInteger

Length: 2

Field: group1

Type: SmallInteger

Length: 2

Field: pop

Type: Double

Length: 8

Field: test

Type: Double

Length: 8

水系面

Field: OBJECTID

Type: OID

Length: 4

Field: Shape

Type: Geometry

Length: 0

Field: GB

Type: Integer

Length: 4

Field: HYDC

Type: String

Length: 8

Field: NAME

Type: String

Length: 60

Field: PERIOD

Type: String

Length: 20

Field: VOL

Type: String

Length: 2

Field: Shape_Length

Type: Double

Length: 8

Field: Shape_Area

Type: Double

Length: 8

 

Process finished with exit code 0

 

参考资料:

https://www.jianshu.com/p/77e114fbdaaa

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值