There are 3 likely scenerios that I am trying to capture near distances for:
- An interchange subway station, which has 2 or more neighboring stations. That is, the station in question connects 2 or more major routes and has 2 or more neighboring stations.
- A terminal subway station, which has only 1 neighboring station. This is the station at the end of the line.
- An inline subway station, which has exactly 2 neighboring stations, one of either approach.
I am attempting to calculate a value one might call "average distance between neighboring stations"
The arcpy.GenerateNearTable_analysis()
can handle two options: Distance to closest feature, and Distance between all features.
Does anyone have a clever method for solving for these scenarios? Note that each station is designated as "Interchange", "Terminal" or "Inline" in the attribute table under the field "StationType".
Added:
Here is some psuedo code based on @whuber's suggestion in the comments. I don't have time to figure this out just yet, so if anyone wants to take a stab at it you'll be rewarded with a checkmark! ;)
I have taken a look at the NetworkX library and it seems to work as I want it to.
Given the graph:
A —― B ―― C ―― D
|
E
as well as the nodes and links:
Nodes = ["A", "B", "C", "D", "E"]
Links = [("A", "B"), ("B", "C"), ("C", "D"), ("B", "E")]
def myFunction(node):
identify the links that node belongs to
count the number of links
calculate the total link lengths
divide the total link lengths by the number of links
return someValue