| 36 | -- script de départ (modifié ensuite) |
| 37 | CREATE TABLE clc.clipped_bretagne AS |
| 38 | SELECT intersected.clcgid, intersected.gid, clipped_geom |
| 39 | FROM (SELECT clc.gid as clcgid, c.gid, ST_Multi(ST_Intersection(clc.the_geom, c.the_geom)) clipped_geom |
| 40 | FROM clc.clc00_v2_europe clc INNER JOIN ccm21.catchments c |
| 41 | ON ST_Intersects (c.the_geom,clc.the_geom) |
| 42 | WHERE c.wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne') |
| 43 | AND substring(code_00 from 1 for 1)='1') AS intersected;--3721 lines |
| 44 | ALTER TABLE clc.clipped_bretagne add column id serial PRIMARY KEY; |
| 45 | |
| 46 | -3721 lines |
| 47 | ALTER TABLE clc.clipped_bretagne add column id serial PRIMARY KEY; |
| 48 | -- ajout dans la table geometry_columns pour référencement rapide sous Qgis |
| 49 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 50 | SELECT '', 'clc', 'clipped_bretagne', 'the_geom', ST_CoordDim(clipped_geom), ST_SRID(clipped_geom), MULTIPOLYGON |
| 51 | FROM clc.clipped_bretagne LIMIT 1; |
| 52 | |
| 53 | -- ci dessous j'essaye d'analyser la structure interne des données pour comprendre quels sont les problèmes |
| 54 | |
| 55 | SELECT intersected.clcgid, intersected.gid, intersected.the_geom |
| 56 | FROM (SELECT clc.gid as clcgid, c.gid, CAST(ST_AsText(ST_Multi(ST_Intersection(clc.the_geom, c.the_geom))) as VARCHAR(150)) as the_geom |
| 57 | FROM clc.clc00_v2_europe clc INNER JOIN ccm21.catchments c |
| 58 | ON ST_Intersects (c.the_geom,clc.the_geom) |
| 59 | WHERE c.wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne') |
| 60 | AND substring(code_00 from 1 for 1)='1') AS intersected; |
| 61 | |
| 62 | |
| 63 | -- Pour comparaison (ressemble beaucoup) |
| 64 | |
| 65 | SELECT CAST(ST_AsText(the_geom) as varchar(150)) from clc.clc00_v2_europe clc limit 20; |
| 66 | |
| 67 | |
| 68 | -- Je rééssaye |
| 69 | DROP TABLE IF EXISTS clc.clipped_bretagne; |
| 70 | CREATE TABLE clc.clipped_bretagne AS |
| 71 | SELECT intersected.clcgid, intersected.gid, the_geom |
| 72 | FROM (SELECT clc.gid as clcgid, c.gid, ST_Multi(ST_Intersection(clc.the_geom, c.the_geom)) the_geom |
| 73 | FROM clc.clc00_v2_europe clc INNER JOIN ccm21.catchments c |
| 74 | ON ST_Intersects (c.the_geom,clc.the_geom) |
| 75 | WHERE c.wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne') |
| 76 | AND substring(code_00 from 1 for 1)='1') AS intersected;--3721 lines |
| 77 | ALTER TABLE clc.clipped_bretagne add column id serial PRIMARY KEY; |
| 78 | -- Here to analyse the structure of data in the created table |
| 79 | SELECT ST_AsText(the_geom) from clc.clipped_bretagne limit 20; |
| 80 | |
| 81 | -- celui là marche sur Postgis (et je ne comprends pas ce qui ne marchait pas peut être le as the_geom a la place de the_geom, ou alors mon Qgis....) |
| 82 | |
| 83 | -- I'm adding some original data tables restricted for an area for Qgis easy use |
| 84 | -- extraction of a clc table for Britany |
| 85 | DROP TABLE IF EXISTS clc.clc00_v2_Bretagne; |
| 86 | CREATE TABLE clc.clc00_v2_Bretagne AS |
| 87 | SELECT * FROM clc.clc00_v2_europe where gid IN ( |
| 88 | SELECT gid FROM clc.clc00_v2_europe clc JOIN |
| 89 | (SELECT the_geom FROM france.region where code_reg='53') as sub |
| 90 | ON ST_Contains(sub.the_geom,clc.the_geom)); |
| 91 | ALTER TABLE clc.clc00_v2_Bretagne ADD CONSTRAINT c_pk_gid PRIMARY KEY (gid); |
| 92 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 93 | SELECT '', 'clc', 'clc00_v2_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 94 | FROM clc.clc00_v2_europe LIMIT 1; |
| 95 | |
| 96 | -- Creating a table for riversegments Bretagne |
| 97 | |
| 98 | DROP TABLE IF EXISTS ccm21.riversegments_Bretagne; |
| 99 | CREATE TABLE ccm21.riversegments_Bretagne AS |
| 100 | SELECT * FROM ccm21.riversegments |
| 101 | WHERE wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne'); |
| 102 | ALTER TABLE ccm21.riversegments_Bretagne ADD CONSTRAINT c_pk_gid_riversegments_Bretagne PRIMARY KEY (gid); |
| 103 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 104 | SELECT '', 'ccm21', 'riversegments_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 105 | FROM ccm21.riversegments_Bretagne LIMIT 1; |
| 106 | |
| 107 | -- creating a table for catchments Bretagne. |
| 108 | DROP TABLE IF EXISTS ccm21.catchments_Bretagne; |
| 109 | CREATE TABLE ccm21.catchments_Bretagne AS |
| 110 | SELECT * FROM ccm21.catchments |
| 111 | WHERE wso_id IN (SELECT wso_id FROM france.wso WHERE area='Bretagne'); |
| 112 | ALTER TABLE ccm21.catchments_Bretagne ADD CONSTRAINT c_pk_gid_catchments_Bretagne PRIMARY KEY (gid); |
| 113 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 114 | SELECT '', 'ccm21', 'catchments_Bretagne', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 115 | FROM ccm21.catchments_Bretagne LIMIT 1; |