<?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: Problem in calculation Area and Perimeter using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350529#M27486</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually i didn't mean to write code for me, i provided my code above, i just want to make it correct, where i am doing wrong nothing else...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Dec 2014 05:49:31 GMT</pubDate>
    <dc:creator>AhsanAbbas</dc:creator>
    <dc:date>2014-12-15T05:49:31Z</dc:date>
    <item>
      <title>Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350522#M27479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt; font-family: 'times new roman', times;"&gt;&lt;STRONG&gt;I need a script that determines the perimeter (in meters) and area (in square meters) of each of the individual islands of the Hawaii.shp feature class. This shapefile is multipart feature class.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;My code illustrate below, but it doesn't give me correct answer ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;fc = r"D:\Python Exercise\Exercise08-2014-12-05\Exercise08\Hawaii.shp"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;cursor = arcpy.da.SearchCursor(fc, ["OID@","SHAPE@","SHAPE@AREA","SHAPE@LENGTH"])&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;units = arcpy.Describe(fc).spatialReference.linearUnitName&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;for row in cursor:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Total Area: ", row[2]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Feature {0}: ".format(row[0]))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum = 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; perimeter = 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for part in row[1]:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Part {0}: ".format(partnum))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for point in part:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perimeter += row[3]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum += 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print "Area: ", row[2]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Perimeter: ", perimeter, units&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 18:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350522#M27479</guid>
      <dc:creator>AhsanAbbas</dc:creator>
      <dc:date>2014-12-14T18:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350523#M27480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You seem to be missing the getPart, getLength and getArea methods in &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Polygon/018z00000061000000/"&gt;Polygon class for arcpy&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 18:57:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350523#M27480</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-12-14T18:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350524#M27481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You appear to be cumulatively adding the total shape length of the entire polygon to the perimeter variable for each point along the perimeter that you encounter.&amp;nbsp; The length between points would require a euclidean distance calculation between all point pairs that make up the part being added as you traverse the part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Shape.Length field (row[3]) should already be the perimeter of the polygon if this shapefile was converted from a geodatabase feature class or calculated using the geometry calculator.&amp;nbsp; Did you mean to update the Shape.Length field after determining the perimeter?&amp;nbsp; If so you need to use an UpdateCursor, not a SearchCursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe something more like this untested code should work if you wanted to get the euclidean distances from a shapefile that is using a Spatial Reference with linear units (however, Dan's option of using getLength from the geometry may be all you need to do):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in cursor:
&amp;nbsp; # Create the geometry object
&amp;nbsp; #
&amp;nbsp; feat = row[1]

&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp; partnum = 0&lt;/SPAN&gt;
&amp;nbsp; perimeter = 0
&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&amp;nbsp; # Step through each part of the feature&lt;/SPAN&gt;
&amp;nbsp; #
&amp;nbsp; for part in feat:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print the part number
&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Part %i:" % partnum

&amp;nbsp;&amp;nbsp;&amp;nbsp; lastpnt = None

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step through each vertex in the feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp; for pnt in feat.getPart(partnum):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pnt:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Print x,y coordinates of current point
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print pnt.X, pnt.Y
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lastpnt == None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastpnt = pnt
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perimeter += math.sqrt((pnt.X - lastpnt.X) ** 2 + (pnt.Y - lastpnt.Y) ** 2)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If pnt is None, this represents an interior ring
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Interior Ring:"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastpnt = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum += 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350524#M27481</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T16:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350525#M27482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay how to calculate area for each polygon ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 19:26:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350525#M27482</guid>
      <dc:creator>AhsanAbbas</dc:creator>
      <dc:date>2014-12-14T19:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350526#M27483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well I misread your earlier post.&amp;nbsp; !Shape@Area! and !Shape@Length! are the area and perimeter values of the feature in its native units.&amp;nbsp; So is this just a simple unit conversion problem?&amp;nbsp; If so, once you know the native units of the feature you can get the &lt;A href="http://en.wikipedia.org/wiki/Conversion_of_units"&gt;conversion factors from here&lt;/A&gt; and apply them to the row[2] and row[3] values to get square meters and meters.&amp;nbsp; Or you could provide a Spatial Reference that used meters as &lt;SPAN style="font-size: 14.4444446563721px;"&gt;the cursor's&lt;/SPAN&gt; fourth parameter and then the !Shape@Area! and !Shape@Length! would return values in square meters and meters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are trying to independently calculate area and confirm the values against those of the area and length returned by the shape method, than the euclidean distance method I gave will be one method for doing that for the perimeter length, provided the distances are not covering a large portion of the globe's surface.&amp;nbsp; For area calculations I don't know an independent formula that will work for all possible polygon shapes (which in part accounts for why we buy Esri's product to take advantage of people who have figured that out).&amp;nbsp; Using the !Shape@Area! values, or the getArea values from a geometry would be the approaches I would take.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 19:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350526#M27483</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-12-14T19:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350527#M27484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given the number and nature of your questions today, not to mention the references to "exercise" in path names, it seems you are relying pretty heavily on GeoNet users to figure your class exercises out for you.&amp;nbsp; I don't mind helping a new GIS user get started with arcpy and Python, but I don't get the sense the Help documentation has been thoroughly read before asking for others to provide code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, and if I understand your question correctly, I believe the following will get close to what you are after:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = #path for feature class
SR = arcpy.Describe(fc).spatialReference
units = SR.linearUnitName

cursor = arcpy.da.SearchCursor(fc, ["OID@","SHAPE@"])
for OID, shape in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Feature: {}\tTotal Area: {} {}^2".format(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OID, shape.area, units
&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for part in shape:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pn = arcpy.Polygon(part, SR)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tPart: {}\t Area: {} {}^2\tPerimeter: {} {}".format(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum, pn.area, units, pn.length, units
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partnum += 1&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A few comments to move beyond simply giving you a proverbial fish:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If you are going to retrieve the shape as a geometry object, there isn't much point in using the other shape tokens.&amp;nbsp; Since retrieving a shape as a geometry object carries the most overhead, the other tokens were created to speed up the search cursor when one didn't need the full shape but only its area, length, etc....&lt;/LI&gt;&lt;LI&gt;The code above, since it relies on the area properties instead of the getArea method of the polygon object, assumes you are interested in planar values and using a feature class that is already projected.&amp;nbsp; If you are interested in other measurement types or are using unprojected data, then you will want to look at the getArea method.&lt;/LI&gt;&lt;LI&gt;When retrieving the parts of a polygon, what is returned aren't polygons but arrays of points that need to be reconstructed back into polygons if you are interested in measuring areas and perimeters.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I strongly encourage you to read the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018z00000061000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Polygon (arcpy)&lt;/A&gt; help, I think it will help clarify your misunderstanding of how to work with arcpy geometry objects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:28:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350527#M27484</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T16:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350528#M27485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another tool to consider is &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000003r000000"&gt;Multipart To Singlepart (Data Management).&lt;/A&gt;‌&amp;nbsp; If you took this approach, then you could use the SHAPE@AREA and SHAPE@LENGTH tokens and not get involved directly with manipulating arcpy geometry objects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 21:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350528#M27485</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2014-12-14T21:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in calculation Area and Perimeter using Python</title>
      <link>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350529#M27486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually i didn't mean to write code for me, i provided my code above, i just want to make it correct, where i am doing wrong nothing else...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 05:49:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-in-calculation-area-and-perimeter-using/m-p/350529#M27486</guid>
      <dc:creator>AhsanAbbas</dc:creator>
      <dc:date>2014-12-15T05:49:31Z</dc:date>
    </item>
  </channel>
</rss>

