<?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 Better way to Calculate Geometry? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/better-way-to-calculate-geometry/m-p/153061#M11837</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a point feature class that has 2 double fields (field names are EASTING and NORTHING) that I use calculate geometry to get the x.y coordinates of the points from the coordinate system of the feature class using the tool in the attribute table. The tool isn't offered in the toolbox, so I developed a quick script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need the coordinate values in the 2 fields for a period of time and then I have a client who wants these coordinate values changed to a different coordinate system, but they want the feature classes coordinate system to remain unchanged. I've come up with a process in python that will do this for me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Re-project feature class to new coordinate system (gives new output)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Add X,Y coordinates to the new FC using arcpy.AddXY_management &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Join these 2 tables based on a unique identifier field &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Field Calculate the EASTING and NORTHING fields based on the new X,Y coordinate fields in the re-projected FC&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Delete the interim stuff, remove join, yadda, yadda&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works fine and I have no issue with it, but I've been reading through some field calculator VB scripts and I'm wondering of there's a way you can just calculate the EASTING and NORTHING fields in a code block based on a different coordinate system, without going though all the re-projecting and joining stuff. I have quite a few point files to process, so I thought a simpler method might be out there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Feb 2012 04:14:28 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2012-02-08T04:14:28Z</dc:date>
    <item>
      <title>Better way to Calculate Geometry?</title>
      <link>https://community.esri.com/t5/python-questions/better-way-to-calculate-geometry/m-p/153061#M11837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a point feature class that has 2 double fields (field names are EASTING and NORTHING) that I use calculate geometry to get the x.y coordinates of the points from the coordinate system of the feature class using the tool in the attribute table. The tool isn't offered in the toolbox, so I developed a quick script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need the coordinate values in the 2 fields for a period of time and then I have a client who wants these coordinate values changed to a different coordinate system, but they want the feature classes coordinate system to remain unchanged. I've come up with a process in python that will do this for me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Re-project feature class to new coordinate system (gives new output)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Add X,Y coordinates to the new FC using arcpy.AddXY_management &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Join these 2 tables based on a unique identifier field &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Field Calculate the EASTING and NORTHING fields based on the new X,Y coordinate fields in the re-projected FC&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Delete the interim stuff, remove join, yadda, yadda&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works fine and I have no issue with it, but I've been reading through some field calculator VB scripts and I'm wondering of there's a way you can just calculate the EASTING and NORTHING fields in a code block based on a different coordinate system, without going though all the re-projecting and joining stuff. I have quite a few point files to process, so I thought a simpler method might be out there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Feb 2012 04:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/better-way-to-calculate-geometry/m-p/153061#M11837</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-02-08T04:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Better way to Calculate Geometry?</title>
      <link>https://community.esri.com/t5/python-questions/better-way-to-calculate-geometry/m-p/153062#M11838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can set a Spatial reference on the cursor options.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then when you get the x,y coordinates they will already be reprojected ready to add back into the fields.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't have to reproject the featureclass first.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example I needed the extent of each polygon in a different projection:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp; # 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # WGS_1984 works for coverages defined with an equivalent custom Transverse projection definition
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.GeographicTransformations = 'NZGD_1949_To_WGS_1984_3_NTv2' 
&amp;nbsp;&amp;nbsp; srOut = gp.CreateObject("SpatialReference")
&amp;nbsp;&amp;nbsp; srOut.CreateFromFile("c:/arcgis/nzmg.prj")
&amp;nbsp;&amp;nbsp; # this is a good on-the-fly switch for the searchcursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; # srOut must be a com object, not a file ref or a factory code
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = gp.SearchCursor(ds+"/polygon",'"PAR_ID" &amp;gt; 0',srOut) 
&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.Reset()
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row&amp;nbsp; :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; f1,"%d,%s" % (row.par_id,row.shape.Extent.replace(" ",","))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n +=1
&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:12:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/better-way-to-calculate-geometry/m-p/153062#M11838</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T08:12:01Z</dc:date>
    </item>
  </channel>
</rss>

