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 |
45 | 24 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
46 | 25 | SELECT '', 'clc', 'clc00_v2_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
47 | 26 | FROM clc.clc00_v2_europe LIMIT 1; |
48 | 27 | }}} |
| 28 | [[Image(source:data/Docs/trac/clc_britany.png,600px)]] |
| 29 | |
| 30 | == Cutting the surface according to the catchments area == |
| 31 | Note this one took a long time to run on my computer, one hour for Britany... |
| 32 | It 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 | -------------------------------------- |
| 39 | DROP TABLE IF EXISTS clc.clipped_bretagne; |
| 40 | CREATE TABLE clc.clipped_bretagne AS |
| 41 | SELECT intersected.clcgid, intersected.gid, code_00,the_geom |
| 42 | FROM (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 |
| 48 | ALTER TABLE clc.clipped_bretagne ADD column id serial PRIMARY KEY; |
| 49 | alter table clc.clipped_bretagne add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 50 | alter table clc.clipped_bretagne add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL); |
| 51 | alter table clc.clipped_bretagne add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 52 | CREATE 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 |
| 56 | SELECT ST_AsText(the_geom) from clc.clipped_bretagne limit 20; |
| 57 | }}} |
| 58 | [[Image(source:data/Docs/trac/clipped_bretane.png,600px)]] |