Changes between Version 14 and Version 15 of CookBook EpA


Ignore:
Timestamp:
Mar 30, 2010 3:15:28 PM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBook EpA

    v14 v15  
    5656  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
    5757}}} 
    58 Joining the riversegment and stationsp2, the_geom is that of stationsp2 
     58Joining 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. 
     62DROP TABLE IF EXISTS ia.correspondancemult; 
     63CREATE 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)  
     73DROP TABLE IF EXISTS ia.correspondance; 
     74CREATE 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); 
     83alter table ia.correspondance add constraint pk_correspondance PRIMARY KEY (iagid); 
    5984 
    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; 
    7285-- mise à jour de la table geometry_columns 
    7386INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
    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; 
     87SELECT '', 'ia', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     88FROM ia.correspondance LIMIT 1; 
    7689 
    7790-- creation d'index, clé primaire, et constraintes qui vont bien 
    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 
     91alter table ia.correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     92alter table ia.correspondance add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     93alter table ia.correspondance add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     94CREATE INDEX indexcorrespondance ON ia.correspondance 
    8395  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     96}}} 
    8497