Finding closed polylines

4719
6
06-18-2012 10:39 AM
RichardPascoe
New Contributor II
Does anyone know how to find closed polylines using only geoprocessing tools (without using Data Reviewer or ArcObjects)?  It seems like I should be able to do this in Python without much hassle, but I can't find a way.  Thanks!
0 Kudos
6 Replies
HardolphWasteneys
Occasional Contributor III
Richard,

try making polygons from them.  If the polylines form closed loops by themselves or by intersection with others they will allow creation of a polygon.

Easy to do in ArcView, no Python etc required.  Here's the simplest case; just ignore step 1.  http://forums.arcgis.com/threads/6786-polyline-to-polygon

Hardolph
0 Kudos
markdenil
Regular Contributor II
failing the simple way, above, you would have to get the vertex array from the geometry object for each line.
itterate through the array (which for a line or polygon is composed of point objects), and compare the first and last points. It they are identical, the line is closed.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Richard,

Here's an example on how to do this using python:

fc = "Boundary"

rows = arcpy.SearchCursor(fc)
for row in rows:
    geom = row.shape
    if geom.firstPoint.X == geom.lastPoint.X:
        print row.OBJECTID

del row, rows


It will compare the X coordinate of the first and last point within each line.  If they are the same the OBJECTID of the line is printed.
0 Kudos
deleted-user-AyQ-Iok8btBJ
New Contributor II

How would I implement this into a field calculator expression? I'm a beginner with python but I could use some help. Basically I'm trying to implement this but rather than print the OID I want to populate a 1 for closed polylines and 0 for open. Thanks. 

0 Kudos
RichardPascoe
New Contributor II
Jake and Mark - This is a great idea!  A polyline can be closed at two points that aren't the first and last, but this gives me a good starting point.  I will post the code once I am finished.  I imagine I will make a set of the coordinates for each feature and see if there are any that appear twice.

Hardolph - This will be a good alternative if the above doesn't work well.  Since I am automating, I want to avoid creating additional features, particularly for large datasets.  However, it is a simple process.  I would just need to create the polygons, join them back to the original features, select by attribute, and delete features.

Many thanks to all of you!
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
If you have ArcInfo license, you can try the two steps:

1. Run Feature To Polygon tool to get polygons from closed lines.
2. Run Select Layer By Location to select polylines by the polygons, with the INTERSECT relationship option (or other suitable options). The resulting selection should contain closed polylines.
0 Kudos