ar_redadeg/scripts/traitements_phase_1.sql

82 lines
1.9 KiB
MySQL
Raw Normal View History

2019-01-01 19:52:23 +00:00
2019-03-06 19:46:07 +00:00
TRUNCATE phase_1_trace ;
INSERT INTO phase_1_trace
2019-01-03 21:19:25 +00:00
SELECT
ogc_fid,
secteur_id::int,
2019-01-03 21:19:25 +00:00
ordre::int,
0 AS longueur,
2019-03-06 19:46:07 +00:00
ST_Transform(the_geom,2154) AS the_geom
2019-01-03 21:19:25 +00:00
FROM phase_1_trace_3857
WHERE ST_LENGTH(the_geom) > 0
ORDER BY secteur_id ASC, ordre ASC ;
2019-01-03 21:19:25 +00:00
-- mise à jour de la longueur 1 fois la géométrie passée en CC48
2019-03-06 19:46:07 +00:00
UPDATE phase_1_trace
2019-01-03 21:19:25 +00:00
SET longueur = TRUNC( ST_Length(the_geom)::numeric / 1000 , 2) ;
2019-01-01 19:52:23 +00:00
-- on remplit la table trace 4326 pour exporter vers umap
TRUNCATE phase_1_trace_4326 ;
INSERT INTO phase_1_trace_4326
SELECT
2019-03-06 20:28:35 +00:00
t.ogc_fid,
2019-03-06 20:47:03 +00:00
s.nom_br AS name,
2019-03-06 20:28:35 +00:00
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 ;
2019-01-01 19:52:23 +00:00
-- TRUNCATE phase_1_pk_vip ;
-- INSERT INTO phase_1_pk_vip
-- SELECT ogc_fid, name, '', ST_Transform(the_geom,2154) AS the_geom
-- FROM phase_1_pk_vip_3857 ;
2019-01-01 19:52:23 +00:00
2019-01-03 21:19:25 +00:00
2019-03-06 19:46:07 +00:00
TRUNCATE phase_1_trace_troncons ;
INSERT INTO phase_1_trace_troncons
2019-01-01 19:52:23 +00:00
SELECT
2019-03-06 20:28:35 +00:00
row_number() over() as uid,
secteur_id,
ordre,
2019-03-06 20:28:35 +00:00
NULL AS km,
NULL AS km_reel,
NULL AS longueur,
ST_LineSubstring(the_geom, 1000.00*n/length,
2019-01-01 19:52:23 +00:00
CASE
2019-01-06 17:00:10 +00:00
WHEN 1000.00*(n+1) < length THEN 1000.00*(n+1)/length
2019-01-01 19:52:23 +00:00
ELSE 1
END) AS the_geom
FROM
(SELECT
ogc_fid,
secteur_id,
2019-01-03 21:56:04 +00:00
ordre,
2019-03-06 19:46:07 +00:00
ST_LineMerge(the_geom)::geometry(LineString,2154) AS the_geom,
2019-01-01 19:52:23 +00:00
ST_Length(the_geom) As length
2019-03-06 19:46:07 +00:00
FROM phase_1_trace
2019-01-03 21:56:04 +00:00
-- ce tri est le plus important
ORDER BY secteur_id ASC, ordre ASC
2019-01-01 19:52:23 +00:00
) AS t
CROSS JOIN generate_series(0,10000) AS n
2019-01-06 17:00:10 +00:00
WHERE n*1000.00/length < 1
ORDER BY t.secteur_id ASC, t.ordre ASC ;
2019-01-01 19:52:23 +00:00
-- mise à jour des attributs
2019-03-06 19:46:07 +00:00
UPDATE phase_1_trace_troncons
2019-01-01 19:52:23 +00:00
SET
longueur =
(CASE
2019-03-04 22:29:02 +00:00
WHEN TRUNC( ST_Length(the_geom)::numeric , 0) = 999 THEN 1000
2019-01-01 19:52:23 +00:00
ELSE TRUNC( ST_Length(the_geom)::numeric , 0)
END),
km = uid -- km redadeg
2019-03-06 19:46:07 +00:00
;
2019-01-01 19:52:23 +00:00