| 6 | |
| 7 | Joining the riversegment from RHT and stationsp2 (??) |
| 8 | |
| 9 | |
| 10 | Problème de projections !!! A vérifier en cours ! |
| 11 | -- creation de la table bdmap_rht, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 12 | DROP TABLE IF EXISTS rht.bdmap_rht; |
| 13 | CREATE TABLE rht.bdmap_rht as ( |
| 14 | SELECT distinct on (st_codecsp) st_codecsp, gid, min(distance) as distance, the_geom FROM ( |
| 15 | SELECT st_codecsp, gid ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
| 16 | FROM bd_map.stationsp2 As s |
| 17 | INNER JOIN rht.riversegments r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 18 | WHERE s.the_geom IS NOT NULL |
| 19 | ORDER BY st_codecsp) AS sub |
| 20 | GROUP BY st_codecsp, distance,gid, the_geom |
| 21 | ); |
| 22 | alter table rht.bdmap_rht add column id serial; |
| 23 | -- mise à jour de la table geometry_columns |
| 24 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 25 | SELECT '', 'rht', 'bdmap_rht', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 26 | FROM rht.bdmap_rht LIMIT 1; |
| 27 | |
| 28 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 29 | alter table rht.bdmap_rht add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 30 | alter table rht.bdmap_rht add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 31 | alter table rht.bdmap_rht add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 32 | alter table rht.bdmap_rht ADD CONSTRAINT pk_id PRIMARY KEY(id); |
| 33 | CREATE INDEX indexbdmap_rht ON rht.bdmap_rht |
| 34 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 35 | |