# Linear referencing to calculate maximum distance between points by group along line (river system) using ArcGIS Pro

I am using ArcGIS Pro.

I have a series of points representing animal locations that were tracked in a small stream. I would like to get the distance between the most upstream and downstream location for each individual (also known as the Linear Home Range), following the river path. Essentially the largest distance along this line between points, grouped by individual. I have downloaded a polylineZM file for the stream - and I understand that I can use Linear Referencing to get the distances between these points, and a measure of the point location in reference to the beginning of the line. But, I am looking for a little more than this, as this result gives me an output that I would need to manually manipulate to get my answer. If there is a code or workflow that would help me to easily calculate this without having to split the data set into a file for each individual, manually rerun it for each individual, sort output by the distance along the line and then manually subtract the largest and smallest points, that would be ideal.

The most recent point may not necessarily be the most upstream point, as the animals are not only traveling in one direction. Below is a screen grab of my points -

If there is a need to write an ArcPy script or a suggestion for manipulating the data after the Linear Referencing output file after it is created - I am all ears.

• You need to check if the M value in your river network is a measurement from the end of the polyline or a measurement from the mouth of the river. If it is the latter then simply run locate features along route. You could then run a summary stats tool grouping by individual ID and extract out min and max distance so you can compute length. Feb 15, 2020 at 23:48
• Thank you - I tried this and it worked well, but right now it seems like the range between max and min is reporting smaller than I would expect and I am not sure why. I will see if there is something wrong with the file imported and where the M values are calculated from. Feb 16, 2020 at 0:03
• Should the bifurcation(s) be accounted for? Say ID 4 was seen on the left hand side branch of the river (in the snip, there is no occurrence) and ID 10 also appeared near ID 4. How do you want to map ID 10’s home range? Feb 16, 2020 at 1:07
• @fatih_dur - There is no need to account for bifurcation, the animals were all located within the stream in reality, but as it is a small stream it is best represented as a line and one of the easiest ways to portray their home range is as a portion of that line. Feb 16, 2020 at 23:58
• @Hornbydd Your solution worked for me - in some cases I needed to use the create Route tool to deal with in consistencies in the stream files, but this worked very well - I hope this can be of use to someone else as well. Feb 17, 2020 at 20:28

LR will calculate distances along separate river segments. To apply it you need "long" rivers starting at multiple upstream points, ending at outlet(s). If you are capable of producing geometric network you might use script from here, to calculate distances of network nodes to outlets and apply LR later.

Alternative to it is using raster approach, namely cost distance.

• populate new field in your streams table by value of 1
• convert them to raster (cost) using that field.
• derive both ends points for stream segments
• select outlet(s). Run cost distance using outlet(s) as sources
• Convert output raster to points:
• spatial join with your points will do the rest.

Note: in the picture above I labelled only some of the points. More accurate results can be obtained by using smaller cell size, but not overdo it, because your points are not perfect spatially.

After obtaining distances for all points, use summary statistics on animal I'd to compute Max and min of distance values.

• Thank you for this suggestion - can you give me a little more detail on some of these steps? How do I set a field value to equal 1? I have used field calculator before but not sure how to just make a value for all rows. Also, How do I derive the end points once I have made the stream segments? Feb 17, 2020 at 3:34
• Activate help, search field calculator. Same with feature vertices to point. Feb 17, 2020 at 4:02
• I am running into an issue testing this solution, and I'm not sure why it isn't working. I set a value of 1 for my stream table, and made a raster. I got the vertices of the lines, and in this case I am just dealing with one outlet, but the line is segmented so there were multiple vertices. I selected the start and end point for my study area and exported that as a new feature. When I tried running cost distance with the outlet as the source and the stream raster, the output raster was not visible and when I tried to convert to point - I got a warning that it did not create any features. Feb 17, 2020 at 15:41
• Set environment extent rqual to extent of stream raster. Snap raster and cell size as well. Zoom to see that your outlet sits in raster cell. I have no clue where start point coming from? Feb 17, 2020 at 18:28
• I found that my issue here was the end point was at the end of line, so it was not actually inside a raster cell, I moved it in and this allowed me to use the cost distance tool. I found that the solution proposed by @Hornybdd in the comments worked better for me as I am mostly dealing with simple stream files - however this could be a good solution for larger stream networks. It is worth noting that the smaller cell sizes allow better tracing of small streams - but can be tricky when doing the join, especially because many of my points are very close together. Thanks for the help Feb 17, 2020 at 20:25