<?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: Geometry object stuff in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51565#M4092</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Neil,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like you are trying to iterate through the shape field, which won't be possible, unless you are working with a multipoint feature class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for pnt in row[1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("{0}, {1}".format(pnt.X, pnt.Y))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, you can return the XY coordinates a couple ways:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}:".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1].centroid.X, row[1].centroid.Y&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@XY"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}:".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:59:21 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-10T21:59:21Z</dc:date>
    <item>
      <title>Geometry object stuff</title>
      <link>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51564#M4091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have used this stuff before but this afternoon (because of my fading brain) I got stuck again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This page says that using point geometry objects, you can access the X,Y,Z like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//002z0000001t000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//002z0000001t000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print the current multipoint's ID
&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}:".format(row[0]))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # For each point in the multipoint feature,
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp; print the x,y coordinates
&amp;nbsp;&amp;nbsp;&amp;nbsp; for pnt in row[1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("{0}, {1}".format(pnt.X, pnt.Y))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you do this, all you get is this :&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; geom1
&amp;lt;PointGeometry object at 0x128e50d0[0x128e51c0]&amp;gt;
&amp;gt;&amp;gt;&amp;gt; geom1.type
u'point'
&amp;gt;&amp;gt;&amp;gt; geom1.X

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;pyshell#2&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; geom1.X
AttributeError: 'PointGeometry' object has no attribute 'X'
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This had me stuck for about an hour until, from somewhere in my aging cortex, I remembered you had to do this :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; geom1.type
u'point'
&amp;gt;&amp;gt;&amp;gt; geom1.getPart().X
37.85577369550394
&amp;gt;&amp;gt;&amp;gt; geom1.getPart().Y
-5.721226269422574
&amp;gt;&amp;gt;&amp;gt; geom1.getPart().Z
633.8880000000063
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh, and if you try to iterate over a geometry object like in the help, that fails as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; for p in geom1:
 print p.getPart().X

 

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;pyshell#10&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for p in geom1:
TypeError: 'PointGeometry' object is not iterable
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dear esri, when is either the attributes of the geometry going to get fixed, or the help files when you want to actually do this stuff?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:59:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51564#M4091</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-10T21:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Geometry object stuff</title>
      <link>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51565#M4092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Neil,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like you are trying to iterate through the shape field, which won't be possible, unless you are working with a multipoint feature class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for pnt in row[1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("{0}, {1}".format(pnt.X, pnt.Y))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, you can return the XY coordinates a couple ways:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}:".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1].centroid.X, row[1].centroid.Y&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@XY"]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}:".format(row[0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:59:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51565#M4092</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T21:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Geometry object stuff</title>
      <link>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51566#M4093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jake,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I realize that .centroid would also work. But I still think that the help could be a little less misleading.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Got my script to work by using .getPart()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Neil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Feb 2014 07:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51566#M4093</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-02-14T07:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Geometry object stuff</title>
      <link>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51567#M4094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Adding my 2 cents here, since i went looking for this today:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The PointGeometry class should have either .X .Y .Z properties or a .Point property.&amp;nbsp; It doesn't make sense to use .getPart() or .centroid() or .firstPoint().&amp;nbsp; Isn't the point (no pun intended) of python to be "easy to read/write"? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I added a item to the ideas system: &lt;/SPAN&gt;&lt;A href="http://shar.es/RHjsR"&gt;http://shar.es/RHjsR&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2014 18:54:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geometry-object-stuff/m-p/51567#M4094</guid>
      <dc:creator>FredSpataro</dc:creator>
      <dc:date>2014-03-06T18:54:25Z</dc:date>
    </item>
  </channel>
</rss>

