Confluence Retirement

In an effort to consolidate USGS hosted Wikis, myUSGS’ Confluence service is scheduled for retirement on January 27th, 2023. The official USGS Wiki and collaboration space is now SharePoint. Please migrate existing spaces and content to the SharePoint platform and remove it from Confluence at your earliest convenience. If you need any additional information or have any concerns about this change, please contact Thank you for your prompt attention to this matter.
Skip to end of metadata
Go to start of metadata

By matching the location of the downstream-most point in one line with the upstream-most point another line other line, we find the downstream feature. This presumes that the vertices that comprise the feature are oriented in a downstream direction and that the feature is geometrically attached to the rest of the network. There is no assumption of formal ESRI topology or network characteristics.

The current method dumps out all features at once and then simplifies. This approach is not likely to scale. Lines 8-22 could be refactored to function on a per feature basis. I tried using a arcpy.da.SearchCursor() with the explode_to_points=True, but this only produced  a single coordinate pair per feature (seems like this isn't actually implemented at the moment (10.3.1)). 

import arcpy
import numpy as np

arcpy.env.workspace = 'c:/workspace/wk_routing/test.gdb'
arcpy.MakeFeatureLayer_management('nhdflowline', 'flTV')

# extract full set of vertices in each segment
flds =['COMID', 'SHAPE@X','SHAPE@Y']
fl = arcpy.da.FeatureClassToNumPyArray('flTV', flds, explode_to_points=True)

# reduce geometry to just up and down-stream vertices
fromToList = []
for id in set(fl['COMID'].tolist()):
    startPt = list(fl[:, fl['COMID'] == id][['SHAPE@X', 'SHAPE@Y']][0])
    endPt = list(fl[:, fl['COMID'] == id][['SHAPE@X', 'SHAPE@Y']][-1])
    fromToList.append(tuple([id] + startPt + endPt + [0]))
dt = np.dtype([('COMID', '<i4'),
               ('from@X', '<f8'), ('from@Y', '<f8'),
               ('to@X', '<f8'), ('to@Y', '<f8'),
               ('downId', '<i4')])
fromTo = np.array(fromToList, dtype=dt)

# determine identity of downstream segment
for l in fromTo:
    toX = l[3]
    toY = l[4]
    id = l[0]
        downId = fromTo[(fromTo['from@X'] == toX) &
                        (fromTo['from@Y'] == toY)][0][0]
        fromTo['downId'][fromTo['COMID'] == id] = downId
print fromTo[['COMID', 'downId']]



Results of algorithm:

[(1862012, 1868004)

(1862004, 0)

(1862002, 1868004)

(1861860, 1862002)
(1868004, 1862004)]



  • No labels