2019-05-04 10:25:25 +00:00
#!/bin/bash
2019-03-28 17:53:10 +00:00
2021-04-15 21:53:09 +00:00
set -e
set -u
# argument 1 = millesime redadeg
millesime = $1
2019-03-28 17:53:10 +00:00
2019-05-04 10:25:25 +00:00
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo " Création de la couche osm_roads"
echo ""
echo ""
2021-04-15 21:53:09 +00:00
PSQL = /usr/bin/psql
2019-05-04 12:21:36 +00:00
HOST_DB_redadeg = localhost
2020-02-07 13:37:13 +00:00
HOST_DB_osm = localhost
2021-04-15 21:53:09 +00:00
DB_REDADEG = redadeg_$millesime
DB_OSM = osm
DB_USER = redadeg
DB_PASSWD = redadeg
rep_scripts = '/data/projets/ar_redadeg/scripts/'
echo " rep_scripts = $rep_scripts "
# variables liées au millésimes
echo " millesime de travail = $1 "
rep_data = ../data/$millesime
echo " rep_data = $rep_data "
2019-03-28 17:53:10 +00:00
2021-04-15 21:53:09 +00:00
echo ""
2019-05-04 12:21:36 +00:00
echo "import phase_1_trace dans la base OSM"
echo ""
2019-03-28 17:53:10 +00:00
2019-05-04 12:21:36 +00:00
# 1. export du tracé phase 1 depuis la base redadeg
2021-04-15 21:53:09 +00:00
pg_dump --file $rep_data /redadeg_trace.sql --host $HOST_DB_redadeg --username $DB_USER --no-password \
--format= p --no-owner --section= pre-data --section= data --no-privileges --no-tablespaces \
--no-unlogged-table-data --no-comments --table public.phase_1_trace $DB_REDADEG
2019-03-28 17:53:10 +00:00
2019-05-04 12:21:36 +00:00
# 2. import dans la base OSM
2021-04-16 12:16:49 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM -c " DROP TABLE IF EXISTS phase_1_trace_ $millesime ; "
2021-04-15 21:53:09 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM < $rep_data /redadeg_trace.sql
2021-04-16 12:16:49 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM -c " ALTER TABLE phase_1_trace RENAME TO phase_1_trace_ $millesime ; "
2019-03-28 17:53:10 +00:00
2019-05-04 12:21:36 +00:00
echo ""
echo "fait"
echo ""
2019-03-28 17:53:10 +00:00
# 3. calcul de la couche osm_roads = intersection buffer trace et routes OSM
2019-05-09 08:06:54 +00:00
echo ">> calcul de la couche osm_roads"
echo ""
# on supprime puis on recrée la table
2021-04-16 12:16:49 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM -c " DROP TABLE IF EXISTS osm_roads_ $millesime ; "
2021-04-15 21:53:09 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM -c "
2021-04-16 12:16:49 +00:00
CREATE TABLE osm_roads_$millesime
2019-05-09 08:06:54 +00:00
(
2019-05-15 15:11:03 +00:00
uid bigint NOT NULL,
2019-05-09 08:06:54 +00:00
osm_id bigint,
highway text,
type text,
oneway text,
ref text,
name_fr text,
name_br text,
the_geom geometry,
CONSTRAINT osm_roads_pkey PRIMARY KEY ( uid) ,
CONSTRAINT enforce_geotype_the_geom CHECK ( geometrytype( the_geom) = 'LINESTRING' ::text OR geometrytype( the_geom) = 'MULTILINESTRING' ::text) ,
CONSTRAINT enforce_srid_the_geom CHECK ( st_srid( the_geom) = 2154)
) ; "
echo ""
2021-04-16 12:16:49 +00:00
echo " table osm_roads_ $millesime créée "
2019-05-09 08:06:54 +00:00
echo ""
echo " chargement des données"
2019-05-04 12:21:36 +00:00
echo ""
2021-04-15 21:53:09 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_osm -U $DB_USER -d $DB_OSM -c " WITH trace_buffer AS (
2019-03-28 17:53:10 +00:00
SELECT
secteur_id,
ST_Union( ST_Buffer( the_geom, 25, 'quad_segs=2' ) ) AS the_geom
2021-04-16 12:16:49 +00:00
FROM phase_1_trace_$millesime
2019-03-28 17:53:10 +00:00
GROUP BY secteur_id
ORDER BY secteur_id
)
2021-04-16 12:16:49 +00:00
INSERT INTO osm_roads_$millesime
2019-03-28 17:53:10 +00:00
(
SELECT
row_number( ) over( ) as id,
osm_id,
highway,
CASE
WHEN highway IN ( 'motorway' , 'trunk' ) THEN 'motorway'
WHEN highway IN ( 'primary' , 'secondary' ) THEN 'mainroad'
WHEN highway IN ( 'motorway_link' , 'trunk_link' , 'primary_link' , 'secondary_link' , 'tertiary' , 'tertiary_link' , 'residential' , 'unclassified' , 'road' , 'living_street' ) THEN 'minorroad'
WHEN highway IN ( 'service' , 'track' ) THEN 'service'
WHEN highway IN ( 'path' , 'cycleway' , 'footway' , 'pedestrian' , 'steps' , 'bridleway' ) THEN 'noauto'
ELSE 'other'
END AS type,
oneway,
ref,
name AS name_fr,
COALESCE( tags -> 'name:br' ::text) as name_br,
ST_Intersection( ST_Transform( o.way,2154) , t.the_geom) AS the_geom
FROM planet_osm_line o, trace_buffer t
WHERE highway IS NOT NULL AND ST_INTERSECTS( t.the_geom, ST_Transform( o.way,2154) )
) ; "
2019-05-04 12:21:36 +00:00
echo ""
echo "fait"
echo ""
2019-03-28 17:53:10 +00:00
# 4. export de osm_roads depuis la base OSM
2021-04-16 12:16:49 +00:00
echo " transfert de osm_roads_ $millesime depuis la base OSM vers la base redadeg "
2019-05-04 12:21:36 +00:00
echo ""
2019-03-28 17:53:10 +00:00
2021-04-15 21:53:09 +00:00
pg_dump --file $rep_data /osm_roads.sql --host $HOST_DB_osm --username $DB_USER --no-password \
2019-05-09 13:17:06 +00:00
--format= p --no-owner --section= pre-data --section= data --no-privileges --no-tablespaces --no-unlogged-table-data --no-comments \
2021-04-16 12:16:49 +00:00
--table osm_roads_$millesime $DB_OSM
2019-03-28 17:53:10 +00:00
# 5. import dans la base redadeg
2021-04-16 12:16:49 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_redadeg -U $DB_USER -d $DB_REDADEG -c "DROP TABLE IF EXISTS osm_roads;"
2021-04-15 21:53:09 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_redadeg -U $DB_USER -d $DB_REDADEG < $rep_data /osm_roads.sql
2021-04-16 12:16:49 +00:00
PGPASSWORD = $DB_PASSWD $PSQL -h $HOST_DB_redadeg -U $DB_USER -d $DB_REDADEG -c " ALTER TABLE osm_roads_ $millesime RENAME TO osm_roads ; "
2019-03-28 17:53:10 +00:00
2019-05-04 12:21:36 +00:00
echo ""
echo "fait"
echo ""
2019-03-28 17:53:10 +00:00
echo "fini"