115 | | }}} |
| 150 | |
| 151 | --select st_transform(PointFromText('POINT(' || st_abcisse || ' ' || st_ordonnee || ')',27572),3035) from bdmap2009.station; |
| 152 | --select * from bdmap2009.station where st_abcisse_l93>0 -- 0 lignes on en peut pas utiliser |
| 153 | |
| 154 | SELECT AddGeometryColumn('bdmap2009', 'station','the_geom', 3035,'POINT',2); |
| 155 | UPDATE bdmap2009.station SET the_geom=st_transform(PointFromText('POINT(' || st_abcisse || ' ' || st_ordonnee || ')',27572),3035); |
| 156 | ALTER TABLE bdmap2009.station SET WITH OIDS; |
| 157 | CREATE INDEX indexStations ON bdmap2009.station |
| 158 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 159 | |
| 160 | -- il faut aller chercher les stations qui manquent dans bdmap2009.station_bdmapv2_final |
| 161 | |
| 162 | DROP TABLE IF EXISTS bdmap2009.stationsp2; |
| 163 | CREATE TABLE bdmap2009.stationsp2 WITH OIDS AS( |
| 164 | select |
| 165 | bdmap2009.station.st_altitude, |
| 166 | bdmap2009.station.st_abcisse, |
| 167 | bdmap2009.station.st_codecsp, |
| 168 | bdmap2009.station.st_datearret, |
| 169 | bdmap2009.station.st_datecreation, |
| 170 | bdmap2009.station.st_distancesource, |
| 171 | bdmap2009.station.st_distancemer, |
| 172 | bdmap2009.station.st_finalite, |
| 173 | bdmap2009.station.st_imageign, |
| 174 | bdmap2009.station.st_imagedept, |
| 175 | bdmap2009.station.st_lieudit, |
| 176 | bdmap2009.station.st_limites, |
| 177 | bdmap2009.station.st_localisation, |
| 178 | bdmap2009.station.st_longueur, |
| 179 | bdmap2009.station.st_moduleia, |
| 180 | bdmap2009.station.st_cd_naturecourseau, |
| 181 | bdmap2009.station.st_ordonnee, |
| 182 | bdmap2009.station.st_penteign, |
| 183 | bdmap2009.station.st_pkaval, |
| 184 | bdmap2009.station.st_raisremp, |
| 185 | bdmap2009.station.st_sbv, |
| 186 | bdmap2009.station.st_t_janvier, |
| 187 | bdmap2009.station.st_t_juillet, |
| 188 | bdmap2009.station.st_cd_typecourseau, |
| 189 | bdmap2009.station.st_cd_tet, |
| 190 | bdmap2009.station.st_st_id, |
| 191 | bdmap2009.station.st_cm_id, |
| 192 | bdmap2009.station.st_cx_id, |
| 193 | bdmap2009.station.st_th_id, |
| 194 | bdmap2009.station.st_eh_id, |
| 195 | bdmap2009.station.st_uh_id, |
| 196 | bdmap2009.station.st_dt_cre, |
| 197 | bdmap2009.station.st_dt_maj, |
| 198 | bdmap2009.station.st_qi_maj, |
| 199 | bdmap2009.station.st_masseeau, |
| 200 | CASE WHEN bdmap2009.station_bdmapv2_final.the_geom IS NULL THEN station.the_geom |
| 201 | ELSE bdmap2009.station_bdmapv2_final.the_geom |
| 202 | END AS the_geom |
| 203 | FROM bdmap2009.station_bdmapv2_final right join bdmap2009.station on station_bdmapv2_final.st_codecsp=bdmap2009.station.st_codecsp);--11379 |
| 204 | COMMENT ON TABLE bdmap2009.stationsp2 is 'Données BDMAP avec l année 2009 transmises par Laurent Beaulaton bdmap20110803.backup et mise à jour avec les coordonnées reprojetées par Hélène' |
| 205 | |
| 206 | -- je vire les stations hors de France, par rapport à la dernière fois deux sont rentrées en France avec des coordonnées correctes. |
| 207 | delete from bdmap2009.stationsp2 where st_codecsp IN ('03890162','03270062','03270061','03270063','03270064','06260126','06420055','06070241') |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | CREATE INDEX indexStationsp2 ON bdmap2009.stationsp2 |
| 213 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 214 | |
| 215 | |
| 216 | -- creation de la table bdmap2009.bdmap_rht, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 217 | DROP TABLE IF EXISTS bdmap2009.bdmap_rht; |
| 218 | CREATE TABLE bdmap2009.bdmap_rht as ( |
| 219 | SELECT distinct on (st_codecsp) st_codecsp, id_drain, min(distance) as distance, the_geom FROM ( |
| 220 | SELECT st_codecsp, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
| 221 | FROM bdmap2009.stationsp2 As s |
| 222 | INNER JOIN rht.rht r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 223 | WHERE s.the_geom IS NOT NULL |
| 224 | ORDER BY st_codecsp) AS sub |
| 225 | GROUP BY st_codecsp, distance,id_drain, the_geom |
| 226 | ); |
| 227 | alter table bdmap2009.bdmap_rht add column id serial; |
| 228 | -- mise à jour de la table geometry_columns |
| 229 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 230 | SELECT '', 'bdmap2009', 'bdmap_rht', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 231 | FROM bdmap2009.bdmap_rht LIMIT 1; |
| 232 | |
| 233 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 234 | alter table bdmap2009.bdmap_rht add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 235 | alter table bdmap2009.bdmap_rht add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 236 | alter table bdmap2009.bdmap_rht add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 237 | alter table bdmap2009.bdmap_rht ADD CONSTRAINT pk_id PRIMARY KEY(id); |
| 238 | CREATE INDEX indexbdmap_rht ON bdmap2009.bdmap_rht |
| 239 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 240 | |
| 241 | -- je vire les deux anciennes tables de Céline qui ne servent plus puisque je viens de refaire le travail de projection |
| 242 | |
| 243 | DROP TABLE IF EXISTS rht.bdmap_rht_id; |
| 244 | DROP TABLE IF EXISTS rht.bdmap_rht; |
| 245 | |
| 246 | -- creation de la table bdmap_bd_carthage, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 247 | -- normalement on projette sur la bd_carthage et on utilise la jointure Rht bd_carthage pour récupérer les tronçons. |
| 248 | |
| 249 | |
| 250 | DROP table if exists bdmap2009.bdmap_bd_carthage; |
| 251 | CREATE TABLE bdmap2009.bdmap_bd_carthage as ( |
| 252 | SELECT distinct on (st_codecsp) st_codecsp, id_bdcarth, min(distance) as distance, the_geom FROM ( |
| 253 | SELECT st_codecsp, id_bdcarth ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
| 254 | FROM bdmap2009.stationsp2 As s |
| 255 | INNER JOIN bd_carthage2011.troncon_hydrographique r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 256 | WHERE s.the_geom IS NOT NULL |
| 257 | AND nature !='Aqueduc, conduite forcée' and num_superp !=1 -- je vire les tronçons superposés. |
| 258 | ORDER BY st_codecsp) AS sub |
| 259 | GROUP BY st_codecsp, distance, id_bdcarth, the_geom |
| 260 | );--11181 |
| 261 | alter table bdmap2009.bdmap_bd_carthage add column id serial; |
| 262 | -- mise à jour de la table geometry_columns |
| 263 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 264 | SELECT '', 'bdmap2009', 'bdmap_bd_carthage', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 265 | FROM bdmap2009.bdmap_bd_carthage LIMIT 1; |
| 266 | |
| 267 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 268 | alter table bdmap2009.bdmap_bd_carthage add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 269 | alter table bdmap2009.bdmap_bd_carthage add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 270 | alter table bdmap2009.bdmap_bd_carthage add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 271 | CREATE INDEX indexbdmap_ccm ON bdmap2009.bdmap_bd_carthage |
| 272 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 273 | |
| 274 | |
| 275 | |
| 276 | -- vérifications il manque peu de stations |
| 277 | select count(*) from bdmap2009.station --11379 |
| 278 | select count(*) from bdmap2009.stationsp2 --11371 0.07 % |
| 279 | select * from bdmap2009.stationsp2 where the_geom is null; -- 110 stations ou il manque la geométrie |
| 280 | select count(*) from bdmap2009.bdmap_bd_carthage; --11181 sur les tronçons hydro 1.74 % |
| 281 | select count(*) from bdmap2009.bdmap_bd_carthage t join rht.rht_bdcarthage r on r.id_bdcarth=t.id_bdcarth; -- 10998 sur les tronçons du RHT 3.34 % |
| 282 | |
| 283 | }}} |