I want to create a Python dictionary with a Feature class as the key and the fields of the feature class and domains of the feature class as separate values. I'm starting off by simply attempting to add a Feature class (as a key) and its respective feature types(as values) but I'm not sure how to build that out. here's what I am trying to do by using list comprehension but my dictionary is empty:
Dict = {fc.name: fc.featureType.values()for fc in arcpy.ListFeatureClasses(r"gdb")}
print Dict
Any clues on how I can start this off?
-
2As an alternative to list comprehension, and to try and learn more about using dictionaries with ArcPy I think you should start with an empty dictionary and then use Describe to determine and add the values as you iterate ListFeatureClasses.PolyGeo– PolyGeo ♦2016年08月04日 21:46:28 +00:00Commented Aug 4, 2016 at 21:46
-
Also, use the da cursors if you have ArcGIS 10.1 or higher, since they are at least 10 times faster than the 10.0 and prior cursors.Richard Fairhurst– Richard Fairhurst2016年08月04日 23:31:29 +00:00Commented Aug 4, 2016 at 23:31
-
Have a look at gis.stackexchange.com/a/188566/64785Midavalo– Midavalo ♦2016年08月05日 04:50:47 +00:00Commented Aug 5, 2016 at 4:50
2 Answers 2
As an alternative to list comprehension, and to try and learn more about using dictionaries with ArcPy I think you should start with an empty dictionary and then use Describe to determine and add the values as you iterate ListFeatureClasses.
The * argument passes all fields into arcpy.da.SearchCursor. The fields function returns a list of all the fields in your feature class.
fcs = arcpy.ListFeatureClasses()
features = {}
for fc in fcs:
cursor = arcpy.da.SearchCursor(fc, '*')
features[fc] = list(cursor.fields)