<?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: Calculating area of only selected features without writing to table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598420#M46831</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, and in case you were wondering, there is additional help at the link below - if you scroll nearly to the bottom to the section on 'Outputting geometry objects', you'll see an example script summing length after copying to a geometry obj from a shp - I noticed it copies to in-memory:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using geometry objects with geoprocessing tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[Outputting geometry objects]&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was curious if a selection was honored from a layer object fetched from the map and it is - see the attached jpg, I also diddled with the token @acres and I that didn't work for me.&amp;nbsp; But it's a simple matter to divide by the conversion factor and I did it for each geometry...better to do the sum, then the total conversion if working with more than one feature as I was doing.&amp;nbsp; The summary from the table matches the figure computed from geom.&amp;nbsp; Just curious, but wouldn't it be quicker not to copy the geometry but to directly read the geom area via a searchcursor?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If there is no need for anything but area, there is no need to copy geometry to memory - using the data access (da) module and the "SHAPE@AREA" token is way faster.&amp;nbsp; (I recently installed 10.1 so the da module is new to me)...below is the code summary (no timing included but you can easily include that if you wish - it was just obviously faster to me.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; doc = arcpy.mapping.MapDocument('CURRENT')
&amp;gt;&amp;gt;&amp;gt; lyr = arcpy.mapping.ListLayers(doc)[0]
&amp;gt;&amp;gt;&amp;gt; g = arcpy.Geometry()
&amp;gt;&amp;gt;&amp;gt; geometryList = arcpy.CopyFeatures_management(lyr, g)
&amp;gt;&amp;gt;&amp;gt; acres = 0.0

&amp;gt;&amp;gt;&amp;gt; for geometry in geometryList:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acres += (geometry.area)/43560
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;gt;&amp;gt;&amp;gt; print acres
776.613255807

&amp;gt;&amp;gt;&amp;gt; 33829273.422968/43560
776.6132558073461



&amp;gt;&amp;gt;&amp;gt; This below is way faster!

&amp;gt;&amp;gt;&amp;gt; area = 0.0

&amp;gt;&amp;gt;&amp;gt; with arcpy.da.SearchCursor("hab60","SHAPE@AREA") as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; area += row[0]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;gt;&amp;gt;&amp;gt; print area
33829273.423
&amp;gt;&amp;gt;&amp;gt; print area/43560
776.613255807
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:41:59 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2021-12-12T01:41:59Z</dc:date>
    <item>
      <title>Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598416#M46827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good afternoon,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm working on a custom button using the Python GUI and perhaps add-in manager in 10.1 to calculate the area of a selected polygon and then display the result as a popup message box.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've got several of the pieces together, using an IF loop with GetCount() to verify a record has been selected before proceeding and easygui.msgbox to report the result; however I'm struggling to figure out how to calculate the area of the selection without writing to the attribute table. I don't want to have to create a new feature class or table - I want to allow a user to interactively select a polygon, calculate the geometry on the fly, or in memory, convert the number to acres, if necessary, and use that result as the variable to report in my pop-up.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Sep 2013 18:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598416#M46827</guid>
      <dc:creator>SarahFranklin</dc:creator>
      <dc:date>2013-09-30T18:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598417#M46828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should be able to achieve what you want using the polygon geometry class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Polygon/018z00000061000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Polygon/018z00000061000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will probable need to use a data access module search cursor to access the Geometry using the SHAPE@ token&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope it helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Sep 2013 18:10:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598417#M46828</guid>
      <dc:creator>DaveBarrett</dc:creator>
      <dc:date>2013-09-30T18:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598418#M46829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Dave.&amp;nbsp; That looks like it's what I want. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I'm still mentally stuck on populating the polygon object based on a selected feature.&amp;nbsp; Would you do this using the CopyFeatures_management function?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Sep 2013 18:44:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598418#M46829</guid>
      <dc:creator>SarahFranklin</dc:creator>
      <dc:date>2013-09-30T18:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598419#M46830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Copy features should work or you should be able to use the make feature layer tool to create the layer in memory&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Sep 2013 18:48:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598419#M46830</guid>
      <dc:creator>DaveBarrett</dc:creator>
      <dc:date>2013-09-30T18:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598420#M46831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, and in case you were wondering, there is additional help at the link below - if you scroll nearly to the bottom to the section on 'Outputting geometry objects', you'll see an example script summing length after copying to a geometry obj from a shp - I noticed it copies to in-memory:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using geometry objects with geoprocessing tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[Outputting geometry objects]&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was curious if a selection was honored from a layer object fetched from the map and it is - see the attached jpg, I also diddled with the token @acres and I that didn't work for me.&amp;nbsp; But it's a simple matter to divide by the conversion factor and I did it for each geometry...better to do the sum, then the total conversion if working with more than one feature as I was doing.&amp;nbsp; The summary from the table matches the figure computed from geom.&amp;nbsp; Just curious, but wouldn't it be quicker not to copy the geometry but to directly read the geom area via a searchcursor?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If there is no need for anything but area, there is no need to copy geometry to memory - using the data access (da) module and the "SHAPE@AREA" token is way faster.&amp;nbsp; (I recently installed 10.1 so the da module is new to me)...below is the code summary (no timing included but you can easily include that if you wish - it was just obviously faster to me.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; doc = arcpy.mapping.MapDocument('CURRENT')
&amp;gt;&amp;gt;&amp;gt; lyr = arcpy.mapping.ListLayers(doc)[0]
&amp;gt;&amp;gt;&amp;gt; g = arcpy.Geometry()
&amp;gt;&amp;gt;&amp;gt; geometryList = arcpy.CopyFeatures_management(lyr, g)
&amp;gt;&amp;gt;&amp;gt; acres = 0.0

&amp;gt;&amp;gt;&amp;gt; for geometry in geometryList:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acres += (geometry.area)/43560
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;gt;&amp;gt;&amp;gt; print acres
776.613255807

&amp;gt;&amp;gt;&amp;gt; 33829273.422968/43560
776.6132558073461



&amp;gt;&amp;gt;&amp;gt; This below is way faster!

&amp;gt;&amp;gt;&amp;gt; area = 0.0

&amp;gt;&amp;gt;&amp;gt; with arcpy.da.SearchCursor("hab60","SHAPE@AREA") as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; area += row[0]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;gt;&amp;gt;&amp;gt; print area
33829273.423
&amp;gt;&amp;gt;&amp;gt; print area/43560
776.613255807
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:41:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598420#M46831</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-12T01:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating area of only selected features without writing to table</title>
      <link>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598421#M46832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I love this thread. I got the code working by saving a new layer and polygon object to memory but it just "felt" bulky.. I also recently just got upgraded to 10.1 so hadn't heard of the da module before, but I'm excited to try it out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;THANK YOU both!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2013 19:16:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-area-of-only-selected-features-without/m-p/598421#M46832</guid>
      <dc:creator>SarahFranklin</dc:creator>
      <dc:date>2013-10-01T19:16:26Z</dc:date>
    </item>
  </channel>
</rss>

