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
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
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