Select to view content in your preferred language

How to delete vertices from a line when inside a selecting polygon

2897
8
Jump to solution
01-24-2022 06:11 PM
Labels (2)
LindsayRaabe_FPCWA
MVP Regular Contributor

Hi Brains Trust. I'm doing some cleanup work on a road network to make it suitable for Network Analysis, and have come across the following issue. One of the steps I have is usin the Integrate tool to align spatially different datasets. Unfortunately, a side effect of this is that lines passing across each other which normally don't intersect (as in no co-located vertices which Network Analyst uses to permit turns) now do. I've identified a lot of overpass/underpass areas which need to have these no-turn intersections cleaned, but can't find a way to bulk delete vertices when identified by an intersecting polygon. Any ideas out there on how to achieve this?

 

Below screenshot shows where a route turns off a bridge instead of following along the off ramp. 

LindsayRaabe_FPCWA_0-1643076407010.png

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
1 Solution

Accepted Solutions
LindsayRaabe_FPCWA
MVP Regular Contributor

Hi. Do you have an advanced license? In a nut shell, I use one of these to:

  1. Convert line vertices to points (Feature Vertices To Points (Data Management)—ArcGIS Pro | Documentation - ADVANCED license)
  2. Erase the points that fall within the polygon (Erase (Analysis)—ArcGIS Pro | Documentation - ADVANCED license)
  3. Reconstruct the lines from the remaining points (Points To Line (Data Management)—ArcGIS Pro | Documentation - BASIC license)

At the time I didn't figure out how to do it without an advanced license, but with some playing around with python, now I have! 

Starting data:

LindsayRaabe_FPCWA_0-1752236438211.png

1. Convert lines to points using below python code:

import arcpy

# Set paths
input_fc = r"C:\YourProject\YourGDB.gdb\YourPolylineLayer"
output_fc = r"C:\YourProject\YourGDB.gdb\PolylineVertices"

# Use the same spatial reference as the input
spatial_ref = arcpy.Describe(input_fc).spatialReference

# Create output point feature class
arcpy.CreateFeatureclass_management(
    out_path=r"C:\YourProject\YourGDB.gdb",
    out_name="PolylineVertices",
    geometry_type="POINT",
    spatial_reference=spatial_ref
)

# Add a field to track original feature ID (optional)
arcpy.AddField_management(output_fc, "SourceID", "LONG")

# Insert points
with arcpy.da.SearchCursor(input_fc, ["OID@", "SHAPE@"]) as search_cursor, \
     arcpy.da.InsertCursor(output_fc, ["SHAPE@", "SourceID"]) as insert_cursor:

    for oid, polyline in search_cursor:
        for part in polyline:
            for point in part:
                if point:
                    insert_cursor.insertRow((point, oid))

 

LindsayRaabe_FPCWA_1-1752236489295.png

2. Use Select by Location to select undesirable points

LindsayRaabe_FPCWA_2-1752236549637.png

3. Use Delete Rows to delete selected points

LindsayRaabe_FPCWA_3-1752236627431.png

LindsayRaabe_FPCWA_4-1752236712760.png

4. Use Points to Line to reconstruct lines from remaining points

LindsayRaabe_FPCWA_5-1752236802454.png

Turn that python code into a python tool and you can string that into a model with the rest of the tools to repeat as needed. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA

View solution in original post

0 Kudos
8 Replies
DanPatterson
MVP Esteemed Contributor

Erase Point (Editing)—ArcGIS Pro | Documentation

assuming you aren't talking about manual editing


... sort of retired...
0 Kudos
LindsayRaabe_FPCWA
MVP Regular Contributor

Close! Yes, I'm not talking manually - that I have well and truly sorted. Trying to automate/script a faster solution for preidentified "issue" intersections. 

The Erase Point tool is almost what I need, except I want vertices on a line - not standalone point features. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
MVP Regular Contributor

I've just found this post (https://gis.stackexchange.com/questions/227268/delete-line-vertex-from-polyline-layer-using-point-fe...) that leads me to the Feature Vertices to Points tool, which might have been helpful in a larger convert, select, rebuild process, but I don't have access to an Advanced licence (only Standard). 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
MVP Regular Contributor

Also just found this (https://gis.stackexchange.com/questions/227115/remove-polyline-vertex-outside-polygon-in-arcpy) from 5 years ago so will see if I can make it work. I've got a trial of XTools Pro which gives me the Line to Point option, so at least I have something to play with.

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
NathanGEOregon
Occasional Contributor

@LindsayRaabe_FPCWA  did you ever find a solution to this? I have a similar situation with a water distribution network.

0 Kudos
LindsayRaabe_FPCWA
MVP Regular Contributor

Hi. Do you have an advanced license? In a nut shell, I use one of these to:

  1. Convert line vertices to points (Feature Vertices To Points (Data Management)—ArcGIS Pro | Documentation - ADVANCED license)
  2. Erase the points that fall within the polygon (Erase (Analysis)—ArcGIS Pro | Documentation - ADVANCED license)
  3. Reconstruct the lines from the remaining points (Points To Line (Data Management)—ArcGIS Pro | Documentation - BASIC license)

At the time I didn't figure out how to do it without an advanced license, but with some playing around with python, now I have! 

Starting data:

LindsayRaabe_FPCWA_0-1752236438211.png

1. Convert lines to points using below python code:

import arcpy

# Set paths
input_fc = r"C:\YourProject\YourGDB.gdb\YourPolylineLayer"
output_fc = r"C:\YourProject\YourGDB.gdb\PolylineVertices"

# Use the same spatial reference as the input
spatial_ref = arcpy.Describe(input_fc).spatialReference

# Create output point feature class
arcpy.CreateFeatureclass_management(
    out_path=r"C:\YourProject\YourGDB.gdb",
    out_name="PolylineVertices",
    geometry_type="POINT",
    spatial_reference=spatial_ref
)

# Add a field to track original feature ID (optional)
arcpy.AddField_management(output_fc, "SourceID", "LONG")

# Insert points
with arcpy.da.SearchCursor(input_fc, ["OID@", "SHAPE@"]) as search_cursor, \
     arcpy.da.InsertCursor(output_fc, ["SHAPE@", "SourceID"]) as insert_cursor:

    for oid, polyline in search_cursor:
        for part in polyline:
            for point in part:
                if point:
                    insert_cursor.insertRow((point, oid))

 

LindsayRaabe_FPCWA_1-1752236489295.png

2. Use Select by Location to select undesirable points

LindsayRaabe_FPCWA_2-1752236549637.png

3. Use Delete Rows to delete selected points

LindsayRaabe_FPCWA_3-1752236627431.png

LindsayRaabe_FPCWA_4-1752236712760.png

4. Use Points to Line to reconstruct lines from remaining points

LindsayRaabe_FPCWA_5-1752236802454.png

Turn that python code into a python tool and you can string that into a model with the rest of the tools to repeat as needed. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
City_of_Salem_OregonGIS
Emerging Contributor

My use case was a little different, but this general workflow worked like a charm! I have a water distribution network where lines cross each other, but aren't actually connected. So I needed to delete all of the vertices where lines intersected where there wasn't actually a point feature connecting them.

So my workflow was basically

 

  1. Feature Vertices to Points (Start and Endpoints)
  2. Feature Vertices to Points (All vertices)
  3. Collect Events on the All vertices layer (counts how many vertices are stacked on each other)
  4. Delete features in the resulting Collect Events Layer where Count = 1
  5. Select By Location with the Collect Events Layer as the input using the Start and Endpoint Vertices layer and delete those features from the Collect Events layer
  6. Select By Location with the All Vertices layer as the input using the resulting Collect Events Layer and deleting those points (at this step, I've deleted all vertices where there is more than one vertex at a given location, which aren't either a start or endpoint)
  7. Run Point To Line tool on the remaining All vertices layer

This was a really easy way to accomplish this, thanks for the insight!

LindsayRaabe_FPCWA
MVP Regular Contributor

Glad you found it useful and managed to adapt it to your needs!

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos