<?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 along a polyline in Spatial Data Science Questions</title>
    <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107507#M284</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No...as indicated, the interpoint distance examples I suggested would give you the Euclidean distance between the points, I think you want points to be along the polyline after they are snapped, then distance determined along the polyline...I would go with Xander's solution...just change the input files and run his script in a script editor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Feb 2015 22:07:43 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-02-06T22:07:43Z</dc:date>
    <item>
      <title>Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107500#M277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have points marking tagged fish locations along a river. How do I measure the distance between each of those successive points?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Feb 2015 13:36:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107500#M277</guid>
      <dc:creator>JodyCamille</dc:creator>
      <dc:date>2015-02-01T13:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107501#M278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't specify the format of your data...but lets assume that the points are in sequential order in something like a shapefile's table.&amp;nbsp; You can create a new field in your table (ie Dist type double etc) and use one of the code blocks specifying a Python parser and copying&lt;/P&gt;&lt;P&gt;dist_between(!Shape!)&amp;nbsp; or&amp;nbsp; dist_cumu(!Shape!)&lt;/P&gt;&lt;P&gt;depending upon whether you need inter-point distance or cumulative distance.&amp;nbsp; (Note...haven't tested in a long time)&lt;/P&gt;&lt;P&gt;EDIT&amp;nbsp;&amp;nbsp; this will give you the point to point distance, if you points form part of the polyline, convert the polyline to points first&lt;/P&gt;&lt;P&gt;otherwise you will get the Euclidean distance between the points and not the points along the polyline&lt;/P&gt;&lt;P&gt;for interpoint distance&lt;/P&gt;&lt;P&gt;I have added a function to produce points along a polyline based upon an increment if that will help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;''' input shape field: returns distance between points
dist_between(!Shape!)&amp;nbsp;&amp;nbsp;&amp;nbsp; #enter into the expression box'''
x0 = 0.0;&amp;nbsp; y0 = 0.0;&amp;nbsp; distance = 0.0
def dist_between(shape):
&amp;nbsp; global x0;&amp;nbsp; global y0;&amp;nbsp; global distance
&amp;nbsp; x = shape.firstpoint.X;&amp;nbsp; y = shape.firstpoint.Y
&amp;nbsp; if x0 == 0.0 and y0 == 0.0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; x0 = x; y0 = y
&amp;nbsp; distance = math.sqrt((x - x0)**2 + (y - y0)**2)
&amp;nbsp; x0 = x;&amp;nbsp; y0 = y
&amp;nbsp; return distance&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for cumulative distance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;''' input shape field: returns cumulative distance between points
dist_cumu(!Shape!)&amp;nbsp;&amp;nbsp;&amp;nbsp; #enter into the expression box'''
x0 = 0.0;&amp;nbsp; y0 = 0.0;&amp;nbsp; distance = 0.0
def dist_cumu(shape):
&amp;nbsp; global x0;&amp;nbsp; global y0;&amp;nbsp; global distance
&amp;nbsp; x = shape.firstpoint.X;&amp;nbsp; y = shape.firstpoint.Y
&amp;nbsp; if x0 == 0.0 and y0 == 0.0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; x0 = x; y0 = y
&amp;nbsp; distance += math.sqrt((x - x0)**2 + (y - y0)**2)
&amp;nbsp; x0 = x;&amp;nbsp; y0 = y
&amp;nbsp; return distance

# create points along polyline example
&lt;SPAN style="font-family: Consolas;"&gt;''' input shape field, value (distance or decimal fraction, 0-1), use_fraction (True/False), XorY (X or Y):
&amp;nbsp;&amp;nbsp;&amp;nbsp; returns a point x meters or x&amp;nbsp; decimal fraction along a line, user specifies whether X or Y coordinates
pnt_along(!Shape!, 100, False, 'X')&amp;nbsp;&amp;nbsp;&amp;nbsp; #eg.&amp;nbsp; calculate X coordinate 100 m from start point '''
def pnt_along(shape, value, use_fraction, XorY):
&amp;nbsp; XorY = XorY.upper()
&amp;nbsp; if use_fraction and (value &amp;gt; 1.0):
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = value/100.0
&amp;nbsp; if shape.type == "polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = shape.boundary()
&amp;nbsp; pnt = shape.positionAlongLine(value,use_fraction)
&amp;nbsp; if XorY == 'X':&amp;nbsp; return pnt.centroid.X
&amp;nbsp; else:&amp;nbsp; return pnt.centroid.Y&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:30:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107501#M278</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T06:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107502#M279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If these points located along river line you can use linear referenceing tool to measure the route length along river&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//003900000001000000" title="http://resources.arcgis.com/en/help/main/10.1/index.html#//003900000001000000"&gt;ArcGIS Help 10.1&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Feb 2015 15:08:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107502#M279</guid>
      <dc:creator>MohamedMagdy</dc:creator>
      <dc:date>2015-02-01T15:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107503#M280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case you have a featureclass with the river (1 line) and a point featureclass with the fishing locations, then you should snap those points to the line, obtain the position of the snapped points on the line, define the distance from the start of the river, sort the location on distance from start and determine the distance between consecutive points. In python this would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc_pnt = r"C:\Forum\Fishing\test.gdb\fishingpoints"
fc_line = r"C:\Forum\Fishing\test.gdb\river"
fld_diststart = "DistStart"
fld_distprevious = "DistPrev"

# add fields to point featureclass in case they do not exist
add_flds = [fld_diststart, fld_distprevious]
for fld in add_flds:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(arcpy.ListFields(fc_pnt, wild_card=fld)) == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc_pnt, fld, "DOUBLE")

# get first (only?) polyline from lines featureclass
polyline = arcpy.da.SearchCursor(fc_line, ("SHAPE@",)).next()[0]

dct = {}
flds = ("SHAPE@", "OID@", fld_diststart)
with arcpy.da.SearchCursor(fc_pnt, flds) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diststart = polyline.queryPointAndDistance(pnt, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct[oid] = diststart[1]
del curs, row

# sort on distance and determine distance between points
dct2 = {}
cnt = 0
for oid, diststart in sorted(dct.items(), key=lambda x: x[1]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distbetween = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distprev = diststart
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distbetween = diststart - distprev
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distprev = diststart
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct2[oid] = distbetween

# update the points fc
flds = ("OID@", fld_diststart, fld_distprevious)
with arcpy.da.UpdateCursor(fc_pnt, flds) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = dct[oid]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = dct2[oid]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)
del curs, row&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result will look like this:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Fishing.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/57373_Fishing.png" style="width: 620px; height: 192px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:30:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107503#M280</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T06:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107504#M281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you have many choices. Using the linear referencing as Mohammed Magdy mentioned gives you the cumulative distance from the start of the river. There is another method which utilizes the "Point Distance Tool". The output of the tool is a table containing all distances from any point to other points.&lt;SPAN style="line-height: 1.5;"&gt; For example, If you have 8 points, then the distances from the point 1 to the other seven points are computed and then the distances from point 2 to the other seven points are computed and stored and so on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;There is another method which could be useful. you can split the river into segments at the fishing sites using "Split Line At Point" tool and store the output in a feature class inside a geodatabase. then you can find the distances stored in the Shape_Length field of the output feature class.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Feb 2015 16:45:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107504#M281</guid>
      <dc:creator>MohammedAlhessi2</dc:creator>
      <dc:date>2015-02-01T16:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107505#M282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I appreciate your comments, Dan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a point shapefile of tagged fish locations. I snapped those points to a polyline shapefile of the rivers that the fish migrated on. Should I convert the river (polyline) shapefile to a point file and calculate your code on a distance field in that newly converted point file?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Jody&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:35:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107505#M282</guid>
      <dc:creator>JodyCamille</dc:creator>
      <dc:date>2015-02-06T19:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107506#M283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try the code I posted? It does not require you to snap your points to the river...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 19:46:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107506#M283</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-02-06T19:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107507#M284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No...as indicated, the interpoint distance examples I suggested would give you the Euclidean distance between the points, I think you want points to be along the polyline after they are snapped, then distance determined along the polyline...I would go with Xander's solution...just change the input files and run his script in a script editor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 22:07:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107507#M284</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-02-06T22:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107508#M285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have the Network Analyst extension I think you might find that it is easiest to use the Origins Destinations (OD) Cost Matrix tool. I have done this for several instances like this and it works well. You do need to create a network dataset using fish locations as point data and then your stream(s) as your line data. ESRI has a nice overview of the tool here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00480000000m000000" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00480000000m000000&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 17:51:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107508#M285</guid>
      <dc:creator>KelseyRydland</dc:creator>
      <dc:date>2015-05-28T17:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107509#M286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This looks like a good script for my needs right now. I have many points that are associated with many different lines. They don't necessarily fall on the lines but I know which line they should be associated with by a unique line&amp;nbsp; ID. It seems I can use your script above but I need to somehow find the right line for the right points. Seems like maybe I should set up a cursor first for the lines that accesses the unique line ID field, and below set up a cursor for the points that accesses the unique line ID field that is attached to the points, and when those values match, then do the distance calculations? The data is multidimensional, where I have groups of points associated with a vehicle, and there are time values for each point as well, that essentially represent trips along each line. I've already sorted on the vehicle ID, the line ID, the time and the coords and now want to calculate the distance, and ultimately the speed of the vehicle between each point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Aug 2015 19:09:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107509#M286</guid>
      <dc:creator>KirstenLawrence</dc:creator>
      <dc:date>2015-08-01T19:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107510#M287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your are wrong on how you should approach this problem.&amp;nbsp; Embedded cursors are virtually never the solution to any problem.&amp;nbsp; Use a dictionary to make the match between the line IDs and the points and then process one cursor normally.&amp;nbsp; The larger your datasets get the embedded cursors slow down exponentially, while Dictionaries have a linear performance impact.&amp;nbsp; So for 10000 points on 100 lines embedded cursors will perform at least 100 times slower than a dictionary lookup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although I have not tested the code below, I believe it will work.&amp;nbsp; The main part I am unsure of is the sort of dct that creates dct2.&amp;nbsp; In any case, once all bugs are worked out this code will perform wonderfully.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 9pt;"&gt;import arcpy&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;fc_pnt = r"C:\Forum\Fishing\test.gdb\fishingpoints"&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;fc_line = r"C:\Forum\Fishing\test.gdb\river"&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;fld_diststart = "DistStart"&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;fld_distprevious = "DistPrev"&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;# add fields to point featureclass in case they do not exist&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;add_flds = [fld_diststart, fld_distprevious]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;for fld in add_flds:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(arcpy.ListFields(fc_pnt, wild_card=fld)) == 0:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc_pnt, fld, "DOUBLE")&amp;nbsp; &lt;/SPAN&gt;

&lt;SPAN style="font-size: 9pt;"&gt;fields = ["LINE_ID", "SHAPE@"]&lt;/SPAN&gt;

&lt;SPAN style="font-size: 9pt;"&gt;# Create a dictionary of lines with their geometry&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(fc_line, fields)}&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;dct = {}&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;flds = ["LINE_ID", "SHAPE@", "OID@", fld_diststart]&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;with arcpy.da.SearchCursor(fc_pnt, flds) as curs:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line = row[0]&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if line in valueDict:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polyline = valueDict[line]&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = row[1]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row[2]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diststart = polyline.queryPointAndDistance(pnt, False)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct[(line, oid)] = diststart[1]&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;del curs, row&amp;nbsp; &lt;/SPAN&gt;

&lt;SPAN style="font-size: 9pt;"&gt;# sort on distance and determine distance between points&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;dct2 = {}&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;cnt = 0&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;prevline = -1&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;for line_oid, diststart in sorted(dct.items(), key=lambda x: x[1]):&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += 1&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt == 1:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distbetween = 0&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distprev = diststart&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prevline = line_oid[0] &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif line_oid[0] != prevline: &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distbetween = 0&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distprev = diststart&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prevline = line_oid[0] &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distbetween = diststart - distprev&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distprev = diststart&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct2[line_oid] = distbetween&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;# update the points fc&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;flds = ("LINE_ID", "OID@", fld_diststart, fld_distprevious)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;with arcpy.da.UpdateCursor(fc_pnt, flds) as curs:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line = row[0]&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row[1]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (line, oid) in dct:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = dct[(line, oid)]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[3] = dct2[(line, oid)]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 9pt;"&gt;del curs, row &lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:30:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107510#M287</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T06:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107511#M288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply that does make sense. I will test your code, thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 14:06:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107511#M288</guid>
      <dc:creator>KirstenLawrence</dc:creator>
      <dc:date>2015-08-02T14:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107512#M289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to sort on more than just line id, oid and distance.. as I mentioned there are multiple sets of a points along each line that need to be grouped and then have the distance calculated.. essentially I think the dct key needs to include some additional fields&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 14:22:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107512#M289</guid>
      <dc:creator>KirstenLawrence</dc:creator>
      <dc:date>2015-08-02T14:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107513#M290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have a screen grab?&amp;nbsp; What sounded like a simple question now has more dimensions to it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 14:56:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107513#M290</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-08-02T14:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107514#M291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a screenshot. The different colored points represent different vehicles that are traveling along the road. I have date/time values associated with each point, and the idea is to determine the avg speed of each vehicle by using the distance between each point in a given trip (which I am roughly determining by date and time), and then calculate the time difference between points to then determine the speed. I have over a million points!&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" height="371" src="https://community.esri.com/legacyfs/online/120274_pastedImage_1.png" style="height: 371px; width: 697.03px;" width="697" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 16:03:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107514#M291</guid>
      <dc:creator>KirstenLawrence</dc:creator>
      <dc:date>2015-08-02T16:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107515#M292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are willing to share a "small" part of the data we could have a look and see what method best matches your specific question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 17:40:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107515#M292</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-02T17:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107516#M293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The lines dictionary won't change, since it only has the line ID.&amp;nbsp; The points dictionary can have any tuple for the key that you may want as long as the line ID is the first field in the tuple or at a known position in the key, so the look up of the line does not change.&amp;nbsp; I see no real difference in the way the code would be structured other than what values reset the counter.&amp;nbsp; So dct and dct2 would change but not valueDict.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case with over 1 million points and probably thousands of lines you would wait days or months for an embedded cursor to finish.&amp;nbsp; However, with that many points and lines you may run out of memory if you process the complete set into these dictionaries in one run.&amp;nbsp; You have to create a loop surrounding my code and process queries in the outer loop to segment the line and point sets into smaller groups (say iterating through ranges of 500 line IDs in the lines and points) .&amp;nbsp; The dictionaries would be cleared and reset in each loop so that your memory would not run out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Aug 2015 20:47:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107516#M293</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-08-02T20:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107517#M294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When testing out your code above the script will run, but the first point values return 0 for both DistStart and DistPrev.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/335230_pastedImage_1.png" style="width: auto; height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Why would this be?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2017 19:25:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107517#M294</guid>
      <dc:creator>KyleCrawford2</dc:creator>
      <dc:date>2017-03-06T19:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107518#M295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have geographic coordinates?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Mar 2017 02:10:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107518#M295</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-03-07T02:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between points along a polyline</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107519#M296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Made the mistake of not correcting the geographic coordinates. Once corrected script works great thanks for sharing it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:18:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/distance-between-points-along-a-polyline/m-p/107519#M296</guid>
      <dc:creator>KyleCrawford2</dc:creator>
      <dc:date>2017-03-07T15:18:24Z</dc:date>
    </item>
  </channel>
</rss>

