125 | | this is ticket #47 |
| 125 | |
| 126 | -- Création d'un index sur obstacle_referentiel |
| 127 | |
| 128 | -- Création de la table correspondance, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis |
| 129 | CREATE INDEX indexgeobs ON geobs.obstacle_referentiel USING GIST (ref_position_etrs89 GIST_GEOMETRY_OPS); |
| 130 | DROP TABLE IF EXISTS geobs.correspondance; |
| 131 | CREATE TABLE geobs.correspondance as ( |
| 132 | SELECT distinct on (ref_id) ref_id, gid, min(distance) as distance, ref_position_etrs89 as the_geom FROM ( |
| 133 | SELECT ref_id, gid ,CAST(distance(r.the_geom, b.ref_position_etrs89) as decimal(15,1)) as distance ,b.ref_position_etrs89 |
| 134 | FROM geobs.obstacle_referentiel As b |
| 135 | INNER JOIN riversegments r ON ST_DWithin(r.the_geom, b.ref_position_etrs89,300) |
| 136 | WHERE b.goodproj IS TRUE |
| 137 | ORDER BY ref_id) AS sub |
| 138 | GROUP BY ref_id, gid, the_geom |
| 139 | ); --53s |
| 140 | alter table geobs.correspondance add column id serial PRIMARY KEY; |
| 141 | -- mise à jour de la table geometry_columns |
| 142 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 143 | SELECT '', 'public', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 144 | FROM correspondance LIMIT 1; |
| 145 | |
| 146 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 147 | alter table correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 148 | alter table correspondance add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 149 | alter table correspondance add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 150 | |
| 151 | alter table correspondance ADD CONSTRAINT pk_id PRIMARY KEY(id); |
| 152 | CREATE INDEX indexcorrespondance ON correspondance |
| 153 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |