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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 4, 2016 at 21:36
3
  • 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. Commented 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. Commented Aug 4, 2016 at 23:31
  • Have a look at gis.stackexchange.com/a/188566/64785 Commented Aug 5, 2016 at 4:50

2 Answers 2

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.

answered Oct 3, 2016 at 2:10
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)
answered Jun 26, 2019 at 23:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.