0

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?

  • 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. – PolyGeo Aug 4 '16 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 Aug 4 '16 at 23:31
  • Have a look at gis.stackexchange.com/a/188566/64785 – Midavalo Aug 5 '16 at 4:50
1

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.

0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.