phase 3 : ajustements
ça marche mieux…
This commit is contained in:
parent
e7071c8507
commit
c05d9ba256
|
@ -1,18 +1,18 @@
|
|||
|
||||
[redadeg_database]
|
||||
host=localhost
|
||||
port=55432
|
||||
port=5432
|
||||
db=redadeg
|
||||
user=redadeg
|
||||
passwd=redadeg
|
||||
|
||||
[osm_database]
|
||||
host=localhost
|
||||
port=55432
|
||||
port=5432
|
||||
db=osm
|
||||
user=redadeg
|
||||
passwd=redadeg
|
||||
|
||||
[redadeg]
|
||||
longueur_densification=2
|
||||
longueur_densification=5
|
||||
pk_start=11
|
||||
|
|
|
@ -78,7 +78,7 @@ FROM pgr_drivingDistance('SELECT id, source, target, cost, reverse_cost FROM pha
|
|||
WHERE SOURCE IS NOT NULL AND id > 0',
|
||||
"""+str(start)+""", """+str(distance)+""")
|
||||
)
|
||||
SELECT node, edge FROM t ORDER BY seq DESC LIMIT 1;"""
|
||||
SELECT node, edge, round(agg_cost) FROM t ORDER BY seq DESC LIMIT 1;"""
|
||||
|
||||
#print(sql_routage)
|
||||
|
||||
|
@ -89,9 +89,10 @@ SELECT node, edge FROM t ORDER BY seq DESC LIMIT 1;"""
|
|||
data = cursor.fetchone()
|
||||
node_end = data[0]
|
||||
edge = data[1]
|
||||
distance = data[2]
|
||||
cursor.close()
|
||||
|
||||
return([node_end, edge])
|
||||
return([node_end, edge, distance])
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
|
@ -269,11 +270,12 @@ try:
|
|||
node_zero = secteur_node_start
|
||||
node_zero_data = getPgrNodeInfos(node_zero)
|
||||
|
||||
sql_insert_pks += "INSERT INTO phase_3_pk (secteur_id, pk_id, the_geom, pk_x, pk_y, pk_long, pk_lat) VALUES ("
|
||||
sql_insert_pks += "INSERT INTO phase_3_pk (secteur_id, pk_id, the_geom, pk_x, pk_y, pk_long, pk_lat, length_theorical, length_real) VALUES ("
|
||||
sql_insert_pks += secteur + ", " + str(secteur_pk_start)
|
||||
sql_insert_pks += ",'" + node_zero_data[0] + "'"
|
||||
sql_insert_pks += "," + str(node_zero_data[1]) + "," + str(node_zero_data[2])
|
||||
sql_insert_pks += "," + str(node_zero_data[3]) + "," + str(node_zero_data[4])
|
||||
sql_insert_pks += f",{longueur_decoupage},0"
|
||||
sql_insert_pks += ");\n"
|
||||
|
||||
print(" nœud du PK " + str(secteur_pk_start) + " : " + str(node_zero))
|
||||
|
@ -309,6 +311,7 @@ try:
|
|||
pk_data = getPKfromRouting(node_x , longueur_decoupage)
|
||||
node_x = pk_data[0]
|
||||
previous_pk_edge = pk_data[1]
|
||||
longueur_km_redadeg = pk_data[2]
|
||||
longueur_parcourue = getLongueurParcourue(node_zero,node_x)
|
||||
longueur_restante = secteur_longueur - longueur_parcourue
|
||||
|
||||
|
@ -327,11 +330,12 @@ try:
|
|||
node_x_data = getPgrNodeInfos(node_x)
|
||||
|
||||
# on fait une requête SQL d'insert de ce PK
|
||||
sql_insert_pks += "INSERT INTO phase_3_pk (secteur_id, pk_id, the_geom, pk_x, pk_y, pk_long, pk_lat) VALUES ("
|
||||
sql_insert_pks += "INSERT INTO phase_3_pk (secteur_id, pk_id, the_geom, pk_x, pk_y, pk_long, pk_lat, length_theorical, length_real) VALUES ("
|
||||
sql_insert_pks += secteur + "," + str(pk_id)
|
||||
sql_insert_pks += ",'" + node_x_data[0] + "'"
|
||||
sql_insert_pks += "," + str(node_x_data[1]) + "," + str(node_x_data[2])
|
||||
sql_insert_pks += "," + str(node_x_data[3]) + "," + str(node_x_data[4])
|
||||
sql_insert_pks += f",{longueur_decoupage},{longueur_km_redadeg}"
|
||||
sql_insert_pks += ");\n"
|
||||
|
||||
# on met en négatif l'info de routage du précédent tronçon afin de l'écarter du prochain calcul de routage
|
||||
|
|
|
@ -191,7 +191,7 @@ WHERE n*"""+longueur_densification+"""/length < 1;"""
|
|||
print("")
|
||||
|
||||
|
||||
print(" Optimisations...")
|
||||
print(" Calcul des coûts...")
|
||||
|
||||
# calcul des attributs de support du calcul pour PGR
|
||||
sql_update_costs = """
|
||||
|
@ -211,22 +211,39 @@ WHERE secteur_id = """ + secteur + """ ;"""
|
|||
|
||||
db_redadeg_cursor.execute(sql_update_costs)
|
||||
|
||||
# optimisation
|
||||
db_redadeg_cursor.execute("VACUUM FULL phase_3_troncons_pgr ;")
|
||||
|
||||
print(" fait")
|
||||
print("")
|
||||
|
||||
|
||||
# ------------------------------------------------------
|
||||
print(" Création / maj de la topologie pgRouting pour les tronçons nouvellement créés")
|
||||
|
||||
sql_create_pgr_topology = "SELECT pgr_createTopology('phase_3_troncons_pgr', 0.001, rows_where:='true', clean:=true);"
|
||||
|
||||
sql_nb_edges = f"SELECT count(*) FROM phase_3_troncons_pgr WHERE secteur_id = {secteur} ;"
|
||||
db_redadeg_cursor.execute(sql_nb_edges)
|
||||
nb_edges = db_redadeg_cursor.fetchone()[0]
|
||||
|
||||
# estimation du temps de traitement avec 400 edges / s
|
||||
temps_sec = round(nb_edges/400)
|
||||
minutes, seconds = divmod(temps_sec, 60)
|
||||
print(f" temps de traitement évalué à {minutes} min et {seconds} sec")
|
||||
now = datetime.datetime.now()
|
||||
fin_sec = now.second + seconds
|
||||
fin_min = now.minute + minutes + 1
|
||||
fin_heure = now.hour
|
||||
print(f" donc fin estimée à {fin_heure}h{fin_min} maximum")
|
||||
|
||||
|
||||
sql_create_pgr_topology = f"SELECT pgr_createTopology('phase_3_troncons_pgr', 0.001, rows_where:='secteur_id={secteur}', clean:=true);"
|
||||
db_redadeg_cursor.execute(sql_create_pgr_topology)
|
||||
|
||||
print(" fait")
|
||||
print("")
|
||||
|
||||
# optimisation
|
||||
print(" vacuum")
|
||||
db_redadeg_cursor.execute("VACUUM FULL phase_3_troncons_pgr ;")
|
||||
print(" fait")
|
||||
print("")
|
||||
|
||||
# ------------------------------------------------------
|
||||
print(" Récupération id des nœuds de début et fin du secteur, et la longueur")
|
||||
|
|
|
@ -462,7 +462,7 @@ ALTER TABLE phase_2_trace_trous OWNER to redadeg;
|
|||
DROP TABLE IF EXISTS phase_2_trace_troncons CASCADE ;
|
||||
CREATE TABLE phase_2_trace_troncons
|
||||
(
|
||||
uid bigint,
|
||||
uid serial,
|
||||
secteur_id int,
|
||||
ordre bigint,
|
||||
km bigint,
|
||||
|
@ -640,14 +640,14 @@ ALTER TABLE phase_3_trace_secteurs_4326 OWNER TO redadeg;
|
|||
|
||||
-- la couche des PK calculés automatiquement
|
||||
DROP TABLE IF EXISTS phase_3_pk CASCADE ;
|
||||
CREATE TABLE phase_3_pk_auto
|
||||
CREATE TABLE phase_3_pk
|
||||
(
|
||||
pk_id integer,
|
||||
pk_x numeric(8,1),
|
||||
pk_y numeric(8,1),
|
||||
pk_long numeric(10,8),
|
||||
pk_lat numeric(10,8),
|
||||
length_real numeric(6,2),
|
||||
length_real integer,
|
||||
length_theorical integer,
|
||||
secteur_id integer,
|
||||
municipality_admincode text,
|
||||
|
|
|
@ -125,7 +125,7 @@ SELECT pgr_createTopology('phase_3_troncons_pgr', 0.001, rows_where:='true', cle
|
|||
|
||||
|
||||
|
||||
|
||||
-------------
|
||||
|
||||
|
||||
SELECT *
|
||||
|
@ -133,3 +133,17 @@ FROM pgr_drivingDistance(
|
|||
'SELECT id, source, target, cost, reverse_cost FROM phase_3_troncons_pgr WHERE SOURCE IS NOT NULL',
|
||||
107, 300);
|
||||
|
||||
|
||||
|
||||
|
||||
-- RAZ de la topologie pgRouting
|
||||
TRUNCATE TABLE phase_3_troncons_pgr;
|
||||
ALTER SEQUENCE phase_3_troncons_pgr_id_seq RESTART WITH 1;
|
||||
VACUUM phase_3_troncons_pgr;
|
||||
|
||||
TRUNCATE TABLE phase_3_troncons_pgr_vertices_pgr;
|
||||
ALTER SEQUENCE phase_3_troncons_pgr_vertices_pgr_id_seq RESTART WITH 1;
|
||||
VACUUM phase_3_troncons_pgr_vertices_pgr;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue