From 4c50956dcebc53cb061ceb417e6ec287eb807cd8 Mon Sep 17 00:00:00 2001 From: MaelReboux Date: Sat, 4 May 2019 12:19:32 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20couches=20de=20rou?= =?UTF-8?q?tage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/routing.sql | 9 +++++ scripts/update_osm_roads_pgr.sh | 32 ++++++++++++++++++ scripts/update_osm_roads_pgr.sql | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100755 scripts/update_osm_roads_pgr.sh create mode 100755 scripts/update_osm_roads_pgr.sql diff --git a/scripts/routing.sql b/scripts/routing.sql index 371a419..2a16b0e 100644 --- a/scripts/routing.sql +++ b/scripts/routing.sql @@ -115,5 +115,14 @@ ON a.edge = b.id -- si besoin : nettoyage par Drop du schéma SELECT topology.DropTopology('osm_roads_topo'); +-- permissions +ALTER SCHEMA osm_roads_topo OWNER TO redadeg ; +ALTER TABLE osm_roads_topo.edge_data OWNER TO redadeg ; +ALTER TABLE osm_roads_topo.face OWNER TO redadeg ; +ALTER TABLE osm_roads_topo.node OWNER TO redadeg ; +ALTER TABLE osm_roads_topo.relation OWNER TO redadeg ; +ALTER VIEW osm_roads_topo.edge OWNER TO redadeg ; +ALTER SEQUENCE osm_roads_topo.layer_id_seq OWNER TO redadeg ; +ALTER SEQUENCE osm_roads_topo.topogeo_s_1 OWNER TO redadeg ; diff --git a/scripts/update_osm_roads_pgr.sh b/scripts/update_osm_roads_pgr.sh new file mode 100755 index 0000000..b40638f --- /dev/null +++ b/scripts/update_osm_roads_pgr.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e +set -u + +PSQL=/usr/bin/psql +DB_HOST=localhost +DB_NAME=redadeg +DB_USER=redadeg + + +cd /data/www/vhosts/ar-redadeg_openstreetmap_bzh/htdocs/scripts/ + + +echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" +echo " Mise à jour des couches de routage" +echo "" +echo " prend environ 5 min" +echo "" + +# cette couche vient d'une base osm donc il faut la recharger +$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME -c "TRUNCATE TABLE public.osm_roads;" +$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME < data/osm_roads.sql + + +# maj de la topologie de la couche osm_roads_pgr qui sert au routage +$PSQL -h $DB_HOST -U $DB_USER -d $DB_NAME < update_osm_roads_pgr.sql + +echo "fini" +echo "" + + diff --git a/scripts/update_osm_roads_pgr.sql b/scripts/update_osm_roads_pgr.sql new file mode 100755 index 0000000..dd21282 --- /dev/null +++ b/scripts/update_osm_roads_pgr.sql @@ -0,0 +1,58 @@ +/* +========================================================================== + + phase 2 : Mise à jour des couches de routage + +========================================================================== +*/ + +-- /!\ +-- cela suppose que la couche osm_roads est à jour !! +-- or cette couche est calculée à partir d'une BD osm cf la documentation + + +-- maj de la topologie de la couche osm_roads_pgr qui sert au routage +-- 3 min +UPDATE osm_roads SET topo_geom = topology.toTopoGeom(the_geom, 'osm_roads_topo', 1, 0.00001); + + +-- maj de la couche support des calculs d'itinéraire +-- 30 s +TRUNCATE TABLE osm_roads_pgr ; +INSERT INTO osm_roads_pgr +( SELECT + row_number() over() as id, + o.osm_id, + o.highway, + o.type, + o.oneway, + o.ref, + o.name_fr, + o.name_br, + NULL as source, + NULL as target, + NULL as cost, + NULL as reverse_cost, + e.geom as the_geom +FROM osm_roads_topo.edge e, + osm_roads_topo.relation rel, + osm_roads o +WHERE e.edge_id = rel.element_id + AND rel.topogeo_id = (o.topo_geom).id +); + +-- calcul des 2 attributs de coût (= longueur) +UPDATE osm_roads_pgr SET cost = st_length(the_geom); +UPDATE osm_roads_pgr SET reverse_cost = st_length(the_geom); + + +-- calcul du graphe routier par pgRouting +-- 30 s +SELECT pgr_createTopology('osm_roads_pgr', 1.0); + +-- vérification +SELECT pgr_analyzegraph('osm_roads_pgr', 1.0); +SELECT pgr_nodeNetwork('osm_roads_pgr', 1.0); + + +