(1)返回数据列表的函数
ArcPy中提供了大量可以返回数据列表的函数,可以方便后续遍历数据。
函数名 | 说明 |
---|---|
ListFields(dataset, wild_card, field_type) | 返回数据集中的字段列表 |
ListIndexes(dataset, wild_card) | 返回数据集中属性索引列表 |
ListDatasets(wild_card, feature_type) | 返回工作空间中的数据集 |
ListFeatureClasses(wild_card, feature_type, feature_dataset) | 返回工作空间中的要素类 |
ListFiles(wild_card) | 返回工作空间中的文件 |
ListRasters(wild_card,raster_type) | 返回工作空间中的栅格数据 |
ListTables(wild_card, table_type) | 返回工作空间中的表 |
ListWorkspaces(wild_card, workspace_type) | 返回工作空间列表 |
ListVersions(sde_workspace) | 返回版本列表 |
参数说明:wild_card:字符串参数,用于过滤,支持通配符。
语法:ListFeatureClasses ( { wild_card }, { feature_type }, { feature_dataset } ) { }为可选参数
例:ListFeatureClasses ( "lr*”, "point" ) ——返回文件名以lr开头,并且要素类型是点的所有要素类
arcpy.env.workspace="c:/map.gdb"
fcs = arcpy.ListFeatureClasses("*","polygon")
fcCount = len(fcs)
(2)遍历数据列表
使用循环语句遍历。
dirPath = "D:/mapdata/test/worldshp"
arcpy.env.workspace=dirPath
ftClasses = arcpy.ListFeatureClasses()
for ftClass in ftClasses:
print(ftClass)
(3)返回工具、工具箱和环境设置列表的函数
工具列表:arcpy.ListTools({wildcard})
环境设置列表:arcpy.ListEnvironments({wildcard})
工具箱列表:arcpy.ListToolboxes({wildcard})
(4)遍历子目录
ArcPy中遍历目录以及子目录,需要使用arcpy.da.Walk
函数。Walk(top, topdown, onerror, followlinks, datatype, type)
返回结果是一个元组(dirpath, dirnames,filenames)
。
扫描二维码关注公众号,回复:
9927560 查看本文章
workspace = "D:/mapdata/test/china/"
for dirpath,dirnames,filenames in arcpy.da.Walk(workspace,datatype="FeatureClass",type="Point"):
print(dirpath,type(dirpath))
print(dirnames)
print(filenames)
作者:辛立
链接:https://www.jianshu.com/p/3355b6efc0d6
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。