5

There are multiple toolboxes in ArcGIS Suite that deal with geographic transformation and correction, such as Spatial Adjustment, Rubbersheeting, and Snap. I'm not sure how to best use a tool to correct my line to a series of points as shown in image #3:

Snapping a line to points

1) is what I currently have;
2) is what I get when I use the Snap tool; and
3) is what I want.

The points are considered accurate geographic "anchors" for the lines, but don't otherwise share any field attributes with the lines. I have access to a list of all of the point coordinates.

If I snap the line without vertices with the Snap tool, the tool doesn't work at all, even with a high tolerance set (higher than the distance between the line and the point).

I'd like to stick to ArcGIS Suite, and to use something that has a corresponding arcpy tool. I realize that I can move the anchors/delete the middle anchor (vertex) to get the shape in Figure #3, but I plan on automating this process because I have hundreds of lines and thousands of points.

7
  • 1: Generalize your line 2: snap your generalized line to your anchors
    – Mapperz
    Commented Oct 2, 2019 at 19:34
  • Thanks for the comment - generalizing my line takes me back to Figure 1, and Figure 3 is what I'm looking for. My question was too vague and has been edited--I should've asked how to best automate correcting my lines to points without snapping the vertices manually, since I have a few hundred lines/few hundred points and don't want to manually deal with anchors/vertices.
    – JMNC
    Commented Oct 2, 2019 at 19:40
  • Calculate chainages of points to line, use points to line tool, sort by chainages, lineid to make lines.
    – FelixIP
    Commented Oct 2, 2019 at 19:45
  • you can chain this in the model builder of ArcGIS - you need to test the torlence of the line to remove the vertices then snap - this can can be automated desktop.arcgis.com/en/arcmap/10.3/tools/cartography-toolbox/…
    – Mapperz
    Commented Oct 2, 2019 at 19:45
  • I've found that if I try to snap the line without any vertices near the calibration point, the Snap tool doesn't work at all, even with a distance buffer/tolerance set. I'll experiment with different tolerances/vertex settings though - thanks.
    – JMNC
    Commented Oct 2, 2019 at 19:52

2 Answers 2

4

I would approach this by reconstructing the line manually. Use a cursor to extract the start and end points from the line, sort the list of point coordinates by proximity to the start of the line, and reconstruct the new line geometry.

# assumes one line in in_line
in_line = r'\scratch.gdb\sample_line'
in_points = r'\scratch.gdb\sample_points' 

# get line start and end points
with arcpy.da.SearchCursor(in_line, ["SHAPE@"]) as cur: 
    for row in cur: 
        geom = row[0]
        point_first = geom.firstPoint
        coord_first = [point_first.X, point_first.Y]
        point_last = geom.lastPoint
        coord_last = [point_last.X, point_last.Y]

# get point coords as list
with arcpy.da.SearchCursor(in_points, ["SHAPE@"]) as cur: 
    points = [[row[0].centroid.X, row[0].centroid.Y] for row in cur]

# define a function used to sort points based on proximity to point_first
def coord_dif(coord_x):
    x_dif = abs(coord_first[0] - coord_x[0])
    y_dif = abs(coord_first[1] - coord_x[1])
    return (x_dif + y_dif) 

# sort points
points = sorted(points, key=coord_dif)
all_points = [coord_first] + points + [coord_last]

# construct geometry
line_geom = arcpy.Polyline(
    arcpy.Array(
        [arcpy.Point(pt[0], pt[1]) for pt in all_points]
    )
)

# update with new line goemetry
with arcpy.da.UpdateCursor(in_line, ["SHAPE@"]) as cur: 
    for row in cur: 
        cur.updateRow([line_geom])

before

after

2
  • 1
    This solution works if the anchor points continue in a constant direction. @JMNC does not actually say what these geometries represent. So if they are rivers for example when you enter a highly meandering section this approach falls over as the river bends around towards the start of the line, then you have the furthest point away nearest to the start.
    – Hornbydd
    Commented Oct 3, 2019 at 23:01
  • 1
    @Hornbydd, I am making an assumption that the points follow a linear pattern, as outlined in OP's example. Alternatively, you could first snap the line to the points, then iterate over all line vertices and keep only the first, last, and ones that match the point list.
    – bebego
    Commented Oct 4, 2019 at 14:49
2

Append end points of your lines to snap points and run near tool on appended set of points. Add field type "Double" to their table:

enter image description here

Rename original lines in table of content to "original" and use field calculator:

g = arcpy.Geometry()
geometryList=arcpy.CopyFeatures_management("original",g)
def getChainage(lineFID,point):
 line=geometryList[lineFID]
 return line.measureOnLine(point.firstPoint)
#------------
getChainage( !NEAR_FID!, !Shape! )

To populate new field in points table:

enter image description here

Points to line tool will do the rest:

arcpy.PointsToLine_management("points", "../SNAPPED.shp", "NEAR_FID", sort_Field="CHAINAGE")

enter image description here

Solution valid for shapefiles, it is a bit more complicated for other storage options. Note that you can use linear referencing to compute distances of points along original lines if you'd like to avoid field calculator used here.

2
  • I would rather have my existing line snap to the points rather than create a new line for two reasons: 1) I'd like to keep field attributes in my current line segments; and 2) While I have hundreds of points, they're unevenly spread out and don't encompass the entire length of the lines I'm working with. However, this is well-thought-out, simple, and will work for the question I posed and can be incorporated into my efforts - thanks.
    – JMNC
    Commented Oct 2, 2019 at 22:59
  • 1
    Add join field will immediately bring attributes into new line.
    – FelixIP
    Commented Oct 2, 2019 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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