<?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: Model Builder - Calculate Field (Area) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246632#M19114</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've attached a zip file (Toolbox.zip) that should contain a 10.2.x toolbox (Toolbox.tbx) with a contained model (ingeniously named 'Model') - this model contains a Calculate Value tool with the corrected snippet...see further notes below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- !shape.area@squarekilometers! is for the field calculator or the Calculate Field tool...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- For use with your tool, Calculate Value, the 'SHAPE@' token was used to return geometry with the da search cursor; area in your desired units was returned via the arcpy 'getArea' method.&amp;nbsp; The code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def getArea(features):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; areaTotal = sum([row[0].getArea('PLANAR', 'SQUAREKILOMETERS') for row in arcpy.da.SearchCursor(features, ['SHAPE@'])])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "%s %s" % (areaTotal, 'Square Kilometers')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- ...and the 'expression' calling the 'getArea' function (notice the proper use of inline variable substitution, where 'myFeatures' is a model parameter [feature layer type] by that name):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
getArea("%myFeatures%")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 12:16:38 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2021-12-11T12:16:38Z</dc:date>
    <item>
      <title>Model Builder - Calculate Field (Area)</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246631#M19113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a totally newbie to Python and have problems to calculate the area of an input feature in my model (model builder). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I use the "Calculate Value" function to calculate the area (in square kilometers or meters) of an input feature (either a raster or a vector feature - should both work?).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found out that it works like that: !shape.area@squarekilometers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have my forumla in the expression block like x/200 and want to calculate the area of myFeature represented by x.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My code block is the following: x = !myFeature.area@squarekilometers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried the following: x = !%myFeature%.area@squarekilometers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I always get an error (ERROR 000989 Python syntax error: Parsing error SyntaxError: invalid syntax (line 1)).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know what I'm doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 19:08:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246631#M19113</guid>
      <dc:creator>MilenaK</dc:creator>
      <dc:date>2014-04-18T19:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder - Calculate Field (Area)</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246632#M19114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've attached a zip file (Toolbox.zip) that should contain a 10.2.x toolbox (Toolbox.tbx) with a contained model (ingeniously named 'Model') - this model contains a Calculate Value tool with the corrected snippet...see further notes below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- !shape.area@squarekilometers! is for the field calculator or the Calculate Field tool...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- For use with your tool, Calculate Value, the 'SHAPE@' token was used to return geometry with the da search cursor; area in your desired units was returned via the arcpy 'getArea' method.&amp;nbsp; The code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def getArea(features):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; areaTotal = sum([row[0].getArea('PLANAR', 'SQUAREKILOMETERS') for row in arcpy.da.SearchCursor(features, ['SHAPE@'])])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "%s %s" % (areaTotal, 'Square Kilometers')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- ...and the 'expression' calling the 'getArea' function (notice the proper use of inline variable substitution, where 'myFeatures' is a model parameter [feature layer type] by that name):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
getArea("%myFeatures%")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:16:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246632#M19114</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T12:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder - Calculate Field (Area)</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246633#M19115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much, I could find it out by myself yesterday, but I just tried your model and it worked immediately &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; !!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Apr 2014 17:13:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246633#M19115</guid>
      <dc:creator>MilenaK</dc:creator>
      <dc:date>2014-04-19T17:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder - Calculate Field (Area)</title>
      <link>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246634#M19116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Very well...one further note about computing geometry measurements--&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE&amp;nbsp; measurement types may be chosen as an alternative, if desired."&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018z00000070000000"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//018z00000070000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used 'PLANAR' because I usually work with relatively small areas in a projected coord sys; 'GEODESIC' is the default measure type...in other words that was an optional parameter I 'forced' to PLANAR that if you left blank may give you a significantly different figure.&amp;nbsp; I suspect it would have to be a large area (smaller areas should yield near equivalent results)...if you want to compare your PLANAR result with the default computation, open the model and remove that param in the code block, save and rerun the model and note the results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Go ahead and mark this thread answered if you're satisfied it's been closed to your satisfaction.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Apr 2014 17:35:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/model-builder-calculate-field-area/m-p/246634#M19116</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-04-19T17:35:16Z</dc:date>
    </item>
  </channel>
</rss>

