使用arcpy,我的目的是在列表中存储要素类以供进一步处理.每行都是一个{'field name': value}包含几何图形的字典.
实现此任务的最pythonic方法应该是使用list comprehension:
fc = '/path/to/fc'
fields = [f.name for f in arcpy.ListFields(fc)] # get field list
features = [[row.getValue(f) for f in fields] for row in arcpy.SearchCursor(fc)]
Run Code Online (Sandbox Code Playgroud)
此方法适用于数据,但列表中的几何图形都相同(在fc中检索的最后几何图形).SearchCursor的这种行为已经在StackOverflow上发表了评论.
我尝试了另一种方法:
fc = '/path/to/fc'
shape_field = arcpy.Describe(fc).shapeFieldName
# load geometry in a list
geom = arcpy.Geometry()
feat = [{shape_field: f} for f in arcpy.CopyFeatures_management(fc, geom)] # slow
# load data in a list
fields = [f.name for f in arcpy.ListFields(fc)]
data = [dict([(f, …Run Code Online (Sandbox Code Playgroud)