<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165312#M12709</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chris:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code is all with the old style cursors and direct reading of the shape field into the dictionary.&amp;nbsp; Did you ever try using a da cursor and a filtered field list that used the "SHAPE@" field value to populate the dictionary?&amp;nbsp; Did it cause the same corruption problems?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; If the Shape geometry could transfer or be read from the dictionary it would be so much better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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?&amp;nbsp; 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?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 31 Aug 2014 07:02:32 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2014-08-31T07:02:32Z</dc:date>
    <item>
      <title>SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165308#M12705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having an issue with this bit of python.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically I open up a cursor to loop through a feature class.&amp;nbsp; At each row, I take every field and put the values in a dictionary.&amp;nbsp; I then append this to a list.&amp;nbsp; I am specifically interested in ObjectID and SHAPE&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next I unpack the list of dictionaries and print the ObjectID and SHAPE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For some reason the SHAPE component isn???t saved properly.&amp;nbsp; But the ObjectID is.&amp;nbsp; I think this is a&amp;nbsp; bug with ArcPy, but it could just as likely be a bug with my code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following output:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1 - -8359910.19268255 4842313.47802997 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 - -8353926.32475581 4846897.25034694 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 - -8359087.54168308 4842848.29488585 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;************&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1 - -8359087.54168308 4842848.29488585 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 - -8359087.54168308 4842848.29488585 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 - -8359087.54168308 4842848.29488585 NaN NaN&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;

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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcDict = {}
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcDict[field.name] = row.getValue(field.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == geo:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s - %s" % (row.getValue(idField), row.getValue(field.name).getPart())
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList.append(fcDict)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del fcDict

print ""
print "************"
print ""

###
# Part B
# Loop through list of dictionary, print objectID and shape
###
for x in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s - %s" % (x[idField],x[geo].getPart())

del fcList
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 12:32:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165308#M12705</guid>
      <dc:creator>ChristopherFricke1</dc:creator>
      <dc:date>2011-07-07T12:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165309#M12706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Christoph,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know much about this stuff, but it would appear that the SHAPE info is being stored as an arcobjects object (i.e. not a Python data type). Python asks Arc for the object, but it appears that only the most recent object is returned - this is why it later gets stuck on the last SHAPE info it read.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you convert the SHAPE info to a string when you read it, shown below, the output looks correct, but it isn't particularly useful if you want to do something else with the point at a later stage...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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: 
&amp;nbsp; if field.name == geo:
&amp;nbsp;&amp;nbsp; fcDict[field.name] = str((row.getValue(field.name)).getPart())
&amp;nbsp;&amp;nbsp; print "%s - %s" % (row.getValue(idField), (row.getValue(field.name)).getPart())
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp; 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])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want the SHAPE data as numbers (more useful if you wanted to do some processing, etc., at a later stage), you could do something like this (more complex stuff would be required for lines, polygons, etc.):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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: 
&amp;nbsp; if field.name == geo:
&amp;nbsp;&amp;nbsp; 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
&amp;nbsp;&amp;nbsp; print "%s - %s" % (row.getValue(idField), (row.getValue(field.name)).getPart())
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp; 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])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can now use the X, Y, Z (=None), and M (=None) data after you use indexes to the list to fetch them... Hope this is helpful!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:37:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165309#M12706</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T08:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165310#M12707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks.&amp;nbsp; I was suspecting that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 15:39:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165310#M12707</guid>
      <dc:creator>ChristopherFricke1</dc:creator>
      <dc:date>2011-07-12T15:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165311#M12708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Read this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/17956-Using-centroid-geometry-to-get-values-of-intersecting-feature?p=58625&amp;amp;viewfull=1#post58625"&gt;http://forums.arcgis.com/threads/17956-Using-centroid-geometry-to-get-values-of-intersecting-feature?p=58625&amp;amp;viewfull=1#post58625&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;and the posts below it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically, we came to the same conclusion: You can't directly store/use the geometry object in a Python dictionary.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 16:18:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165311#M12708</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-07-12T16:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165312#M12709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chris:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code is all with the old style cursors and direct reading of the shape field into the dictionary.&amp;nbsp; Did you ever try using a da cursor and a filtered field list that used the "SHAPE@" field value to populate the dictionary?&amp;nbsp; Did it cause the same corruption problems?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; If the Shape geometry could transfer or be read from the dictionary it would be so much better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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?&amp;nbsp; 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?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Aug 2014 07:02:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165312#M12709</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-08-31T07:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165313#M12710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Richard,&lt;/P&gt;&lt;P&gt;reading fc records of geometry and attributes into a dictionary for further processing works a treat (at the mo on v10.2).&lt;/P&gt;&lt;P&gt;Used it often recently to do geometry comparisons (intersect etc).&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Neil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 07:04:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165313#M12710</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-09-02T07:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: SHAPE from Cursor doesn't save correctly in List of Dictionaries</title>
      <link>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165314#M12711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Richard,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well I guess it seems to work well now. Here's a somewhat recent example: &lt;A _jive_internal="true" href="https://community.esri.com/message/362783#362783" title="https://community.esri.com/message/362783#362783"&gt;https://community.esri.com/message/362783#362783&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 18:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/shape-from-cursor-doesn-t-save-correctly-in-list/m-p/165314#M12711</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2014-09-02T18:59:02Z</dc:date>
    </item>
  </channel>
</rss>

