65 | | The next steps is to group the different layers, we use the ''' ST_Multi(ST_Collect(()) ''' function to group the POLYGONS into MULTIPOLYGONS (one per line) and before this we do the reverse by transforming all MUTIPOLYGONS into POLYGONS using ''' ST_Dump() '''. |
| 65 | The next steps is to group the different layers, we use the ''' ST_Multi(ST_Collect(()) ''' function to group the POLYGONS into MULTIPOLYGONS (one per line) and before this we do the reverse by transforming all MUTIPOLYGONS into POLYGONS using ''' ST_Dump() '''. So finally calculating the area using ''' ST_Area ''' is a very quick and simple step. Note the unicity constraint wich ensures that we have only one code_00 per unit catchment. |
| 66 | |
| 67 | {{{ |
| 68 | -------------------------------------- |
| 69 | -------------------------------------- |
| 70 | --REGROUPEMENT |
| 71 | -------------------------------------- |
| 72 | -------------------------------------- |
| 73 | |
| 74 | DROP TABLE IF EXISTS clc.clipped_bretagne1; |
| 75 | CREATE TABLE clc.clipped_bretagne1 AS ( |
| 76 | SELECT gid,code_00, |
| 77 | ST_Multi(ST_Collect(f.the_geom)) as the_geom |
| 78 | FROM (SELECT gid, code_00,(ST_Dump(the_geom)).geom As the_geom |
| 79 | FROM |
| 80 | clc.clipped_bretagne |
| 81 | ) As f |
| 82 | GROUP BY gid,code_00); -- 5s |
| 83 | ALTER TABLE clc.clipped_bretagne1 add column id serial PRIMARY KEY; |
| 84 | alter table clc.clipped_bretagne1 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 85 | alter table clc.clipped_bretagne1 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL); |
| 86 | alter table clc.clipped_bretagne1 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 87 | CREATE INDEX indexclc00clipped_bretagne1 ON clc.clipped_bretagne1 |
| 88 | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 89 | ALTER TABLE clc.clipped_bretagne1 add constraint c_ck_uk UNIQUE(gid,code_00); -- contrainte d'unicité OK ! |
| 90 | |
| 91 | |
| 92 | ALTER TABLE clc.clipped_bretagne1 add column area numeric; |
| 93 | UPDATE clc.clipped_bretagne1 set area=ST_Area(the_geom); -- 9s |
| 94 | }}} |