2

I am using ArcGIS Desktop 10.8.1 with extensions including Network Analyst.

I have a set of lines (geodatabase feature class), some of which join and some do not. I would like to give each discrete group of connected lines a unique ID to allow statistics on number of lines in the group, total length, etc. Are there any existing tools that will help me do this?

I have a manual workflow using repeated Select By Location that can achieve this but it is time consuming. I could try to script/ModelBuilder the task, but suspect (due to inexperience) this will take me longer than the manual workflow. I have built a Network Dataset based on the lines but am not sure if that helps.

Any suggestions? ArcGIS Pro 3.0 is potentially available if there is a solution that only exists there.

sample of line dataset

3 Answers 3

3

Dissolve your lines with the unsplit lines parameter. Then use a spatial join tool to populate the original lines with the OIDs of the joined features. Any lines that share nodes in the original data will then share a dissolved OID from the joined data and any single line features will have a unique OID from the joined data.

This will work if and only if the groups actually share nodes. You can use topology tool to edit your line work after you identify areas where lines do not share nodes base on your user-defined tolerances.

There is also this tool which might help you get started coding a tool if you are interested in creating a recursive selection tool.

1
  • I believe Unsplit only works where just 2 lines share an endpoint, and here there are many points where several lines meet. Even on groups which happen to have 2 lines I am not seeing an unsplit result, though. Endpoints should be coincident since the lines were generated from a process involving Add XY Coordinates and then XY To Line. So I need to look into that further. Commented Nov 2, 2022 at 10:53
2

An alternative coding approach is to use the python module networkx and pull out the connected components.

import networkx as nx

# Simple shapefile, no MZ values
fc = r"c:\scratch\test2.shp"

#  Reads and returns a directed graph
dG = nx.read_shp(fc,True) 

# Convert to an undirected graph
uG = dG.to_undirected()

# Report number of components
x = nx.number_connected_components(uG)
print("Number of sub-components = " + str(x))

# Get components, this is a list of set objects which contain 
# tuples of XY coordinates of the nodes in the component
connected_components = list(nx.connected_components(uG))

Its then up to you to match the nodes to their edges and pass through to the shapefile a simple count, that being the component number in the list connected_components. An example of this is shown in the answer within a QGIS environment, but note the comments later about precision issues. I'm unsure if this is relevant to ArcGIS Pro as it is using a newer version of networkx (2.7.1).

If you are not comfortable with coding in python then I suspect @GBG approach is best and easier to understand.

1
  • I might come back to this but it is a bit beyond my own capabilities at the moment. Thanks! Commented Nov 2, 2022 at 10:57
0

Some time after posting my question I found this previous one: Unsplit/Dissolve multiple touching lines in Stream Network using ArcGIS Desktop?

That question has an accepted solution that does not involve scripting (based on buffering) and other solutions that use Python. The buffer-based solution works for me although takes a very long time to run; I have not tried the scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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