christophfricke

SHAPE from Cursor doesn't save correctly in List of Dictionaries

Discussion created by christophfricke on Jul 7, 2011
Latest reply on Sep 2, 2014 by csny490
I am having an issue with this bit of python. 

Basically I open up a cursor to loop through a feature class.  At each row, I take every field and put the values in a dictionary.  I then append this to a list.  I am specifically interested in ObjectID and SHAPE

Next I unpack the list of dictionaries and print the ObjectID and SHAPE.

For some reason the SHAPE component isn???t saved properly.  But the ObjectID is.  I think this is a  bug with ArcPy, but it could just as likely be a bug with my code.


I get the following output:

1 - -8359910.19268255 4842313.47802997 NaN NaN
2 - -8353926.32475581 4846897.25034694 NaN NaN
3 - -8359087.54168308 4842848.29488585 NaN NaN

************

1 - -8359087.54168308 4842848.29488585 NaN NaN
2 - -8359087.54168308 4842848.29488585 NaN NaN
3 - -8359087.54168308 4842848.29488585 NaN NaN




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

Outcomes