I think the best way to do this is in arcpy. The following is a complete script that will do what you need. It works by putting a small buffer around all of the stream features and indexing them(adds a field that is used later in the script to dissolve). The buffer allows for every part of a network, whether it is connected or not, to be considered part of it by using the buffer distance as a "tolerance". So... if the networks are really close together you can set the buffer distance lower.
import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
inFC = arcpy.GetParameterAsText(0)
outLoc = arcpy.GetParameterAsText(1)
outName = arcpy.GetParameterAsText(2)
newFC = os.path.join(outLoc, outName)
def buildWhereClause(table, field, value):
fieldDelimited = arcpy.AddFieldDelimiters(table, field)
fieldType = arcpy.ListFields(table, field)[0].type
if str(fieldType) == 'String':
value = "'%s'" % value
whereClause = "%s = %s" % (fieldDelimited, value)
return whereClause
bufferClass = os.path.join(outLoc, outName + "_Buffer")
singleClass = os.path.join(outLoc, outName + "_singlePart")
arcpy.Buffer_analysis(inFC, bufferClass, 500, "", "", "ALL")
arcpy.MultipartToSinglepart_management(bufferClass, singleClass)
arcpy.AddField_management(singleClass, "INDEX_ID", "LONG")
fields = arcpy.ListFields(singleClass)
fieldList = []
for nm in fields:
fieldList.append(nm.name)
for field in fieldList:
if field == "INDEX_ID":
fieldCounter = 1
with arcpy.da.UpdateCursor(singleClass, field) as cursor:
for row in cursor:
row[0] = fieldCounter
cursor.updateRow(row)
fieldCounter += 1
del cursor
del row
arcpy.CreateFeatureclass_management(outLoc, outName + "_Final", "POLYLINE")
finalFC = os.path.join(outLoc, outName + "_Final")
try:
arcpy.AddField_management(finalFC, "ID_Match", "LONG")
except:
pass
tempFC = os.path.join(outLoc, "tempFC_SE")
tempFC_2 = os.path.join(outLoc, "tempFC_SE_2")
arcpy.AddField_management(inFC, "ID_Match", "LONG")
fieldMatch = ["INDEX_ID", "OBJECTID"]
inFCMatch = ["ID_Match"]
arcpy.MakeFeatureLayer_management(singleClass, "singleClass_lyr")
arcpy.MakeFeatureLayer_management(inFC, "inFC_lyr")
with arcpy.da.SearchCursor("singleClass_lyr", fieldMatch) as cursor:
for row in cursor:
arcpy.SelectLayerByAttribute_management("singleClass_lyr", "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("inFC_lyr", "CLEAR_SELECTION")
where = buildWhereClause(singleClass, "OBJECTID", str(row[1]))
arcpy.SelectLayerByAttribute_management("singleClass_lyr", "NEW_SELECTION", where)
arcpy.CopyFeatures_management("singleClass_lyr", tempFC_2)
arcpy.SelectLayerByLocation_management("inFC_lyr", "INTERSECT", tempFC_2)
arcpy.CopyFeatures_management("inFC_lyr", tempFC)
with arcpy.da.UpdateCursor(tempFC, inFCMatch) as cursor2:
for row2 in cursor2:
row2[0] = row[0]
cursor2.updateRow(row2)
del cursor2
del row2
arcpy.Append_management(tempFC, finalFC, "NO_TEST")
arcpy.Delete_management(tempFC)
arcpy.Delete_management(tempFC_2)
del cursor
del row
arcpy.Dissolve_management(finalFC, newFC, "ID_Match")
arcpy.Delete_management(finalFC)
arcpy.Delete_management(bufferClass)
arcpy.Delete_management(singleClass)
The results will not preserve fields from the original FC but with a little tweaking that is also possible.