| 8 | {{{ |
| 9 | #!sql |
| 10 | |
| 11 | |
| 12 | |
| 13 | set search_path to belge,public; |
| 14 | select * from obstacles limit 100; |
| 15 | alter table obstacles add column obs_id serial primary key; |
| 16 | select st_srid(the_geom) from obstacles;--31300 |
| 17 | update belge.obstacles set the_geom=st_setsrid(the_geom,31370); |
| 18 | update belge.obstacles set the_geom=ST_PointFromText('POINT('||x_lb72||' '||y_lb72||')',31370);--8188 |
| 19 | update belge.obstacles set the_geom=st_transform(the_geom,3035);--2484 |
| 20 | alter table belge.obstacles ADD CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2); |
| 21 | alter table belge.obstacles ADD CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text); |
| 22 | alter table belge.obstacles ADD CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 3035); |
| 23 | alter table belge.obstacles ADD CONSTRAINT geometry_valid_check CHECK (isvalid(the_geom)); |
| 24 | |
| 25 | /* |
| 26 | retour des données dans la dbeel |
| 27 | H: |
| 28 | cd base |
| 29 | pg_dump -U postgres -h 192.168.1.104 -f "belge.obstacles.sql" --table belge.obstacles --verbose eda2 |
| 30 | psql -U postgres -h 1.100.1.6 -f "belge.obstacles.sql" dbeel |
| 31 | */ |
| 32 | -- Script integration des obstacles dans dbeel |
| 33 | |
| 34 | -- select * from obstacles |
| 35 | |
| 36 | set search_path to belge,public,dbeel; |
| 37 | |
| 38 | -- il faut d'abord rentrer un lieu |
| 39 | |
| 40 | DROP TABLE if exists belge.ouvragedbeel CASCADE; |
| 41 | CREATE TABLE belge.ouvragedbeel ( |
| 42 | obs_id integer, |
| 43 | CONSTRAINT pk_obs_op_id PRIMARY KEY (op_id), |
| 44 | CONSTRAINT c_uk_obs_id UNIQUE (obs_id), |
| 45 | CONSTRAINT fk_so_observation_place_type_id FOREIGN KEY (op_no_observationplacetype) |
| 46 | REFERENCES dbeel_nomenclature.observation_place_type (no_id) |
| 47 | MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT |
| 48 | ) INHERITS (dbeel.observation_places); |
| 49 | -- select * from belge.ouvragedbeel; |
| 50 | |
| 51 | INSERT INTO belge.ouvragedbeel |
| 52 | SELECT uuid_generate_v4() AS op_id, |
| 53 | '3035' AS op_gis_systemname , |
| 54 | 'OBSTACLES' AS op_gis_layername, |
| 55 | site_num AS op_gislocation, |
| 56 | noma AS op_placename, |
| 57 | 11 AS op_no_observationplacetype, -- Obstacle location |
| 58 | NULL AS op_op_id, |
| 59 | the_geom, |
| 60 | obs_id -- on a rajouté qu'une seule colonne, seulement l'identifiant de l'ouvrage.... |
| 61 | FROM belge.obstacles ; -- 8188 lines |
| 62 | |
| 63 | select * from belge.ouvragedbeel |
| 64 | |
| 65 | CREATE TABLE belge.obstaclescourt as |
| 66 | select site_num, obst_num, code_ori, sousbassin, basin_inf, categorie, noma, province, symbolisat, dat_m_jour, type_obst, revetement, longueur, larg_diam, |
| 67 | hauteur, prof_amont, prof_aval, lame_eau, dif_niveau, import_bio, echelle, obs_id, role_obst FROM belge.obstacles; |
| 68 | |
| 69 | DROP TABLE if exists belge.physical_obstruction CASCADE; |
| 70 | CREATE TABLE belge.physical_obstruction( |
| 71 | LIKE belge.obstaclescourt, |
| 72 | CONSTRAINT physical_obstruction_id PRIMARY KEY (ob_id), |
| 73 | CONSTRAINT fk_dp FOREIGN KEY (ob_dp_id) REFERENCES dbeel.data_provider (dp_id), |
| 74 | CONSTRAINT fk_ob_origin FOREIGN KEY (ob_no_origin)REFERENCES dbeel_nomenclature.observation_origin (no_id) , |
| 75 | CONSTRAINT fk_ob_period FOREIGN KEY (ob_no_period) REFERENCES dbeel_nomenclature.period_type (no_id) , |
| 76 | CONSTRAINT fk_ob_type FOREIGN KEY (ob_no_type) REFERENCES dbeel_nomenclature.observation_type (no_id) , |
| 77 | CONSTRAINT fk_po_obstruction_passability FOREIGN KEY (po_no_obstruction_passability)REFERENCES dbeel_nomenclature.obstruction_impact (no_id) |
| 78 | ) INHERITS (dbeel.physical_obstruction); |
| 79 | |
| 80 | -- select * from belge.physical_obstruction |
| 81 | |
| 82 | INSERT INTO belge.physical_obstruction (ob_id,ob_no_origin,ob_no_type,ob_no_period,ob_starting_date, ob_ending_date,ob_op_id,ob_dp_id,ot_no_obstruction_type, |
| 83 | ot_obstruction_number,ot_no_mortality_type, ot_no_mortality , po_no_obstruction_passability, po_obstruction_height, po_turbine_number, site_num, obst_num, code_ori, sousbassin, basin_inf, categorie, noma, province, symbolisat, dat_m_jour, type_obst, revetement, longueur, larg_diam, |
| 84 | hauteur, prof_amont, prof_aval, lame_eau, dif_niveau, import_bio, echelle, obs_id, role_obst |
| 85 | ) |
| 86 | SELECT |
| 87 | uuid_generate_v4() as ob_id, |
| 88 | 11 AS ob_no_origin, -- raw data |
| 89 | 16 AS ob_no_type, -- obstruction |
| 90 | 74 AS ob_no_period, -- Unknown |
| 91 | NULL AS ob_starting_date, |
| 92 | NULL AS ob_ending_date, |
| 93 | d.op_id as ob_op_id, |
| 94 | 7 AS ob_dp_id, |
| 95 | 219 as ot_no_obstruction_type, |
| 96 | 1 as ot_obstruction_number, |
| 97 | NULL AS ot_no_mortality_type, |
| 98 | NULL AS ot_no_mortality, |
| 99 | case when o.symbolisat='AMENAGE' then 209 |
| 100 | when o.symbolisat='CHANTOIR' then 209 |
| 101 | when o.symbolisat='EMBACLE' then 209 |
| 102 | when o.symbolisat='IMPORTANT' then 212 |
| 103 | when o.symbolisat='INDETERMINE' then 208 |
| 104 | when o.symbolisat='INFRANCHISSABLE' then 214 |
| 105 | when o.symbolisat='MAJEUR' then 213 |
| 106 | when o.symbolisat='MINEUR' then 210 |
| 107 | when o.symbolisat='NEANT' then 209 |
| 108 | when o.symbolisat='TERMINUS' then 208 |
| 109 | when o.symbolisat='N''EXISTE PLUS' then 208 |
| 110 | when o.symbolisat is null then 208 |
| 111 | end as po_no_obstruction_passability, |
| 112 | o.dif_niveau as po_obstruction_height, |
| 113 | NULL AS po_turbine_number,o.* |
| 114 | FROM |
| 115 | belge.obstaclescourt o JOIN belge.ouvragedbeel d ON o.obs_id=d.obs_id; |
| 116 | |
| 117 | }}} |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |