Exemple #1
0
pg_start = time.time()

"""
=======  Now Loop through the shapefiles and write edges to PostGIS  =======
"""
for i in range(1018):

    # Get the path of a network
    edge_path = edge_dir + "Edges" + str(i) + ".shp"
    node_path = node_dir + "Nodes" + str(i) + ".shp"

    # Only read the network if exsists such file
    if os.path.exists(edge_path) and os.path.exists(node_path):
        print(i, "pgRouting writing edges")
        undir_network = shp2nx.read_shp(edge_path, node_path)
        dir_network = undir2dir.convert(undir_network)
        dir_network = undir2dir.encodeDir(dir_network)

        net_id = i

        # now let's write all the edges in PostGIS
        for edge in dir_network.edges():
            startNode = edge[0]
            endNode = edge[1]
            edge_id = dir_network.edge[startNode][endNode]['edgeID']
            edge_type = dir_network.edge[startNode][endNode]['type']
            edge_length = dir_network.edge[startNode][endNode]['length']
            edge_wkt = dir_network.edge[startNode][endNode]['Wkt']
            edge_feeder = dir_network.edge[startNode][endNode]['feeder']
Exemple #2
0
"""
===============================================================================
                     From here is the main programme
===============================================================================
"""

start = time.time()

dbname = "00_NCL_WATER_TEMP_CATCHMENT"
"""
================  First let's read all the data into python =============
"""
edge_path = 'Input/Edges.shp'
node_path = 'Input/Nodes.shp'
mainNet = shp2nx.read_shp(edge_path, node_path)
"""
Read each pipe into PipeList
"""
pipeList = pg_read.readPipe()
print("%d pipes have been read\n" % len(pipeList))
"""
Read each building into buildingList
"""
buildingList = pg_read.readBuilding()
print("%d buildings have been read\n" % len(buildingList))

print("=====================================================")
print("input data reading is completed......................")
print("=====================================================")
print("\n")
import shp2nx
import pickle
import copy
import fiona

G = shp2nx.read_shp('Input/NCL_Sewer_Pipes_Project.shp',
                    'Input/NCL_Sewer_Nodes_Project.shp')

ff = open("sink_nodes", "rb")
sink_nodes = pickle.load(ff)

# Delete edges from G
GCopy = copy.deepcopy(G)

current_sinks = sink_nodes

sum = 0
while (GCopy.number_of_edges() > 0):

    sum += 1
    print("iteration", sum)
    print("GCopy edges", GCopy.number_of_edges())
    print("number of current sinks", len(current_sinks))

    sinks_to_nodes = {}
    sinks_to_edges = {}

    for sink in current_sinks:
        # find immerdiate nodes connecting each sink
        sinks_to_nodes[sink] = GCopy.neighbors(sink)