| 165 | == Joining BDMAP with RHT == |
| 166 | Projection spatiale des points BDMAP sur la couche station_geography (bdmap2009). |
| 167 | {{{ |
| 168 | #sql! |
| 169 | -- creation de la table bdmap2009.bdmap_rhtvs2, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 170 | DROP TABLE IF EXISTS bdmap2009.bdmap_rhtvs2; |
| 171 | CREATE TABLE bdmap2009.bdmap_rhtvs2 as ( |
| 172 | SELECT distinct on (st_codecsp) st_codecsp, id_drain, min(distance) as distance, the_geom FROM ( |
| 173 | SELECT st_codecsp, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
| 174 | FROM bdmap2009.stationsp2 As s |
| 175 | INNER JOIN rht.rhtvs2 r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 176 | WHERE s.the_geom IS NOT NULL |
| 177 | ORDER BY st_codecsp) AS sub |
| 178 | GROUP BY st_codecsp, distance,id_drain, the_geom |
| 179 | ); |
| 180 | alter table bdmap2009.bdmap_rhtvs2 add column id serial; |
| 181 | -- mise à jour de la table geometry_columns |
| 182 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 183 | SELECT '', 'bdmap2009', 'bdmap_rhtvs2', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 184 | FROM bdmap2009.bdmap_rhtvs2 LIMIT 1; |
| 185 | |
| 186 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 187 | alter table bdmap2009.bdmap_rhtvs2 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 188 | alter table bdmap2009.bdmap_rhtvs2 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 189 | alter table bdmap2009.bdmap_rhtvs2 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 190 | alter table bdmap2009.bdmap_rhtvs2 ADD CONSTRAINT pk_id PRIMARY KEY(id); |
| 191 | CREATE INDEX indexbdmap_rht ON bdmap2009.bdmap_rhtvs2 |
| 192 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 193 | }}} |
| 194 | |