Changes between Version 97 and Version 98 of CookBook join BDMAP_CCM


Ignore:
Timestamp:
May 21, 2010 2:31:26 PM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBook join BDMAP_CCM

    v97 v98  
    1010  * ticket #20 
    1111{{{ 
     12#!sql 
    1213create schema csp; 
    1314drop table if exists csp.codier; 
     
    6162Press F5 on BDMAP in pgAdminIII, the table stationsp has been created in BDMAP-Schémas-public-Tables (not in BDMAP-Schémas-bdmap-tables ? is it normal ?) > stationsp (20 Colonnes and 4 contraintes)[[BR]][[BR]] 
    6263{{{ 
     64#!sql 
    6365SELECT ST_SRID(the_geom) from stationsp; 
    6466}}}  
     
    7072If shp2psql does not populate the geometry column table, you have to do it manually, see ["CookBook Postgis"] Geometry column section for more details 
    7173{{{ 
     74#!sql 
    7275INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
    7376SELECT '', 'public', 'stationsp', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     
    7982 * We first create a table using the AS SELECT command, it is populated with colums from station, and with columns from stationsp2, note the CASE WHEN syntax, which allow to use station.the_geom when stationsp.the_geom is not present in the table. So in practise we use all the old coordinates plus the new ones which have not been verified. Also noteworthy in the script is the CREATE TABLE ... WITH OIDS. The OIDS are mandatory if you want to display the table in Qgis. 
    8083 {{{ 
     84#!sql 
    8185DROP TABLE IF EXISTS stationsp2; 
    8286CREATE TABLE stationsp2 WITH OIDS AS( 
     
    133137  * ah, and now if you want to display the new stations using Qgis, adding a further column saying whether or not the column X is filled is usefull, the result is displayed there : [screenshot:4], 
    134138{{{ 
     139#!sql 
    135140ALTER TABLE stationsp2 ADD COLUMN newstation boolean; 
    136141UPDATE stationsp2 set newstation=TRUE where x is null; 
     
    139144   * now some results ... 
    140145{{{ 
     146#!sql 
    141147select count(*) from stationsp2 --10203 
    142148select count(*) from bdmap.station --10203  
     
    146152  * those are the wrong stations  [screenshot:5] 
    147153{{{ 
    148  
     154#!sql 
    149155select * from stationsp2 where st_codecsp IN ('03890162','062B0086','01620140','03270062','03270061','03270063','03270064','062160126','06420055','06070241') 
    150156}}} 
     
    154160 * if you want to drop those stations 
    155161{{{ 
     162#!sql 
    156163delete from stationsp2 where st_codecsp IN ('03890162','062B0086','01620140','03270062','03270061','03270063','03270064','062160126','06420055','06070241') 
    157164}}} 
     
    192199You will also have to populate the geometry_column table manually 
    193200{{{ 
     201#!sql 
    194202INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
    195203SELECT '', 'bd_map', 'stationsp2', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     
    198206 
    199207{{{ 
     208#!sql 
    200209alter table bd_map.stationsp2 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
    201210alter table bd_map.stationsp2 add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     
    210219 
    211220{{{ 
     221#!sql 
    212222CREATE INDEX indexriversegments ON ccm21.riversegments 
    213223  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     
    219229Joining the riversegment and stationsp2, the_geom is that of stationsp2 
    220230{{{ 
    221  
     231#!sql 
    222232-- creation de la table correspondance, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis   
    223233DROP TABLE IF EXISTS bd_map.correspondance; 
     
    248258 
    249259{{{ 
     260#!sql 
    250261select count(*) from bd_map.correspondance ;--9272 -- 8884 a 300m 
    251262select count(*) from bd_map.stationsp2 ;--10203