Select to view content in your preferred language

# Finding closed polylines

5965
6
06-18-2012 10:39 AM
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!
Tags (3)
6 Replies
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
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.
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.
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.

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!
by
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.