2

I have two shapefiles: a series of points and a polyline created from the points with the tool Points to Line. Both shapefiles have the same projected coordinate system with a linear unit in metres.

enter image description here

If you were to calculate the distance to the points along this line - which is what I'm trying to do - the first point would have a value of 0 metres and the last a value of closer to 40 000 metres (the length of the line). I want to gather these values in an attribute field or a table so that I can plot the points in a graph with the distance in metres on the x axis.

I have tried the tool Locate Features Along Routes but for some reason the data doesn't come out right. I have tried the tool with both the original line and a route created from the line with the tool Create Routes.

Input values (identical for line and route):

enter image description here

Results - line:

enter image description here

Results - route:

enter image description here

Do you have any idea where I'm going wrong and what I should be doing instead? Is there another way to go about this?

I use ArcMap 10.4.1.

  • Use start-end points to calibrate route first. – FelixIP Mar 30 '18 at 1:02
  • Your end goal is a chart. So are you open to using other tools? How about making a sample shape file available to play with? – Werner Mar 30 '18 at 5:22
  • FelixIP: Could you elaborate a bit? As I explained in the question, I did create a route with the tool Create Routes. Werner: Maybe this weekend! If I haven't figured it out by then. – Linebeck Apr 5 '18 at 12:09
2

You can use (Split line at vertices) for your polyline shapefile that you created.

The result is the line segments with each length.

enter image description here

This tool needs Advanced license of ArcGIS. And of course, there are other options.

To get a new table with the points id, joining line id and the lengths, You can use (Spatial join) between the points and lines shapefiles.

  • -1 because it doesn't answer question and misleading. Tool is available for advanced license only. – FelixIP Mar 30 '18 at 1:26
  • @FelixIP Sorry, I got confused and I didn't pay attention that it's just for the advanced license. But for the question about distance along line, it solves the problem well. – Moh Mar 30 '18 at 1:29
  • Remove down vote, after amendment. Still incomplete answer. How to transfer segment lengths to points table? – FelixIP Mar 30 '18 at 1:39
  • This also doesn't measure the distance along the line from the beginning of the line, as the original problem stated. – crmackey Mar 30 '18 at 14:41
  • Thank you for the answer. I still haven't had the time to try this, but it only works if the points are vertices on the line, right? So I would have to start by converting the point into verticles. – Linebeck Apr 5 '18 at 12:17
1

You can accomplish this very easily with Python, no need for any advanced licensing. This function can be used in the Python window of ArcMap and/or saved as a standalone script for future use (you would need to make sure to import arcpy first):

def measure_along_line(line, line_rid, points, point_rid, distance, factor=1):
    """ Calculates distances at points along line from beginning of segment

    Required:
        line -- input line feature class
        line_rid -- unique id for line route id
        points -- points feature class
        point_rid -- id field that matches up with values in line_rid
        distance -- field that will contain distance calculations

    Optional:
        factor -- factor for conversion of units. Default is 1.  If feature
            class units are in meters and you want to convert to feet, use a
            factor of 3.28084.

    """
    # read all lines into dict
    with arcpy.da.SearchCursor(line, [line_rid, 'SHAPE@']) as rows:
        ld = dict(r for r in rows)

    # now get the measure along line for every point (measure distance is in same units of projection)
    with arcpy.da.UpdateCursor(points, [point_rid, 'SHAPE@', distance]) as rows:
        for r in rows:
            # first get associated line
            line = ld.get(r[0])
            if line:
                # now get measure distance from beginning of line to this point
                measure = line.measureOnLine(r[1], False) * factor
                r[2] = measure
                rows.updateRow(r)

Here is the example I used in ArcMap (note I used a factor of 3.28084 to convert meters to feet):

enter image description here

And here is the table afterwards:

enter image description here

And what the data looks like:

enter image description here

This is done by using the arcpy.Polyline.measureOnLine() method, which does exactly what you're trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.