Changes between Version 21 and Version 22 of CLC Join


Ignore:
Timestamp:
Jun 1, 2010 11:52:58 AM (15 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CLC Join

    v21 v22  
    11= This page describes the join of ccm21.catchments with the clc = 
    22[wiki:"CookBook Eda"] 
    3  
    4 --- building a table of clc only for Britany --- 
     3= First an example for Britany = 
     4== building a table of clc only for Britany == 
     5After several trial neither --- ST_Crosses --- nor  --- ST_Contains --- did work, the example with ST_Intersects provides a surface that is larger than britany, but ST_Crosses missed the area near the coasts as the geom had to be fully within Britany. 
    56{{{ 
    67#!sql 
    7 -- I'm adding some original data tables restricted for an area for Qgis easy use 
    88-- extraction of a clc table for Britany 
    99DROP TABLE IF EXISTS clc.clc00_v2_Bretagne; 
     
    1212SELECT gid FROM  clc.clc00_v2_europe clc JOIN 
    1313    (SELECT the_geom FROM france.region where code_reg='53') as sub 
    14     ON ST_Contains(sub.the_geom,clc.the_geom)); 
     14    ON ST_Intersects(sub.the_geom,clc.the_geom)); 
    1515     
    1616ALTER TABLE clc.clc00_v2_Bretagne ADD CONSTRAINT c_pk_gid PRIMARY KEY  (gid); 
     
    1818alter table clc.clc00_v2_Bretagne add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL); 
    1919alter table clc.clc00_v2_Bretagne add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     20CREATE INDEX indexclc00_v2_Bretagne ON clc.clc00_v2_Bretagne 
     21  USING GIST ( the_geom GIST_GEOMETRY_OPS );  
    2022 
    21 INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
    22 SELECT '', 'clc', 'clc00_v2_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
    23 FROM clc.clc00_v2_europe LIMIT 1; 
    24  
    25 }}} 
    26  
    27 Trial in Brittany [[BR]] 
    28  
    29 {{{ 
    30 #!sql 
    31 DROP TABLE IF EXISTS clc.clipped_bretagne; 
    32 CREATE TABLE clc.clipped_bretagne AS 
    33 SELECT intersected.clcgid, intersected.gid, the_geom 
    34 FROM (SELECT clc.gid as clcgid, c.gid, ST_Multi(ST_Intersection(clc.the_geom, c.the_geom)) the_geom 
    35         FROM  clc.clc00_v2_europe clc INNER JOIN ccm21.catchments c 
    36         ON  ST_Intersects (c.the_geom,clc.the_geom) 
    37         WHERE c.wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne') 
    38         AND substring(code_00 from 1 for 1)='1')  AS intersected;--3721 lines   
    39 ALTER TABLE clc.clipped_bretagne add column id serial PRIMARY KEY; 
    40 -- Here to analyse the structure of data in the created table 
    41 SELECT ST_AsText(the_geom) from clc.clipped_bretagne limit 20; 
    42  
    43 ALTER TABLE clc.clc00_v2_Bretagne ADD CONSTRAINT c_pk_gid PRIMARY KEY  (gid); 
    44  
     23-- run this only once 
    4524INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
    4625SELECT '', 'clc', 'clc00_v2_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
    4726FROM clc.clc00_v2_europe LIMIT 1; 
    4827}}} 
     28[[Image(source:data/Docs/trac/clc_britany.png,600px)]]  
     29 
     30== Cutting the surface according to the catchments area == 
     31Note this one took a long time to run on my computer, one hour for Britany... 
     32It uses --- ST_Intersects --- to reduce the search list and -- ST_Multi(ST_Intersection()) to cut along the primary catchments borders. 
     33{{{ 
     34-------------------------------------- 
     35-------------------------------------- 
     36--DECOUPAGE DES SURFACES 
     37-------------------------------------- 
     38-------------------------------------- 
     39DROP TABLE IF EXISTS clc.clipped_bretagne; 
     40CREATE TABLE clc.clipped_bretagne AS 
     41SELECT intersected.clcgid, intersected.gid, code_00,the_geom 
     42FROM (SELECT clc.gid as clcgid, c.gid,code_00, ST_Multi(ST_Intersection(clc.the_geom, c.the_geom)) the_geom 
     43        FROM  clc.clc00_v2_europe clc INNER JOIN ccm21.catchments c 
     44        ON  ST_Intersects (c.the_geom,clc.the_geom) 
     45        WHERE c.wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne') 
     46       -- AND substring(code_00 from 1 for 1)='1' 
     47       )  AS intersected; --1h12 min 
     48ALTER TABLE clc.clipped_bretagne ADD column id serial PRIMARY KEY; 
     49alter table clc.clipped_bretagne add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     50alter table clc.clipped_bretagne add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL); 
     51alter table clc.clipped_bretagne add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     52CREATE INDEX indexclc00clipped_bretagne ON clc.clipped_bretagne 
     53  USING GIST ( the_geom GIST_GEOMETRY_OPS );  
     54  -- les limites sont bien meilleures 
     55-- Here to analyse the structure of data in the created table 
     56SELECT ST_AsText(the_geom) from clc.clipped_bretagne limit 20; 
     57}}} 
     58[[Image(source:data/Docs/trac/clipped_bretane.png,600px)]]  
    4959The final file is effectively cut .... [[BR]] 
    5060[[Image(source:data/Docs/trac/coupure des couvertures anthropisées.png,600px)]]  [[BR]]