How to view/export the connectivity table list of a network

7834
5
10-24-2011 01:36 AM
Highlighted
New Contributor II
Dear all,

I have a basic street network. For research purpose, I need to access and export (.dbf, .txt,...) the "connectivity table" of my network exactly as shown in the joined screenshot:

Junction / Adjacent junction and edge elements

I'm using ArcGIS 10. Any advice welcome..

Best regards,
Theo

ps. The screeenshot as been taken on http://edndoc.esri.com/arcobjects/8.3/TechnicalDocuments/Network/ArcGISNetworkModel/ArcGISNetwork.ht...
Tags (2)
Reply
0 Kudos
5 Replies
Highlighted
Esri Regular Contributor
You can add a network dataset to ArcMap and run the following code to list out each junction and its adjacent set of edges. Customize it as needed for your needs.
Jay Sandhu

Public Sub List_ND_Junctions()
  Dim pMxDoc As IMxDocument
  Set pMxDoc = ThisDocument
 
  Dim pNLayer As INetworkLayer
  Set pNLayer = pMxDoc.FocusMap.Layer(0)
 
  Dim pND As INetworkDataset
  Set pND = pNLayer.NetworkDataset
 
  Dim pNQ As INetworkQuery
  Set pNQ = pND
   
  Dim pEnumNE As IEnumNetworkElement
  Set pEnumNE = pNQ.Elements(esriNETJunction)
    
  Dim pNE As INetworkElement
  Set pNE = pEnumNE.Next
 
  Dim pNJunc As INetworkJunction
  Set pNJunc = pNE
 
  Dim i As Integer
  Dim j As Integer
  Dim pEdge As INetworkEdge
  Set pEdge = pNQ.CreateNetworkElement(esriNETEdge)
  'Print out junction OID and all it's connected edge OID's
  Debug.Print "JunctionOID  Count       Edge#       OID"
  Do Until pNE Is Nothing
    j = pNJunc.EdgeCount
    Debug.Print pNJunc.OID, j
    For i = 0 To j - 1
      pNJunc.QueryEdge i, False, pEdge
      Debug.Print "                  ", i + 1, pEdge.OID
    Next i
    Set pNE = pEnumNE.Next
  Loop
  
End Sub
Reply
0 Kudos
Highlighted
Occasional Contributor II
This looks like a vb code.

you can also look at near function with a distance of may be 1 cm or so, so that you are not collecting far off edges from the junction. and then use the field separator as "," ; so if node 1 is connected to edge 10, edge 23, & edge 41 you will get a result like 10,23,41 for node 1.

worth a try !

regards,
Reply
0 Kudos
Highlighted
New Contributor III

Hello Theo,

I'm in a situation where I have the exact same need - exporting the connectivity table from a geometric network.  I'm curious how you ended up solving your problem.  Did you go with the VB Code, or a similar python script? Or perhaps there's a newer solution that's come up in the last three years.

Thanks,
Ben

Reply
0 Kudos
Highlighted
New Contributor

Also , I have the same problem . Please if you have some solutions , share it with me . I used the schematic tool , but I got some tables , regarding your images there is only a connectivity table.

Thanks in advance

Diego

Reply
0 Kudos
Highlighted
New Contributor II

Dear all,

Thanks for your answers. In the end I've built a python solution to export adjacency matrix and node list of a network to text files.

It requires the installation of networkX and shapely python packages. Your network has to be a shapefile, and the script was not tested on big graphs.

I have uploaded a zip file containing script, data sample and results hereHope this helps and feel free to comment !

Best regards,

Theo

# Extract adjacency matrix and nodelist from Shapefile with python networkX

#Packages import

import os

import networkx as nx

import shapely

import numpy as np

import re

# Setting the working directory (the network .shp file has to be in this path)

path = r'Q:\gis\NetworkSample'

# Now change the directory

os.chdir( path )

# Check current working directory.

retval = os.getcwd()

print "Directory changed successfully %s" % retval

# Name of the network shapefile

shpFileName = 'SampleNetworkData.shp'

shpFileNameStr=shpFileName.replace(".","_")

# Adjacency matrix export name

AdjMatName="Adj_matrix_dist_"+shpFileNameStr+".txt"

# node list export name

NodeListName="Nodes_of_"+shpFileNameStr+".txt"

#Reading the shp and creating the corresponding graph G

G=nx.read_shp(shpFileName)

#Converting G to an unoriented graph

G=G.to_undirected()

# Print the number of nodes and edges

n=G.number_of_nodes()

e=G.number_of_edges()

print str(G.number_of_nodes()) +" nodes" + " and " +str(G.number_of_edges()) + " edges"

#Change nodes labels by an integer that range from 0 --> n and save the old labels (XY coordinates).

G=nx.convert_node_labels_to_integers(G,label_attribute='XYcoordinates')

# Adjacency Matrix

# Computing adjacency matrix using length as weight

adjMatrix=nx.adjacency_matrix(G,nodelist=None,weight='Shape_Leng')

# Converting CSR matrix format to dense format

DenseAdjMatrix=adjMatrix.todense()

# Exporting adjacency matrix as .txt file

np.savetxt("dense_adjacency_matrix_SampleNetworkData.txt", DenseAdjMatrix, delimiter=',', newline="\n", fmt='%d')

# Nodes attributes

# Exporting the nodes key and coordinates has a file ("nodelist.txt")

with open('nodeslist.txt','w') as file:

        for node in G.nodes_iter(data=True):

        #Identify the node key (integer) and X,Y coordinates (float) and return them in the list 'towrite'

                towrite=re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", str(node))

                #Setting file format (node key,X,Y) and export

                towrite= ','.join(map(str, towrite))

                print>>file, towrite

#End of script