<?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: Common Python geometry calculations in the Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630014#M49019</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;EasyCalculate is a free set of 100+ field calculator scripts, definitely check them out: &lt;A href="http://www.ian-ko.com/free/free_arcgis.htm"&gt;http://www.ian-ko.com/free/free_arcgis.htm&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wow this looks stupendiforously useful, however I note it only mentions up to Arc 9.x in the documentation, not Arc 10. Will there be compatibility issues?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Feb 2011 04:27:44 GMT</pubDate>
    <dc:creator>wilfredwaters</dc:creator>
    <dc:date>2011-02-28T04:27:44Z</dc:date>
    <item>
      <title>Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630010#M49015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Making_field_calculations"&gt;Here&lt;/A&gt;&lt;SPAN&gt; it has Common VBA geometry calculations in the Field Calculator, provide as a number of code blocks. I have pasted these below and am wondering if someone can make a set of equivalent code blocks in Python, or can point me where someone has already made them?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Common VBA geometry calculations in the Field Calculator &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Below are some code samples you can use to perform geometric calculations with VBA statements, rather than having the Calculate Geometry command do them for you. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To use the samples, open the Field Calculator, check Advanced, and type the VBA statement in the first text box. Then, type the variable name in the text box directly under the field name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Area &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblArea as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea as IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pArea = [shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblArea = pArea.area&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perimeter &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblPerimeter as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pCurve as ICurve&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pCurve = [shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblPerimeter = pCurve.Length&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Length &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblLength as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pCurve as ICurve&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pCurve = [shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblLength = pCurve.Length&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;X-coordinate of a point &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblX As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pPoint As IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pPoint = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblX = pPoint.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Y-coordinate of a point &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblY As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pPoint As IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pPoint = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblY = pPoint.Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;X-coordinate of a polygon centroid &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblX As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea As IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pArea = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblX = pArea.Centroid.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Y-coordinate of a polygon centroid &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblY As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea As IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pArea = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblY = pArea.Centroid.Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To add the z-value of the start point of a polyline &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblZ As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pLine As IPolyline&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pPoint as IPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pLine = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pPoint = pLine.FromPoint&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblZ= pPoint.Z&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 20:59:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630010#M49015</guid>
      <dc:creator>wilfredwaters</dc:creator>
      <dc:date>2011-02-17T20:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630011#M49016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;area:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.area@hectares!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(or whatever other unit is required)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 21:16:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630011#M49016</guid>
      <dc:creator>wilfredwaters</dc:creator>
      <dc:date>2011-02-17T21:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630012#M49017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;did you rule out those contained in the help files?&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/005s0000002m000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/005s0000002m000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Feb 2011 21:36:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630012#M49017</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-02-17T21:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630013#M49018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;EasyCalculate is a free set of 100+ field calculator scripts, definitely check them out: &lt;/SPAN&gt;&lt;A href="http://www.ian-ko.com/free/free_arcgis.htm"&gt;http://www.ian-ko.com/free/free_arcgis.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 21:21:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630013#M49018</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2011-02-18T21:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630014#M49019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;EasyCalculate is a free set of 100+ field calculator scripts, definitely check them out: &lt;A href="http://www.ian-ko.com/free/free_arcgis.htm"&gt;http://www.ian-ko.com/free/free_arcgis.htm&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wow this looks stupendiforously useful, however I note it only mentions up to Arc 9.x in the documentation, not Arc 10. Will there be compatibility issues?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wil&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 04:27:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630014#M49019</guid>
      <dc:creator>wilfredwaters</dc:creator>
      <dc:date>2011-02-28T04:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630015#M49020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ianko responded to my email with this link for arc 10:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.ian-ko.com/free/EC10/EC10_main.htm"&gt;http://www.ian-ko.com/free/EC10/EC10_main.htm&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 04:53:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630015#M49020</guid>
      <dc:creator>wilfredwaters</dc:creator>
      <dc:date>2011-02-28T04:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630016#M49021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ArcGIS 10 supports all of the common field calculator geometry expressions in Python as simple expressions (no advanced calculations necessary, unlike VBA).&amp;nbsp; Here they are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Area &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.area!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perimeter &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.length! (for polygons length returns the perimeter length)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Length &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.length! (for polylines length returns the line length)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;X-coordinate of a point &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.firstpoint.X!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Y-coordinate of a point &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.firstpoint.Y!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;X-coordinate of a polygon centroid &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.centroid.X! (works for polyline too, but is not necessarily the midpoint, see midpoint/truecentroid below)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Y-coordinate of a polygon centroid &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.centroid.Y! (works for polyline too, but is not necessarily the midpoint, see midpoint/truecentroid below)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To add the z-value of the start point of a polyline &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.firstpoint.Z!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To add the z-value of the end point of a polyline &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.lastpoint.Z!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To add the z-value of the mid point of a polyline&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.truecentroid.Z!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All of the above calculations can get the X, Y, Z and M values of a geometry (if Z and M are enabled) by substituting the appropriate letter at the end of any of the expressions that return a coordinate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the expression pattern below units can be converted in one expression to any of the following units for area:&amp;nbsp; ACRES | ARES | HECTARES | SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | SQUAREFEET | SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES | SQUAREMILLIMETERS | SQUAREYARDS | SQUAREMAPUNITS | UNKNOWN (do not use with geographic coordinate systems that use angular units as the results will be questionable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.area@squarekilometers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the expression pattern below units can be converted in one expression to any of the following units for length:&amp;nbsp; CENTIMETERS | DECIMALDEGREES | DECIMETERS | FEET | INCHES | KILOMETERS | METERS | MILES | MILLIMETERS | NAUTICALMILES | POINTS | UNKNOWN | YARDS (geodesic conversions occur for geographic coordinate systems that use angular units)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;!shape.length@kilometers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001s000000"&gt;Working with geometry in Python &lt;/A&gt;&lt;SPAN&gt;help for calculating other geometry properties, such as extent, hullRectangle, isMultipart, partCount, pointCount, labelPoint, and type.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Feb 2012 15:35:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630016#M49021</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2012-02-04T15:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630017#M49022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you rfairhur24.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is getting me in the right direction , however I'm still stumped as to how I can calculate the lat/long of a point.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:courier new;"&gt;!shape.length@DECIMALDEGREES!&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; returns zero. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family:courier new;"&gt;!shape.firstpoint.X!&lt;/SPAN&gt;&lt;SPAN&gt; returns the location in my State plane coordinates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family:courier new;"&gt;!shape.firstpoint.X@DECIMALDEGREES!&lt;/SPAN&gt;&lt;SPAN&gt; doesn't work .&amp;nbsp; (just taking a stab at things)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any one know how to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A couple clicks in the desktop software does it easily, but I need to incorporate this functionality into a python script that will do this each night with new points.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ann&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2012 15:19:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630017#M49022</guid>
      <dc:creator>AnnStark</dc:creator>
      <dc:date>2012-02-23T15:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630018#M49023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm having the same problem Ann (except I think mine is worse.&amp;nbsp; I've lost access to field calculator and geometry calculator.).&amp;nbsp; The only thing I've found as a possible answer is that you have to reproject your stateplane layer to a geographic coordinate system like wgs84 and then add the x/y table values for lat/long.&amp;nbsp; Depending on how you want to use the data (I want lat/longs but within a stateplane projected layer), you will have to extract the field data and write it back into your stateplane layer record by record, or reproject the geographic layer back to stateplane.&amp;nbsp; It's a pain in the rear for sure.&amp;nbsp; I can't believe it's this hard to do something so basic.&amp;nbsp; And I hope nobody responds with "just use the x/y data tool",&amp;nbsp; or "use the geometry calculator", because neither of them work properly, nor do they throw errors or give any clue as to why they don't work properly.&amp;nbsp; I hope my 2 cents might help.&amp;nbsp; I'll keep checking back to see if a more viable solution arrives that I can use also.....I'd hate to have to write my own tool, when ESRI has one they need to fix.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Apr 2012 18:44:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630018#M49023</guid>
      <dc:creator>BryanTaylor</dc:creator>
      <dc:date>2012-04-26T18:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630019#M49024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The only way I have found to avoid using the Project tool to do a conversion from a spatial projection that uses linear units (like State Plane coordinates) to angular units (like Decimal Degrees) is using the Geoprocessing Environment settings to set up any transformation option and the spatial reference parameter of a Python UpdateCursor.&amp;nbsp; If you have ArcGIS Desktop 10.1 or later you should only use a Data Access UpdateCursor (da UpdateCursor), not the original Python UpdateCursor syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A note of warning, if you use this approach with an XY Event layer that has its original coordinates in linear units, like State Plane coordinates, you need to first duplicate those coordinates into a pair of new fields that you want to hold your Latitude (Y coordinate) and Longitude (X coordinate) and use those new fields with the XY Event Layer tool, because if you include the SHAPE@X or SHAPE@Y feilds in the UpdateCursor field list and use the updateRow method, the fields used to set the coordinates of the XY Event Layer will convert and be overwritten with new coordinate values that match the new spatial reference and transformation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13px; line-height: 1.5;"&gt;The script below can create a new Latitude and Longitude field in an XY Event Layer table that has only State Plane coordinates, make a copy of the original state plane coordinates into the new &lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333339691162px;"&gt;Latitude and Longitude &lt;/SPAN&gt;&lt;SPAN style="font-size: 13px; line-height: 1.5;"&gt;fields, and use an XY Event layer and a da UpdateCursor opened with a different spatial reference to convert the values in the Latitude and Longitude fields into the coordinates matching the new spatial reference.&amp;nbsp; It can run the entire script to process over 131K records in an &lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333339691162px;"&gt;XY Event Layer &lt;/SPAN&gt;&lt;SPAN style="font-size: 13px; line-height: 1.5;"&gt;in approximately 36 seconds, which is about 5 to 10 times faster than methods that used to use the Field Calculator.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14154827232944116" jivemacro_uid="_14154827232944116"&gt;
&lt;P&gt;# Import arcpy module&lt;/P&gt;
&lt;P&gt;from time import strftime &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Set or comment out Geographic Transformation&lt;/P&gt;
&lt;P&gt;arcpy.env.geographicTransformations = "NAD_1983_To_WGS_1984_5"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Use a table with State Plane NAD 83 coordinates&lt;/P&gt;
&lt;P&gt;fc = r"C:\Users\RFAIRHUR\Documents\ArcGIS\DEFAULT.gdb\CL_INTERSECTIONS_PAIRS"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished Setup: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Add Latitude Field&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(fc, "LATITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Add Longitude Field&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(fc, "LONGITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finish Adding Fields: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Specify original X and Y fields and corresponding Longitude and Latitude output fields.&lt;/P&gt;
&lt;P&gt;fields = ( 'LONGITUDE', 'X_COORD', 'LATITUDE', 'Y_COORD')&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#Open a da UpdateCursor and duplicate the X and Y coordinates in the Longitude and Latitude fields.&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fc, fields) as updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for updateRow in updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow[0] = updateRow[1]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow[2] = updateRow[3]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished UpdateCursor Longitude and Latitude edits " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Set a name for your XY Event Layer&lt;/P&gt;
&lt;P&gt;CL_INTERSECTIONS_PAIRS_Events = "CL_INTERSECTIONS_PAIRS Events"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Make an X/Y Event Layer with NAD 83 projection.&lt;/P&gt;
&lt;P&gt;arcpy.MakeXYEventLayer_management(fc, "LONGITUDE", "LATITUDE", CL_INTERSECTIONS_PAIRS_Events, "PROJCS['NAD_1983_StatePlane_California_VI_FIPS_0406_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-116.25],PARAMETER['Standard_Parallel_1',32.78333333333333],PARAMETER['Standard_Parallel_2',33.88333333333333],PARAMETER['Latitude_Of_Origin',32.16666666666666],UNIT['Foot_US',0.3048006096012192]];-118608900 -91259500 3048.00609601219;-100000 10000;-100000 10000;3.28083333333333E-03;0.001;0.001;IsHighPrecision", "")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished Making XY Event Layer: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Use the Event layer as the cursor input&lt;/P&gt;
&lt;P&gt;fcl = CL_INTERSECTIONS_PAIRS_Events&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Specify shape coordinate fields.&lt;/P&gt;
&lt;P&gt;fields = ("SHAPE@X", "SHAPE@Y")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Specify the Spatial Reference of the Cursor&lt;/P&gt;
&lt;P&gt;latLonRef = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Create update cursor for feature class with a new Spatial Reference.&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fcl, fields, ' ', latLonRef) as updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for updateRow in updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Lat and Long convert just by using the updateRow method on the Shape fields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished Converting Longitude and Latitude fields: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# The coordinates in the Longitude and Latitude fields are now converted to Decimal Degrees.&lt;/P&gt;
&lt;P&gt;print "Finish script: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;








&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is a script that adds a Latitude and Longitude field to a State Plane NAD 83 Point Feature Class and using an UpdateCursor with a different spatial reference is able to fill those fields in with the Decimal Degree coordinates of a WGS 1984 spatial reference.&amp;nbsp; The underly geometry of the points is unaffected by the script.&amp;nbsp; The entire script takes approximately 25 seconds to run on over 131K points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14154916587613273 jive_text_macro" jivemacro_uid="_14154916587613273"&gt;
&lt;P&gt;from time import strftime&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Set or comment out Geographic Transformation&lt;/P&gt;
&lt;P&gt;arcpy.env.geographicTransformations = "NAD_1983_To_WGS_1984_5"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Use a table with State Plane NAD 83 coordinates&lt;/P&gt;
&lt;P&gt;fc = r"C:\Users\RFAIRHUR\Documents\ArcGIS\DEFAULT.gdb\CL_INT_PAIRS_POINTS"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished Setup: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Add Latitude Field&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(fc, "LATITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Add Longitude Field&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(fc, "LONGITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finish Adding Fields: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Specify shape coordinate fields.&lt;/P&gt;
&lt;P&gt;fields = ("LONGITUDE", "SHAPE@X", "LATITUDE", "SHAPE@Y")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Specify the Spatial Reference of the Cursor&lt;/P&gt;
&lt;P&gt;latLonRef = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Create update cursor for feature class with a new Spatial Reference.&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fc, fields, ' ', latLonRef) as updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for updateRow in updateRows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow[0] = updateRow[1]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow[2] = updateRow[3]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Finished Converting Longitude and Latitude fields: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# The coordinates in the Longitude and Latitude fields are now converted to Decimal Degrees.&lt;/P&gt;
&lt;P&gt;print "Finish script: " + strftime("%Y-%m-%d %H:%M:%S")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Nov 2014 21:49:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630019#M49024</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-11-08T21:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630020#M49025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe I am misunderstanding the problem here.&lt;/P&gt;&lt;P&gt;But if you want to add a couple of columns containing XY's for a different coord sys than the data itself just add the columns (double of course), change the coordinate system of the data frame to your desired output. Then right click on the column, pick the XY value, and choose "use cords sys of the data frame".&lt;/P&gt;&lt;P&gt;Easy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 06:29:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630020#M49025</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-11-10T06:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Common Python geometry calculations in the Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630021#M49026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am finding that cursors and dictionaries are now reducing my time doing field calculations by factors of nearly 16 times the speed.&amp;nbsp; As a result, I now have determined that my time will be better spent abandoning all Field and Geometry Calculator operations to write my own set of tools to replace them with an interface that configures cursors and dictionaries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My latest script rewrite replaced 11 field calculations and one summary statistics operation with cursors and dictionary operations on 800K records and reduced the script time from 63 minutes to 4 minutes.&amp;nbsp; As a result, I simply can no longer justify the amount of my time the Field Calculator and Geometry Calculator will waste if I continue using them on any large record sets, no matter how easy they are to set up.&amp;nbsp; Now that I can design high performing tools of my own I soon will no longer ever have to fall asleep again at my computer while I tie up my ArcGIS Desktop waiting on calculations to complete.&amp;nbsp; I can't wait.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Nov 2014 09:13:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/common-python-geometry-calculations-in-the-field/m-p/630021#M49026</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-11-10T09:13:56Z</dc:date>
    </item>
  </channel>
</rss>

