traitements phase 1
This commit is contained in:
parent
063c8cc950
commit
9145b17e9e
97
scripts_v2/phase_1.sh
Executable file
97
scripts_v2/phase_1.sh
Executable file
|
@ -0,0 +1,97 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# exit dès que qqch se passe mal
|
||||||
|
set -e
|
||||||
|
# sortir si "unbound variable"
|
||||||
|
#set -u
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "Pas de millésime en argument --> stop"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# lecture du fichier de configuration
|
||||||
|
. config.sh
|
||||||
|
|
||||||
|
|
||||||
|
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||||
|
echo " Récupération des fichiers geojson depuis umap"
|
||||||
|
|
||||||
|
# traitement des tracés manuels
|
||||||
|
|
||||||
|
# on commence par supprimer la table
|
||||||
|
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "DROP TABLE IF EXISTS phase_1_trace_3857 CASCADE;"
|
||||||
|
# PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "DROP TABLE IF EXISTS phase_1_pk_vip_3857;"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
# on va lire le fichier de config des couches umap pour boucler
|
||||||
|
IFS="="
|
||||||
|
while read -r line
|
||||||
|
do
|
||||||
|
layer=$line
|
||||||
|
|
||||||
|
echo " umap layer id = $layer"
|
||||||
|
wget -q -O $rep_data/phase_1_umap_trace_$layer.geojson https://umap.openstreetmap.fr/fr/datalayer/$layer
|
||||||
|
echo " recup ok"
|
||||||
|
|
||||||
|
# on charge dans postgis
|
||||||
|
# note : les coordonnées sont en 3857 mais la déclaration de la table = 4326
|
||||||
|
|
||||||
|
echo " chargement dans la couche d'import"
|
||||||
|
ogr2ogr -f "PostgreSQL" PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" \
|
||||||
|
$rep_data/phase_1_umap_trace_$layer.geojson -nln phase_1_trace_3857 -lco GEOMETRY_NAME=the_geom -explodecollections
|
||||||
|
echo " fait"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
# fin de la boucle de lecture des layers umap
|
||||||
|
done < $rep_data/umap_phase_1_layers.txt
|
||||||
|
|
||||||
|
|
||||||
|
# PK VIP
|
||||||
|
# plus besoin en 2021
|
||||||
|
#ogr2ogr -f "PostgreSQL" PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" data/phase_1_umap_pk_vip.geojson -nln phase_1_pk_vip_3857 -lco GEOMETRY_NAME=the_geom -explodecollections -overwrite
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||||
|
echo " Application des traitements SQL "
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# on crée les tables en 3948
|
||||||
|
PGPASSWORD=$DB_PASSWD $PSQL -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME < sql/phase_1_trace.sql
|
||||||
|
|
||||||
|
echo " fait"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||||
|
echo " Exports "
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " exports geojson"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# et on exporte vers Geojson
|
||||||
|
rm -f $rep_data/phase_1_pk_auto.geojson
|
||||||
|
ogr2ogr -f "GeoJSON" $rep_data/phase_1_pk_auto.geojson PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" phase_1_pk_auto_4326
|
||||||
|
rm -f $rep_data/phase_1_trace_4326.geojson
|
||||||
|
ogr2ogr -f "GeoJSON" $rep_data/phase_1_trace_4326.geojson PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" phase_1_trace_4326
|
||||||
|
# les fichiers sont ensuite tout de suite visible dans umap
|
||||||
|
|
||||||
|
# exports supplémentaires
|
||||||
|
rm -f $rep_data/phase_1_pk_auto.xlsx
|
||||||
|
ogr2ogr -f "XLSX" $rep_data/phase_1_pk_auto.xlsx PG:"host=$DB_HOST user=$DB_USER password=$DB_PASSWD dbname=$DB_NAME" phase_1_pk_auto_4326
|
||||||
|
|
||||||
|
echo " fait"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||||
|
echo " F I N traitements phase 1"
|
||||||
|
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||||
|
echo ""
|
73
scripts_v2/sql/phase_1_trace.sql
Normal file
73
scripts_v2/sql/phase_1_trace.sql
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
|
||||||
|
|
||||||
|
TRUNCATE phase_1_trace ;
|
||||||
|
INSERT INTO phase_1_trace
|
||||||
|
SELECT
|
||||||
|
ogc_fid,
|
||||||
|
secteur_id::int,
|
||||||
|
ordre::int,
|
||||||
|
0 AS longueur,
|
||||||
|
ST_Transform(the_geom,2154) AS the_geom
|
||||||
|
FROM phase_1_trace_3857
|
||||||
|
WHERE ST_LENGTH(the_geom) > 0
|
||||||
|
ORDER BY secteur_id ASC, ordre ASC ;
|
||||||
|
|
||||||
|
-- mise à jour de la longueur 1 fois la géométrie passée en CC48
|
||||||
|
UPDATE phase_1_trace
|
||||||
|
SET longueur = TRUNC( ST_Length(the_geom)::numeric / 1000 , 2) ;
|
||||||
|
|
||||||
|
|
||||||
|
-- on remplit la table trace 4326 pour exporter vers umap
|
||||||
|
TRUNCATE phase_1_trace_4326 ;
|
||||||
|
INSERT INTO phase_1_trace_4326
|
||||||
|
SELECT
|
||||||
|
t.ogc_fid,
|
||||||
|
s.nom_br AS name,
|
||||||
|
t.secteur_id::int,
|
||||||
|
t.ordre::int,
|
||||||
|
t.longueur,
|
||||||
|
ST_Transform(t.the_geom,4326) AS the_geom
|
||||||
|
FROM phase_1_trace t JOIN secteur s ON t.secteur_id = s.id
|
||||||
|
ORDER BY secteur_id ASC, ordre ASC ;
|
||||||
|
|
||||||
|
|
||||||
|
TRUNCATE phase_1_trace_troncons ;
|
||||||
|
INSERT INTO phase_1_trace_troncons
|
||||||
|
SELECT
|
||||||
|
row_number() over() as uid,
|
||||||
|
secteur_id,
|
||||||
|
ordre,
|
||||||
|
NULL AS km,
|
||||||
|
NULL AS km_reel,
|
||||||
|
NULL AS longueur,
|
||||||
|
ST_LineSubstring(the_geom, 1000.00*n/length,
|
||||||
|
CASE
|
||||||
|
WHEN 1000.00*(n+1) < length THEN 1000.00*(n+1)/length
|
||||||
|
ELSE 1
|
||||||
|
END) AS the_geom
|
||||||
|
FROM
|
||||||
|
(SELECT
|
||||||
|
ogc_fid,
|
||||||
|
secteur_id,
|
||||||
|
ordre,
|
||||||
|
ST_LineMerge(the_geom)::geometry(LineString,2154) AS the_geom,
|
||||||
|
ST_Length(the_geom) As length
|
||||||
|
FROM phase_1_trace
|
||||||
|
-- ce tri est le plus important
|
||||||
|
ORDER BY secteur_id ASC, ordre ASC
|
||||||
|
) AS t
|
||||||
|
CROSS JOIN generate_series(0,10000) AS n
|
||||||
|
WHERE n*1000.00/length < 1
|
||||||
|
ORDER BY t.secteur_id ASC, t.ordre ASC ;
|
||||||
|
|
||||||
|
-- mise à jour des attributs
|
||||||
|
UPDATE phase_1_trace_troncons
|
||||||
|
SET
|
||||||
|
longueur =
|
||||||
|
(CASE
|
||||||
|
WHEN TRUNC( ST_Length(the_geom)::numeric , 0) = 999 THEN 1000
|
||||||
|
ELSE TRUNC( ST_Length(the_geom)::numeric , 0)
|
||||||
|
END),
|
||||||
|
km = uid -- km redadeg
|
||||||
|
;
|
||||||
|
|
Loading…
Reference in a new issue