Snapping Endpoints Only

1435
3
05-24-2011 01:59 PM
JenniferBaughman
New Contributor II
Hi, all.

I've been trying to figure out how to snap only the endpoints in a polyline layer to the edges of a polygon layer using arcpy (Arc10), and I and my team members are stumped. The sheer number of lines we have to snap makes doing them manually unpalatable, at best. As-is, the snap tool snaps interior vertices on polylines as well as the endpoints, distorting the lines -- again, trying to catch these manually is a problem. We were able to do this in 9.3 using the BulkSnap tool that someone kindly wrote and made available, but it doesn't work correctly in 10.

Any suggestions would be appreciated.

Thank you,

Jennifer
Tags (2)
0 Kudos
3 Replies
DarrenWiens2
MVP Honored Contributor
I haven't tested this at all, but it seems like you should be able to use Feature Vertices to Points, specifying you want both ends only. Then, Snap those endpoints to the polygons. Finally, snap your lines to those end points.

The problem may come if you have several line vertices (the 2nd, 3rd, and so on) still within the snap tolerance that you don't want to be snapped to the moved end points. I'm not sure if they will all be condensed into the newly moved end points or not.

A more involved python coding solution is to rip apart the entire geometry of every line, cycle though each vertex, decide if the first and last vertex are within a distance to any of the moved endpoints, then make the x and y coords of those vertices match the closest moved endpoint. Yikes.
KevinBell
Occasional Contributor III
arcpy searchcursor's will give access to the SHAPE.firstpoint/lastpoint, so if you're programmatically building lines look at using something like:

for row in arcpy.searchcursor(myLines):
    print row.SHAPE.firstpoint

or rather than printing store in a variable for latter use during the line build...
0 Kudos
ChrisSnyder
Regular Contributor III
How about this:

1. Use the FeatureToVertices tool to output just the endpoints

2. Use the GenerateNearTable tool to then, for each endpoint, get the nearest polygon. Note in the output table gives you the nearest XY coordinate of the polygon relative to the endpoint.

3. You now have the xy coordinates of the endpoint (you can get these from the output of the FeatureToVertices tool) and you also have the xy coordinates (somewhere along the edge) to the closest polygon. Use the common OBJECTID to associate the endpoint records to the near table records.

4. Now using a cursor, either update (using and update cursor) the existing line segment so as to insert a new vertex for each line - the new vertex being the xy coordinate along the polygon. Or use an insert cursor to write a new line segment that bridges the gap between the endpoint and the polygon edge. You could right the OBJECTID as well, to facilitate dissolving the new line into the existing one.  I actually have some sample code for the �??connector arc�?� method: http://forums.arcgis.com/threads/28194-How-to-change-the-geometry-of-a-line-(lastpoint-amp-startpoin...
0 Kudos