<?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: Distance between Points in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668797#M51901</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At the moment this process is comparing apples and oranges and it will give incorrect results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This said, the process needed is to build in a reproject function to take the coordinates from Geographic Coordinates (decimal degrees) into Map units (meters).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Todo Get distance between 2 point&lt;/P&gt;&lt;P&gt;Step 1: Build up representation of 1st point in memory as PointGeometry Object&lt;/P&gt;&lt;P&gt;Step 2; Reproject point in map units&lt;/P&gt;&lt;P&gt;Step 3: Build up representation of 2nd point in memory as PointGeometryObject&lt;/P&gt;&lt;P&gt;Step 4: Reproject this into Map Units&lt;/P&gt;&lt;P&gt;Step 5: Compare the 2 points using Pythagoras Formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached is a function to perform the Reproject using the arcpy module&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#projectSR&lt;/P&gt;&lt;P&gt;def projectSR (pt, sr): #sr = spatial reference, pt is geometry in memory&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #constantts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gcs = arcpy.SpatialReference(2193)&amp;nbsp; #2193 = factory code for NZ Transverse Mercator &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gt = 'NZGD_2000_To_WGS_1984_1' #geographic transformation, if application&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptgeom = arcpy.PointGeometry(pt, nztm).projectAs(gcs, gt)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords.insert(0,(ptgeom.centroid.X))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords.insert(1,(ptgeom.centroid.Y))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del ptgeom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return coords&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call projectSR to get the coordinates in map units meters and then you'll be able to use the Pythagoras theorem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Susan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Oct 2014 20:59:56 GMT</pubDate>
    <dc:creator>SusanJones</dc:creator>
    <dc:date>2014-10-09T20:59:56Z</dc:date>
    <item>
      <title>Distance between Points</title>
      <link>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668796#M51900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here the thing-&lt;/P&gt;&lt;P&gt;in the same layer, I have POINT_X, POINT_Y and POINT_X_1, POINT_Y_1, as decimal degrees.&lt;/P&gt;&lt;P&gt;I´m trying to find the linear distance in meters from the 2 points.&lt;/P&gt;&lt;P&gt;I´m trying to get it with pyhton, using the below code, but I get always the same syntax error &lt;/P&gt;&lt;H1&gt;000989 : Python syntax error: &amp;lt;value&amp;gt;&lt;/H1&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Joao&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;pre-logic code&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ef Haversine(Lat0, Lat1, Lon0, Lon1):&lt;/P&gt;&lt;P&gt;[INDENT]dlat = Lat0 - Lat1&lt;/P&gt;&lt;P&gt;dlon = Lon0 - Lon1&lt;/P&gt;&lt;P&gt;a = (math.sin(math.radians(dlat)/2 )*math.sin(math.radians(dlat)/2 )) + math.cos(math.radians(Lat1) )*math.cos(math.radians( Lat0 ) )*(math.sin(math.radians(dlon)/2 )*math.sin(math.radians(dlon)/2 ))&lt;/P&gt;&lt;P&gt;c = 2*math.atan2( math.sqrt(a ),math.sqrt(1-a ))&lt;/P&gt;&lt;P&gt;H = c * 6371&lt;/P&gt;&lt;P&gt;return H&lt;/P&gt;&lt;P&gt;[/INDENT] &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;Code:&lt;/P&gt;&lt;P&gt;Haversine( !POINT_Y! , !POINT_Y_1! , !POINT_X! , !POINT_X_1! )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 20:40:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668796#M51900</guid>
      <dc:creator>JoaoOliveira2</dc:creator>
      <dc:date>2014-10-09T20:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between Points</title>
      <link>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668797#M51901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At the moment this process is comparing apples and oranges and it will give incorrect results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This said, the process needed is to build in a reproject function to take the coordinates from Geographic Coordinates (decimal degrees) into Map units (meters).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Todo Get distance between 2 point&lt;/P&gt;&lt;P&gt;Step 1: Build up representation of 1st point in memory as PointGeometry Object&lt;/P&gt;&lt;P&gt;Step 2; Reproject point in map units&lt;/P&gt;&lt;P&gt;Step 3: Build up representation of 2nd point in memory as PointGeometryObject&lt;/P&gt;&lt;P&gt;Step 4: Reproject this into Map Units&lt;/P&gt;&lt;P&gt;Step 5: Compare the 2 points using Pythagoras Formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached is a function to perform the Reproject using the arcpy module&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#projectSR&lt;/P&gt;&lt;P&gt;def projectSR (pt, sr): #sr = spatial reference, pt is geometry in memory&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #constantts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gcs = arcpy.SpatialReference(2193)&amp;nbsp; #2193 = factory code for NZ Transverse Mercator &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gt = 'NZGD_2000_To_WGS_1984_1' #geographic transformation, if application&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptgeom = arcpy.PointGeometry(pt, nztm).projectAs(gcs, gt)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords.insert(0,(ptgeom.centroid.X))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; coords.insert(1,(ptgeom.centroid.Y))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del ptgeom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return coords&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Call projectSR to get the coordinates in map units meters and then you'll be able to use the Pythagoras theorem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Susan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 20:59:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668797#M51901</guid>
      <dc:creator>SusanJones</dc:creator>
      <dc:date>2014-10-09T20:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between Points</title>
      <link>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668798#M51902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you still want to use Haversine, there are many examples on the web in python,&lt;A href="http://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points"&gt; for example&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 22:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/distance-between-points/m-p/668798#M51902</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-09T22:07:26Z</dc:date>
    </item>
  </channel>
</rss>

