144 | | == Joining ROE with RHT == |
145 | | Projection spatiale des obstacles (points) sur le RHT (lignes) avec un buffer de 300 m [[BR]] |
146 | | {{{ |
147 | | #!sql |
148 | | DROP TABLE IF EXISTS rht.rhtvs2_roev2; |
149 | | CREATE TABLE rht.rhtvs2_roev2 as ( |
150 | | SELECT distinct on (id_roe) id_roe, id_drain, min(distance) as distance, the_geom FROM ( |
151 | | SELECT id_roe, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance, s.the_geom |
152 | | FROM roe_v2.roe_v2 As s |
153 | | INNER JOIN rht.rhtvs2 r ON ST_DWithin(r.the_geom, s.the_geom,300) |
154 | | WHERE s.the_geom IS NOT NULL |
155 | | ORDER BY id_roe) AS sub |
156 | | GROUP BY id_roe, distance,id_drain, the_geom ---49269 lines |
157 | | ); |
158 | | alter table rht.rhtvs2_roev2 add column id serial; |
159 | | -- mise à jour de la table geometry_columns |
160 | | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
161 | | SELECT '', 'rht', 'rhtvs2_roev2', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
162 | | FROM rht.rhtvs2_roev2 LIMIT 1; |
163 | | |
164 | | -- creation d'index, clé primaire, et constraintes qui vont bien |
165 | | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
166 | | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
167 | | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
168 | | alter table rht.rhtvs2_roev2 ADD CONSTRAINT pk_idroe PRIMARY KEY(id); |
169 | | alter table rht.rhtvs2_roev2 drop CONSTRAINT pk_idroe; |
170 | | CREATE INDEX indexroev2_rhtvs2 ON rht.rhtvs2_roev2 |
171 | | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
172 | | |
173 | | |
174 | | |
175 | | |
176 | | alter table rht.rhtvs2_roev2 add column nbdams integer; |
177 | | update rht.rhtvs2_roev2 set nbdams=1; |
178 | | |
179 | | ---Clause group by par id_bdcarthage |
180 | | select id_drain, count(nbdams) as nbdams from rht.rht_bdcarthage_roev2 group by id_drain; |
181 | | |
182 | | drop table if exists rht.rht_bdcarthage_roev2_nbdams; |
183 | | create table rht.rht_bdcarthage_roev2_nbdams as |
184 | | select id_drain, count(nbdams) as nbdams from rht.rht_bdcarthage_roev2 as r group by id_drain; |
185 | | }}} |
| 182 | }}} |
| 183 | |
| 184 | == Joining ROE with RHT == |
| 185 | Projection spatiale des obstacles (points) sur le RHT (lignes) avec un buffer de 300 m [[BR]] |
| 186 | {{{ |
| 187 | #!sql |
| 188 | DROP TABLE IF EXISTS rht.rhtvs2_roev2; |
| 189 | CREATE TABLE rht.rhtvs2_roev2 as ( |
| 190 | SELECT distinct on (id_roe) id_roe, id_drain, min(distance) as distance, the_geom FROM ( |
| 191 | SELECT id_roe, id_drain ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance, s.the_geom |
| 192 | FROM roe_v2.roe_v2 As s |
| 193 | INNER JOIN rht.rhtvs2 r ON ST_DWithin(r.the_geom, s.the_geom,300) |
| 194 | WHERE s.the_geom IS NOT NULL |
| 195 | ORDER BY id_roe) AS sub |
| 196 | GROUP BY id_roe, distance,id_drain, the_geom ---49269 lines |
| 197 | ); |
| 198 | alter table rht.rhtvs2_roev2 add column id serial; |
| 199 | -- mise à jour de la table geometry_columns |
| 200 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 201 | SELECT '', 'rht', 'rhtvs2_roev2', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 202 | FROM rht.rhtvs2_roev2 LIMIT 1; |
| 203 | |
| 204 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 205 | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 206 | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 207 | alter table rht.rhtvs2_roev2 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 208 | alter table rht.rhtvs2_roev2 ADD CONSTRAINT pk_idroe PRIMARY KEY(id); |
| 209 | alter table rht.rhtvs2_roev2 drop CONSTRAINT pk_idroe; |
| 210 | CREATE INDEX indexroev2_rhtvs2 ON rht.rhtvs2_roev2 |
| 211 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | alter table rht.rhtvs2_roev2 add column nbdams integer; |
| 217 | update rht.rhtvs2_roev2 set nbdams=1; |
| 218 | |
| 219 | ---Clause group by par id_bdcarthage |
| 220 | select id_drain, count(nbdams) as nbdams from rht.rht_bdcarthage_roev2 group by id_drain; |
| 221 | |
| 222 | drop table if exists rht.rht_bdcarthage_roev2_nbdams; |
| 223 | create table rht.rht_bdcarthage_roev2_nbdams as |
| 224 | select id_drain, count(nbdams) as nbdams from rht.rht_bdcarthage_roev2 as r group by id_drain; |