back to first page[..][[BR]] back to ["CookBook Eda"][[BR]] back to ["RHT"][[BR]] = Joining RHT with BDMAP = == Joining the riversegment from RHT and stationsp2 (??) == {{{ -- creation de la table bdmap_rht, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis DROP TABLE IF EXISTS rht.bdmap_rht; CREATE TABLE rht.bdmap_rht as ( SELECT distinct on (st_codecsp) st_codecsp, id_drain, min(distance) as distance, the_geom FROM ( SELECT st_codecsp, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom FROM bd_map.stationsp2 As s INNER JOIN rht.rht r ON ST_DWithin(r.the_geom, s.the_geom,300) WHERE s.the_geom IS NOT NULL ORDER BY st_codecsp) AS sub GROUP BY st_codecsp, distance,id_drain, the_geom ); alter table rht.bdmap_rht add column id serial; -- mise à jour de la table geometry_columns INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") SELECT '', 'rht', 'bdmap_rht', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) FROM rht.bdmap_rht LIMIT 1; -- creation d'index, clé primaire, et constraintes qui vont bien alter table rht.bdmap_rht add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); alter table rht.bdmap_rht add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); alter table rht.bdmap_rht add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); alter table rht.bdmap_rht ADD CONSTRAINT pk_id PRIMARY KEY(id); CREATE INDEX indexbdmap_rht ON rht.bdmap_rht USING GIST ( the_geom GIST_GEOMETRY_OPS ); }}} {{{ select count(*) from bd_map.stationsp2 --10193 lignes select count(*) from rht.rht --114601 lignes select count(*) from rht.bdmap_rht -- 9650 lignes }}} Soit 94% des stations projetées sur le RHT {{{ select count(*) from bd_map.bdmap_ccm_gid --8188 lignes }}} Soit 80% des stations projetées sur la CCM == Some station must be deleted or reproject and the id_drain must be changed: == {{{ DROP table if exists rht.bdmap_rht_id; CREATE TABLE rht.bdmap_rht_id as ( select distinct on (st_codecsp) * from rht.bdmap_rht ); ---Tous les cours d'eau situés à plus de 200m ont été vérifiés. delete from rht.bdmap_rht_id where st_codecsp in ('03760141','03270131','01620009','01620005','01620137','01590014','06890285','06210238','03890095','02570237','02670291','02670264','02670097','02670092','02670098','02670230','02670231','02670232','02680172','02680166','02680039','02680033','02680037','02680144','02680143'); -- 25 stations supprimées delete from rht.bdmap_rht_id where st_codecsp in ('05400178','05400044','0547C020','06040033','06040206','06070217','06840018','03600120','03910037','03910021','04450005','04181015','04181000','03510116','06390254','06250304','06730233','02880208','06700020','02550268','02080064','02080065','03510111','03520110','02670261','02670202','02670203') -- 27 stations supprimées delete from rht.bdmap_rht_id where st_codecsp in ( }}} Verification des stations projetées sur ccm et dont gid a été modifié --> changement si besoin sur le rht de l'id_drain Stations vérifiées et bien projetées : {{{ st_codecsp IN ('06210010','05405071','05645242','05471015','05245023','03580002','03760112','05332023','05330018','06250227','05630038','05470066','03500175','06250317,'03580002','06690101','03760112') }}}