import arcpy fc = r'C:\Users\cfricke.GISINC\Documents\BOMBED\Test.gdb\Stores' cursor = arcpy.SearchCursor(fc) fields = arcpy.ListFields(fc) geo = arcpy.Describe(fc).ShapeFieldName idField = arcpy.Describe(fc).OIDFieldName ### # Part A # Output Cursor into List of Dictionaries # Print ObjectID and Shape at each iteration ### fcList = [] for row in cursor: fcDict = {} for field in fields: fcDict[field.name] = row.getValue(field.name) if field.name == geo: print "%s - %s" % (row.getValue(idField), row.getValue(field.name).getPart()) fcList.append(fcDict) del fcDict print "" print "************" print "" ### # Part B # Loop through list of dictionary, print objectID and shape ### for x in fcList: print "%s - %s" % (x[idField],x[geo].getPart()) del fcList
import arcpy fc = r'C:\Users\cfricke.GISINC\Documents\BOMBED\Test.gdb\Stores' cursor = arcpy.SearchCursor(fc) fields = arcpy.ListFields(fc) geo = arcpy.Describe(fc).ShapeFieldName idField = arcpy.Describe(fc).OIDFieldName ### # Part A # Output Cursor into List of Dictionaries # Print ObjectID and Shape at each iteration ### fcList = [] for row in cursor: fcDict = {} for field in fields: if field.name == geo: fcDict[field.name] = str((row.getValue(field.name)).getPart()) print "%s - %s" % (row.getValue(idField), (row.getValue(field.name)).getPart()) else: fcDict[field.name] = row.getValue(field.name) fcList.append(fcDict) del fcDict print "" print "************" print "" # ### # # Part B # # Loop through list of dictionary, print objectID and shape # ### for x in fcList: # for every feature print "%s - %s" % (x[idField], x[geo])
import arcpy fc = r'C:\Users\cfricke.GISINC\Documents\BOMBED\Test.gdb\Stores' cursor = arcpy.SearchCursor(fc) fields = arcpy.ListFields(fc) geo = arcpy.Describe(fc).ShapeFieldName idField = arcpy.Describe(fc).OIDFieldName ### # Part A # Output Cursor into List of Dictionaries # Print ObjectID and Shape at each iteration ### fcList = [] for row in cursor: fcDict = {} for field in fields: if field.name == geo: fcDict[field.name] = [row.getValue(field.name).firstPoint.X, row.getValue(field.name).firstPoint.Y, row.getValue(field.name).firstPoint.Z, row.getValue(field.name).firstPoint.M]# add the geo data as a list print "%s - %s" % (row.getValue(idField), (row.getValue(field.name)).getPart()) else: fcDict[field.name] = row.getValue(field.name) fcList.append(fcDict) del fcDict print "" print "************" print "" # ### # # Part B # # Loop through list of dictionary, print objectID and shape # ### for x in fcList: # for every feature print "%s - %s" % (x[idField], x[geo])
Chris:
This code is all with the old style cursors and direct reading of the shape field into the dictionary. Did you ever try using a da cursor and a filtered field list that used the "SHAPE@" field value to populate the dictionary? Did it cause the same corruption problems?
The use of the dictionary is sooo much faster than an embedded cursor pair or repeated use of select by attribute queries for feature matching when there is a matching attribute key. If the Shape geometry could transfer or be read from the dictionary it would be so much better.
If using a dictionary is still not possible, have you come up with any alternative processing algorithm that avoids the exponential loop growth of an embedded cursor pair routine or the slow processing of repeatedly doing a Search by Attribute for one feature match at a time? For example, is it possible that loading the source/read-only FC into an inmemory FC could speed up either the embedded cursors or repeated search by attribute queries.rather than doing these routines directly against the on-disk FC?
Richard,
reading fc records of geometry and attributes into a dictionary for further processing works a treat (at the mo on v10.2).
Used it often recently to do geometry comparisons (intersect etc).
Cheers,
Neil
Hi Richard,
Well I guess it seems to work well now. Here's a somewhat recent example: https://community.esri.com/message/362783#362783
In that message I tried to goad someone from ESRI to give an explanation and/or assurance everything was a-okay now, but no takers.