<?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 pointZ and getZ in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554312#M43329</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Gang,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm chasing myself into corners, trying to add a field to a PointZ shapefile, that contains the hidden Z value associated with the shape.&amp;nbsp; Can't get it to work.&amp;nbsp; I expect a Python snippet like this to work, in field calculator, for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
[Shape].Z
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I get nothing but errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Huh?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Bruce&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Oct 2013 07:32:47 GMT</pubDate>
    <dc:creator>brucesimonson</dc:creator>
    <dc:date>2013-10-15T07:32:47Z</dc:date>
    <item>
      <title>pointZ and getZ</title>
      <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554312#M43329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Gang,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm chasing myself into corners, trying to add a field to a PointZ shapefile, that contains the hidden Z value associated with the shape.&amp;nbsp; Can't get it to work.&amp;nbsp; I expect a Python snippet like this to work, in field calculator, for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
[Shape].Z
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I get nothing but errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Huh?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Bruce&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 07:32:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554312#M43329</guid>
      <dc:creator>brucesimonson</dc:creator>
      <dc:date>2013-10-15T07:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: pointZ and getZ</title>
      <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554313#M43330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Why not use the Calculate Geometry option on the column, then select Z.&lt;/SPAN&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>Tue, 15 Oct 2013 09:49:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554313#M43330</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2013-10-15T09:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: pointZ and getZ</title>
      <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554314#M43331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Brackets only apply to VBA and VB Script fields.&amp;nbsp; With python you use exclamation marks for fields.&amp;nbsp; If you are at ArcGIS 10.0 or above, VBA is no longer supported by the Field Calculator and VB Script, which replaced it, cannot do geometry calculations.&amp;nbsp; You have to use Python.&amp;nbsp; Also you have to specify that you want the Centroid for a point feature class.&amp;nbsp; So check the Python option and use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!Shape.Centroid.Z!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 10:20:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554314#M43331</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-10-15T10:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: pointZ and getZ</title>
      <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554315#M43332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Brackets only apply to VBA and VB Script fields.&amp;nbsp; With python you use exclamation marks for fields.&amp;nbsp; If you are at ArcGIS 10.0 or above, VBA is no longer supported by the Field Calculator and VB Script, which replaced it, cannot do geometry calculations.&amp;nbsp; You have to use Python.&amp;nbsp; Also you have to specify that you want the Centroid for a point feature class.&amp;nbsp; So check the Python option and use:&lt;BR /&gt;&lt;BR /&gt;!Shape.Centroid.Z!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Both of the above suggestions work great, when run from the attribute table.&amp;nbsp; I'd like to extend this, though, to creating a python program which reads all of the shapefiles in a workspace, adds a field for z, and updates with the appropriate value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, in a set of shapefiles that have PointZ values in meters, I'd like to add a field which captures the Z value in feet (from the source shapefiles, which are in meters).&amp;nbsp; Not sure why I can't get this to work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env

env.workspace = "P:/path/to/some/directory"

fcList = arcpy.ListFeatureClasses( )

for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management( fc, "Z_feet", "DOUBLE", "10", "3" )
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc, "Z_feet", "3.28083 * float(!SHAPE.CENTROID.Z!)", "PYTHON")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In particular, !SHAPE.CENTROID.Z! seems to work in the field calculator (Python mode), but not in a Python program.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:57:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554315#M43332</guid>
      <dc:creator>brucesimonson</dc:creator>
      <dc:date>2021-12-11T23:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: pointZ and getZ</title>
      <link>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554316#M43333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Both of the above suggestions work great, when run from the attribute table.&amp;nbsp; I'd like to extend this, though, to creating a python program which reads all of the shapefiles in a workspace, adds a field for z, and updates with the appropriate value.&lt;BR /&gt;&lt;BR /&gt;For example, in a set of shapefiles that have PointZ values in meters, I'd like to add a field which captures the Z value in feet (from the source shapefiles, which are in meters).&amp;nbsp; Not sure why I can't get this to work:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env

env.workspace = "P:/path/to/some/directory"

fcList = arcpy.ListFeatureClasses( )

for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management( fc, "Z_feet", "DOUBLE", "10", "3" )
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc, "Z_feet", "3.28083 * float(!SHAPE.CENTROID.Z!)", "PYTHON")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;In particular, !SHAPE.CENTROID.Z! seems to work in the field calculator (Python mode), but not in a Python program.&lt;BR /&gt;&lt;BR /&gt;Suggestions?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Change "PYTHON" in your calculation to "PYTHON_9.3".&amp;nbsp; "PYTHON" is pre-9.3 and does not use the current syntax of the field calculator.&amp;nbsp; A new Python keyword was created so that "PYTHON" would remain unchanged for pre-9.3 scripts to maintain backward compatibility.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Additionally you don't need to cast to float and you don't need to do the multiplication to convert to Feet.&amp;nbsp; Change the calculation to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!SHAPE.CENTROID.Z@FEET!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:57:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pointz-and-getz/m-p/554316#M43333</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T23:57:31Z</dc:date>
    </item>
  </channel>
</rss>

