<?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 straight line distance between consecutive locations in Spatial Statistics Questions</title>
    <link>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537974#M1725</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't have an answer for you, but I have the same question! With the additional detail of having my points in date order, but also having different categories of points for which I would like to calculate distance moved in date order. Feedback on this would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Oct 2013 19:24:19 GMT</pubDate>
    <dc:creator>ElisabethCondon</dc:creator>
    <dc:date>2013-10-28T19:24:19Z</dc:date>
    <item>
      <title>Calculating straight line distance between consecutive locations</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537973#M1724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well I am back to dealing with the un-user friendly ArcGIS, and I have a basic question. I import a bunch of GPS coordinates in Arcscene, and I would like to add a field in my attribute table. I would like to calculate the distance between consecutive points (all data is arranged in chronological order). What is the easiest way to do it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Aug 2013 06:51:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537973#M1724</guid>
      <dc:creator>XavierGlaudas</dc:creator>
      <dc:date>2013-08-31T06:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating straight line distance between consecutive locations</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537974#M1725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't have an answer for you, but I have the same question! With the additional detail of having my points in date order, but also having different categories of points for which I would like to calculate distance moved in date order. Feedback on this would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Oct 2013 19:24:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537974#M1725</guid>
      <dc:creator>ElisabethCondon</dc:creator>
      <dc:date>2013-10-28T19:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating straight line distance between consecutive locations</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537975#M1726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Gludo and Elisabeth,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you can use some Python to achieve this. See example below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():

&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; # assume data is available as point featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; # and fc has projected coordinate system&lt;STRONG&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = "c:/folder/yourGeodatabase.gdb/yourFCname" # change this (path to featureclass GPS points)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fldDistance = "DistGPSpoints"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # change this (output name distance field)&lt;/STRONG&gt;


&amp;nbsp;&amp;nbsp;&amp;nbsp; # add distance field if it doesn't exist
&amp;nbsp;&amp;nbsp;&amp;nbsp; if FieldExist(fc,fldDistance) == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, fldDistance, "DOUBLE")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create update cursor for feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = ['SHAPE@XY', fldDistance]
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prevX = X
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prevY = Y
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X = row[0][0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y = row[0][1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt == 1:
&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;&amp;nbsp; # for first point distance is 0
&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;&amp;nbsp; distance = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = getDist(X,Y,prevX,prevY)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update row
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = distance
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

&amp;nbsp;&amp;nbsp;&amp;nbsp; del row


def getDist(X1,Y1,X2,Y2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; import math
&amp;nbsp;&amp;nbsp;&amp;nbsp; return math.hypot(X2 - X1, Y2 - Y1)


def FieldExist(featureclass, fieldname):
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldList = arcpy.ListFields(featureclass, fieldname)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldCount = len(fieldList)

&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fieldCount == 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return False



if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will need to change the path to the featureclass and the name of the output field. It assumes the data is available as point featureclass and the point should be projected (not in a geographic coordinate system).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script will:&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;add the output distance field (now named "&lt;STRONG&gt;DistGPSpoints&lt;/STRONG&gt;") if it doesn't exist yet&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;loop through the points and calculate the distance to the previous point&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:21:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/calculating-straight-line-distance-between/m-p/537975#M1726</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T23:21:27Z</dc:date>
    </item>
  </channel>
</rss>

