# Using Python in ArcGIS 10, create a line between the middle of the polylines which are intersected

I have got a river network as a feature class in a gdb.

I need to calculate the topologic attributes via the connectivity graph of the river network. A graph-theoretic representation of river networks uses rivers as vertices and river junctions as links of a connectivity graph to understand the topology of river networks (takes rivers as nodes and river intersections as links of a connectivity graph). It will give information about centrality of lines and also simplify the network.

In order to do this, I want to draw lines from the middle of each river branch to the middle of intersected higher order river. By this way, I can calculate the topological centrality of a river branch by using from-to node.

When doing this manually, I draw a polyline from the middle of a river line to the middle of intersected higher order river line. Please help me to do this automatically by using Python in ArcGIS 10. If I do it manually it will take too long because of the drainage density.

-
You'll have to elaborate a bit more - I don't really understand. You want to draw lines between the middle of each river branch which is interesected with what? Are you saying you want to simplify the network? –  Stev_k Feb 22 '12 at 11:56
Inserting a sample graphic representation of what you are after would help explain your needs, and help others come up with good suggestions greatly. –  RyanDalton Feb 22 '12 at 15:32
This is pretty straightforward, except that I do not understand what you mean by "the middle of a river line" and "the middle of intersected higher order river line". Defining these two end points will be the most difficult part. Creating the polyline once you have these coordinates is easy. –  blord-castillo Feb 22 '12 at 16:03
I could not add a figure because I am a new user. I do not know how to add in other way. I want to show lines as nodes (junctions) and intersections as edges (links) in the network. For this you can use middle point of line representing a line as point (node) but it is not necessary. –  syd Feb 22 '12 at 17:02
@syd, if you post a link to a graphic you store online, someone will gladly add it into the question for you. –  RyanDalton Feb 23 '12 at 0:14

Here are steps to create centerlines from polygons. Mr. Huber posted this in 2002 on the old ESRI forum. You may need to first densify the river verticies.

1. Convert the polygons to their vertices. Retain the polygon ids.

2. Compute the Thiessen polygon tessellation for the vertices.

3. Convert the Thiessen polygons to a collection of line segments forming their edges.

4. Retain only those segments that lie entirely within some original polygon. Associate the containing polygon's id with each segment.

5. Spatially merge those segments based on polygon id.

6. (Optional) Spline the merged segments.

Incidentally, what is being approximated here is the "medial axis transform" of each polygon, sometimes known informally as its "skeleton." Search http://www.google.com for more information. (I haven't found any practicable algorithms for the MAT on the Web, though.)

-

Have you looked at RivEX this can generate all sorts of analysis and store topological information as tables.

-

``````import arcpy
from arcpy import env
env.workspace = r"C:\TEMP\Python\test.gdb"
env.overwriteOutput = 1

fc1 = "River"
fc2 = "New_Poyline"

coordList = []

arcpy.FeatureVerticesToPoints_management(fc1, "vertices", "MID")
rows = arcpy.SearchCursor("vertices")
for row in rows:
X = row.getValue("POINT_X")
Y = row.getValue("POINT_Y")
coordList.append([X, Y])

del row, rows

coordList.sort()

point = arcpy.Point()
array = arcpy.Array()

for feature in coordList:
point.X = feature[0]
point.Y = feature[1]

polyline = arcpy.Polyline(array)

array.removeAll()
arcpy.Delete_management("vertices")
arcpy.CopyFeatures_management(polyline, fc2)
``````
-