Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a polygon layer of water reservoirs and a polyline layer of canals.

In my data, some canals are originating from reservoirs, and leading to other canals. On the other hand there are some canals that are isolated or not connected to anything. (How this came about is story for another day)

I need to delete the isolated canals and those canal networks(i.e. connected set of canals) that are not connected to a reservoir.

I assume that i will have to use some kind of network tracing, but I am not sure where to start.

I have ArcGIS desktop, along with Network Analyst to solve this task.

How would you go about this task?

share|improve this question

I'm not sure exactly what your canal shapefile looks like, but here's how I would do that without using Network Analyst:

In the likely case that your Canals.shp polylines are split into separate but connected segments, use Dissolve to unsplit them. Then run Select by Location, finding features in Canals.shp that INTERSECT or BOUNDARY_TOUCHES with Reservoirs.shp.

share|improve this answer
unfortunately, there is no field that is useful enough to run the Dissolve Tool – Devdatta Tengshe Nov 4 '11 at 14:19
then create a new field (short int) and dissolve on it's default (0) – Brad Nesom Nov 4 '11 at 14:34

I would approach this as two separate problems. First, the individual line segments must be dissolved into connected components; just dissolving all of them on a default value won't work. This is a graph theory problem, and what we want are the "connected component sub graphs".

I'm sure there's a way to hack this with network analyst, but my preference would be to treat it like the graph problem it is; don't reinvent the wheel, just install the excellent Networkx python module and try the following:

from networkx import Graph, connected_components
G = Graph()
# iterate through your feature class and build a graph
for row in featureclass:
    # we need a unique representation for each edges start and end points
    start = row.shape.getpart()[0]
    end = row.shape.getpart()[-1]

# get the connected components
Components = connected_components(G)

# we now have a "list of lists" containing edges grouped by their component
# there's several ways to apply this to the feature
for i, connected in enumerate(Components):
    # assign id = i to the group by writing it to a field for all members 
    # of that component (the row oid is an attribute of the edge)

Second step would be the dissolve and select by location as suggested by dmahr

I've used a similar technique many times successfully. Graph theory is awesome and solves many GIS problems, and Networkx is a great tool to implement this in python.

share|improve this answer
thanks. I'll try it at work on Tuesday! – Devdatta Tengshe Nov 6 '11 at 15:48
Couldn't have said it better. +1 – Allan Adair Nov 7 '11 at 9:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.