<?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 Calculate distance between consecutive points in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389696#M22378</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I wish to calculate the distance between consecutive points in a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried using the following code in the "Pre-Logic VBA Script Code" box in the Field Calculator dialog -&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;static x0 as double, y0 as double ' Previous location&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;BR /&gt;&lt;SPAN&gt;x = pPoint.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;y = pPoint.Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;d = sqr((x - x0)^2 + (y - y0)^2) ' Distance&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;x0 = x&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;y0 = y&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but it doesn't work. Does anyone have any suggestions? Thanks for any help anyone can give me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Mar 2014 23:42:20 GMT</pubDate>
    <dc:creator>KarrenO_Neill</dc:creator>
    <dc:date>2014-03-06T23:42:20Z</dc:date>
    <item>
      <title>Calculate distance between consecutive points</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389696#M22378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I wish to calculate the distance between consecutive points in a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried using the following code in the "Pre-Logic VBA Script Code" box in the Field Calculator dialog -&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;static x0 as double, y0 as double ' Previous location&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;BR /&gt;&lt;SPAN&gt;x = pPoint.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;y = pPoint.Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;d = sqr((x - x0)^2 + (y - y0)^2) ' Distance&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;x0 = x&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;y0 = y&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but it doesn't work. Does anyone have any suggestions? Thanks for any help anyone can give me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Mar 2014 23:42:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389696#M22378</guid>
      <dc:creator>KarrenO_Neill</dc:creator>
      <dc:date>2014-03-06T23:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate distance between consecutive points</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389697#M22379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi &lt;BR /&gt;I wish to calculate the distance between consecutive points in a feature class.&lt;BR /&gt;I tried using the following code in the "Pre-Logic VBA Script Code" box in the Field Calculator dialog -&lt;BR /&gt; &lt;BR /&gt;static x0 as double, y0 as double ' Previous location&lt;BR /&gt;dim pPoint as IPoint&lt;BR /&gt;set pPoint = [Shape]&lt;BR /&gt;&lt;BR /&gt;x = pPoint.X&lt;BR /&gt;y = pPoint.Y&lt;BR /&gt;d = sqr((x - x0)^2 + (y - y0)^2) ' Distance&lt;BR /&gt;x0 = x&lt;BR /&gt;y0 = y&lt;BR /&gt;&lt;BR /&gt;but it doesn't work. Does anyone have any suggestions? Thanks for any help anyone can give me.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VB Script at 10.0 or later cannot use the DIM statement to create Point variables anymore (or any other variable type other than Variant).&amp;nbsp; You have to use Python for all geometry field calculations from now on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my attempt based on an adaptation of the &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/88260-Sequential-Number?highlight=autoincrement+python" rel="nofollow noopener noreferrer" target="_blank"&gt;autoincrement&lt;/A&gt;&lt;SPAN&gt; calculation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Parser: Python&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use Codeblock: checked&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Codeblock:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;x0 = 0.0
y0 = 0.0
def distance(x, y):
 global x0
 global y0
 if x0 = 0.0 and y0 = 0.0:
&amp;nbsp; x0 = x
&amp;nbsp; y0 = y
 d = math.sqrt((x - x0)**2 + (y - y0)**2) # Distance
 x0 = x
 y0 = y
 return d&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: distance(!shape.Centroid.X!, !shape.Centroid.Y!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am assuming the first point should give a distance of 0, so I set an invalid coordinate that I know will not be in your data and replace that impossible value with the first point value.&amp;nbsp; If 0,0 is a possible coordinate change the initial x0 and y0 values outside the def to a known invalid point location and change the if condition to match it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:52:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389697#M22379</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T17:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate distance between consecutive points</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389698#M22380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Richard,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;great! thanks for that. One slight error the if statement should read - if x0 == 0.0 and y0 = =0.0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Very much appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 21:54:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389698#M22380</guid>
      <dc:creator>KarrenO_Neill</dc:creator>
      <dc:date>2014-03-10T21:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate distance between consecutive points</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389699#M22381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Richard,&lt;BR /&gt;great! thanks for that. One slight error the if statement should read - if x0 == 0.0 and y0 = =0.0:&lt;BR /&gt;Very much appreciated!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I always forget that.&amp;nbsp; I am a VB Script guy more than a Python guy and that trips me up all the time.&amp;nbsp; Anyway, glad you got it working.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2014 22:21:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389699#M22381</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-03-10T22:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate distance between consecutive points</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389700#M22382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Richard,&lt;BR /&gt;great! thanks for that. One slight error the if statement should read - if x0 == 0.0 and y0 = =0.0:&lt;BR /&gt;Very much appreciated!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I only write VB Script calculations if I don't have to use Python, so when I have to use Python I always forget that = is not == (there is no such thing as == in VB Script).&amp;nbsp; So I normally make that mistake in all the code examples I write from memory on the Forum that I have not actually run.&amp;nbsp; In any case, glad it works for what you needed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 14:45:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-distance-between-consecutive-points/m-p/389700#M22382</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-03-19T14:45:11Z</dc:date>
    </item>
  </channel>
</rss>

