Delete all non-end point vertices in a line

6585
9
11-28-2016 12:14 PM
RobBlash
Occasional Contributor III

I'm looking for a simple way to delete all of the "interior" (non endpoint) vertices in a line. It can't be a GP tool that writes a new output, I need to modify the existing features. Generalize wont work because the data is in a geometric network that I cannot delete and recreate. Ideally I could select multiple lines and have them processed with a single button click. Is there anything out there that will do this?

Tags (2)
0 Kudos
9 Replies
RebeccaStrauch__GISP
MVP Emeritus

You do realize that is you delete all the vertices that you will have a straight line between the two end points, correct?

If you are editing Deleting a vertex—Help | ArcGIS for Desktop   but since you are using a network, maybe this will help

Configuring the Network Dataset builder—Help | ArcGIS for Desktop  

I do not use networks myself, but that looks like it will help remove some vertices without compromising the network itself.  there are also several other links available from that landing page that might be of help.

0 Kudos
RobBlash
Occasional Contributor III

Yup a straight line is exactly what I want. This is for a water utility when a bunch of service connections are snapped to a line. If you move the line endpoints you wind up with a funky looking water line, unless you manually adjust all of the vertices where the services are snapped to the line. If you delete all of the middle vertices the geometric network retains the service snapping while giving you a nice straight line. I just need to figure out hot to do it efficiently. Delete vertices takes too long when there are thousands of features.

0 Kudos
RobBlash
Occasional Contributor III

Hopefully this clears it up more

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

You can get to the geometry and grab the first and last points using python

Geometry—Help | ArcGIS for Desktop 

but again, since I do not work with networks, I'm not sure how this would effect your original data (so always test on a copy).

How Simplify Line works—Help | ArcGIS for Desktop   might be another option.

RobBlash
Occasional Contributor III

Thanks for the suggestions. My python skills are not ready to quickly tackle this issue. If I had 40 hours to play with I'm sure I could make it happen, but that's not the case for this one. Thanks again.

If anyone else has suggestions please let me know. ET GeoTools has a Generalize tool that works about 60% of the time but that still also requires hitting individual features.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Here's one more effort to help.

Since you can't create a new network you may not be able to get away without some manual work, but looking at the network tools avaiable, have you looked at Update by Geometry—Help | ArcGIS for Desktop 

Updates all the edge references in the turn feature class using the geometry of the turn features. This tool is useful when the IDs listed for the turn can no longer find the edges participating in the turn due to edits to the underlying edges

I have no idea whether this will work or not (again, I don't use networks), but reading this I'm thinking if you can get a layer of just the end points, then maybe you can use this to modify the lines.  (again, test on a copy). 

There are many suggestions for getting a new layer of jut the end points.   Have you done a basic browser search on something like "arcgis find endpoints" or "arcgis find nodes" ?  Sometimes that pops up ArcGIS help or geonet, but also Stackexchange. 

qgis - How to retrieve start and end points for each line in line shapefile? - Geographic Informatio... 

has some decent options, including the first suggestion by Richard Fairhurst‌    

I'll back off this thread now....hopefully someone with Network experience will jump in.  I'll tag

https://community.esri.com/community/gis/analysis/network-analyst?sr=search&searchId=4141e295-4e55-4...‌ 

RobBlash
Occasional Contributor III

As an update for anyone interested, I found that the ET GeoTools generalize will work on a line in a geometric network. While it still requires processing individual lines one at a time it is a better solution than manually deleting vertices.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I am not sure if this will work when the layer is part of a network, but below is an example of how a MULTILINESTRING can be collapsed to just the endpoints of the individual LINESTRINGS.  The code will work against a single-part MULTILINESTRING too. 

>>> polyline = arcpy.FromWKT('MULTILINESTRING((0 0, 5 0, 7 0, 7 1, 9 1, 9 3, 9 5),(3 2, 5 2, 6 2, 8 5))')
>>> polyline.WKT
u'MULTILINESTRING ((0 0, 5 0, 7 0, 7 1, 9 1, 9 3, 9 5), (3 2, 5 2, 6 2, 8 5))'
>>> arr = arcpy.Array()
>>> for line in polyline.getPart():
...     arr.add(arcpy.Array([line[0], line[-1]]))
...     
>>> polyline = arcpy.Polyline(arr)
>>> polyline.WKT
u'MULTILINESTRING ((0 0, 9 5), (3 2, 8 5))'‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The following code could be wrapped in an ArcPy Data Access cursor.

0 Kudos
MatthewComartin
New Contributor II

The following Python code would accomplish what you're after:

import arcpy

fc = arcpy.mapping.Layer('C:/Temp/Temp.gdb/myFc')

with arcpy.da.UpdateCursor(fc,["SHAPE@"]) as cursor:
    for row in cursor:
        #loop through parts
        for part in row[0]:
            count = 0
            # loop through verticies
            for pnt in part:
                count = count + 1
                if count >= 3:
                    arr = row[0].getPart(0)
                    arr.remove(1)
                    newLine = arcpy.Polyline(arr)
                    row[0] = newLine
                    cursor.updateRow(row)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Reference: arcpy - Delete middle vertex of multiple 3-vertex polylines - Geographic Information Systems Stack E... 

updatecursor‌arcpy

0 Kudos