Select to view content in your preferred language

Using Python in ArcGIS 10, create a line between the middle of the lines

3987
2
Jump to solution
02-22-2012 04:06 AM
Alper_Sen
Emerging Contributor
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 network (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 information.

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.
[ATTACH=CONFIG]12116[/ATTACH]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Here is an example on how to do this:

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") arcpy.AddXY_management("vertices") 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]     array.add(point)  polyline = arcpy.Polyline(array)      array.removeAll() arcpy.Delete_management("vertices") arcpy.CopyFeatures_management(polyline, fc2)


This will create a polyline feature class using the midpoint vertices of each River segment.  It starts from the lowest mid-point and ends at the highest.

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Here is an example on how to do this:

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") arcpy.AddXY_management("vertices") 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]     array.add(point)  polyline = arcpy.Polyline(array)      array.removeAll() arcpy.Delete_management("vertices") arcpy.CopyFeatures_management(polyline, fc2)


This will create a polyline feature class using the midpoint vertices of each River segment.  It starts from the lowest mid-point and ends at the highest.
0 Kudos
Alper_Sen
Emerging Contributor
Thank you very much for the answer.

The points are not in true sequence in the table. Therefore, I add a code part about "select layer by attribute and location management" and use intersections between the rivers to draw lines combining the midpoints of the intersected lines.

But still there is an overwrite problem!  Following code copies features by overwriting action. How can i add new features to one feature class or to namely different feature classes and prevent overwriting.

import arcpy
from arcpy import env
env.workspace = r"D:\pomme de terre 2\pomme de terre2.gdb"
env.overwriteOutput = 1

fc1 = "Flowline24k_sl_u2"
fc2 = "Graph"


for a in range(1,6):

        obj = "ID_1=%d" % (a)
        
        arcpy.SelectLayerByAttribute_management (fc1,"NEW_SELECTION",obj)      
        arcpy.SelectLayerByLocation_management(fc1,"INTERSECT",fc1)
        arcpy.CopyFeatures_management(fc1,"hidden")
        arcpy.SelectLayerByAttribute_management (fc1,"CLEAR_SELECTION")

        coordList = []

        arcpy.FeatureVerticesToPoints_management("hidden", "vertices", "MID")
        arcpy.AddXY_management("vertices")
        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]
            array.add(point)

        polyline = arcpy.Polyline(array)           
        array.removeAll()

        arcpy.Delete_management("vertices")
        arcpy.Delete_management("hidden")
        arcpy.CopyFeatures_management(polyline, fc2)
0 Kudos