58 | | Joining the riversegment and stationsp2, the_geom is that of stationsp2 |
| 58 | Joining the riversegment and ia files |
| 59 | {{{ |
| 60 | -- creation de la table correspondance, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 61 | -- attentaion cette table contient des doublons et la clause DISTINCT ON NE permet pas de choisir parmi les doublons. |
| 62 | DROP TABLE IF EXISTS ia.correspondancemult; |
| 63 | CREATE TABLE ia.correspondancemult as ( |
| 64 | SELECT iagid, gid, min(distance) as distance, the_geom FROM ( |
| 65 | SELECT i.gid as iagid, r.gid ,CAST(distance(r.the_geom, i.the_geom) as decimal(15,1)) as distance,i.the_geom |
| 66 | FROM ia.iabret As i |
| 67 | INNER JOIN riversegments r ON ST_DWithin(r.the_geom, i.the_geom,300) |
| 68 | ORDER BY i.gid) AS sub |
| 69 | GROUP BY iagid, gid, the_geom |
| 70 | ); |
| 71 | -- Dans cette requète, on recherche d'aord à sélectionner pour chaque point de pêche la plus petite des distances aux tronçons |
| 72 | -- puis comme il existe des doublons (même distance) |
| 73 | DROP TABLE IF EXISTS ia.correspondance; |
| 74 | CREATE TABLE ia.correspondance as ( |
| 75 | SELECT distinct on (sub.iagid) sub.iagid ,sub.distance,the_geom,gid FROM |
| 76 | ( |
| 77 | SELECT iagid, min(distance) as distance from ia.correspondancemult |
| 78 | group by iagid |
| 79 | order by iagid |
| 80 | ) as sub |
| 81 | LEFT JOIN ia.correspondancemult c on (sub.iagid=c.iagid and sub.distance=c.distance) |
| 82 | ); |
| 83 | alter table ia.correspondance add constraint pk_correspondance PRIMARY KEY (iagid); |
60 | | -- creation de la table correspondance, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
61 | | DROP TABLE IF EXISTS bd_map.correspondance; |
62 | | CREATE TABLE bd_map.correspondance as ( |
63 | | SELECT distinct on (st_codecsp) st_codecsp, gid, min(distance) as distance, the_geom FROM ( |
64 | | SELECT st_codecsp, gid ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
65 | | FROM bd_map.stationsp2 As s |
66 | | INNER JOIN riversegments r ON ST_DWithin(r.the_geom, s.the_geom,300) |
67 | | WHERE s.the_geom IS NOT NULL |
68 | | ORDER BY st_codecsp) AS sub |
69 | | GROUP BY st_codecsp, gid, the_geom |
70 | | ); |
71 | | alter table bd_map.correspondance add column id serial; |
74 | | SELECT '', 'bd_map', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
75 | | FROM bd_map.correspondance LIMIT 1; |
| 87 | SELECT '', 'ia', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 88 | FROM ia.correspondance LIMIT 1; |
78 | | alter table bd_map.correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
79 | | alter table bd_map.correspondance add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
80 | | alter table bd_map.correspondance add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
81 | | alter table bd_map.correspondance ADD CONSTRAINT pk_id PRIMARY KEY(id); |
82 | | CREATE INDEX indexcorrespondance ON bd_map.correspondance |
| 91 | alter table ia.correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 92 | alter table ia.correspondance add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 93 | alter table ia.correspondance add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 94 | CREATE INDEX indexcorrespondance ON ia.correspondance |