| 49 | |
| 50 | Version obstacle version 3 |
| 51 | {{{ |
| 52 | DROP TABLE IF EXISTS rht.rhtvs2_roev3; |
| 53 | CREATE TABLE rht.rhtvs2_roev3 as ( |
| 54 | SELECT distinct on (id_roe) id_roe, id_drain, min(distance) as distance, the_geom FROM ( |
| 55 | SELECT id_roe, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance, s.the_geom |
| 56 | FROM roe_v3.obstacle As s |
| 57 | INNER JOIN rht.rhtvs2 r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 58 | WHERE s.the_geom IS NOT NULL |
| 59 | ORDER BY id_roe) AS sub |
| 60 | GROUP BY id_roe, distance,id_drain, the_geom ---49269 lines |
| 61 | ); |
| 62 | alter table rht.rhtvs2_roev3 add column id serial; |
| 63 | -- mise à jour de la table geometry_columns |
| 64 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 65 | SELECT '', 'rht', 'rhtvs2_roev3', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 66 | FROM rht.rhtvs2_roev3 LIMIT 1; |
| 67 | |
| 68 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 69 | alter table rht.rhtvs2_roev3 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 70 | alter table rht.rhtvs2_roev3 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 71 | alter table rht.rhtvs2_roev3 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 72 | alter table rht.rhtvs2_roev3 ADD CONSTRAINT pk_idroe PRIMARY KEY(id); |
| 73 | alter table rht.rhtvs2_roev3 drop CONSTRAINT pk_idroe; |
| 74 | CREATE INDEX indexroev2_rhtvs3 ON rht.rhtvs2_roev3 |
| 75 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 76 | |
| 77 | ---Ajout des colonnes height et score |
| 78 | alter table rht.rhtvs2_roev3 add column height integer; |
| 79 | alter table rht.rhtvs2_roev3 add column score integer; |
| 80 | update rht.rhtvs2_roev3 set height=1; |
| 81 | update rht.rhtvs2_roev3 set score=1; |
| 82 | |
| 83 | |
| 84 | ---Ajout de la colonne nbdams =1 |
| 85 | alter table rht.rhtvs2_roev3 add column nbdams integer; |
| 86 | update rht.rhtvs2_roev3 set nbdams=1; |
| 87 | |
| 88 | ---Clause group by par id_drain |
| 89 | select id_drain, count(nbdams) as nbdams from rht.rhtvs2_roev3 group by id_drain; |
| 90 | |
| 91 | drop table if exists rht.rhtvs2_roev3_nbdams; |
| 92 | create table rht.rhtvs2_roev3_nbdams as |
| 93 | select id_drain, count(nbdams) as nbdams from rht.rhtvs2_roev3 as r group by id_drain; |
| 94 | alter table rht.rhtvs2_roev3_nbdams add column height integer; |
| 95 | alter table rht.rhtvs2_roev3_nbdams add column score integer; |
| 96 | update rht.rhtvs2_roev3_nbdams set height=1; |
| 97 | update rht.rhtvs2_roev3_nbdams set score=1; |
| 98 | |
| 99 | select * from roe_v3.obstacle where idtrcart is null ---2960 lignes etanom validé |
| 100 | select count(etatnom), etatnom from roe_v3.obstacle group by etatnom --- 57745 (avant 54057) obstacles marqués comme validé. |
| 101 | select * from rht.rhtvs2_roev3 where id_roe in (select id_roe from roe_v3.obstacle where idtrcart is null) --- 1895 (avant 1710) obstacles |
| 102 | |
| 103 | alter table rht.rhtvs2_roev3 add column bdc boolean default FALSE; |
| 104 | update rht.rhtvs2_roev3 set bdc=TRUE where id_roe in (select id_roe from roe_v3.obstacle where idtrcart is null) |
| 105 | }}} |
| 106 | |