Changes between Version 66 and Version 67 of CookBook join ROE_CCM
- Timestamp:
- Apr 28, 2010 9:16:53 AM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CookBook join ROE_CCM
v66 v67 4 4 5 5 = Join ROE - CCM = 6 == Putting geobs into the CCM ==6 == Putting geobs2010 into the CCM == 7 7 Initially, the database was located in another table, below we just copy the table shema roe into the eda2.0 database 8 8 … … 11 11 REM pour Cédric 12 12 CD C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\Barrages 13 C:\"Program Files"\PostgreSQL\8.4\bin\pg_dump -U postgres -n geobs ROE> roe_schema.sql13 C:\"Program Files"\PostgreSQL\8.4\bin\pg_dump -U postgres -n geobs2010 ROE> roe_schema.sql 14 14 C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -h localhost -p 5433 -U postgres -f roe_schema.sql 15 15 REM==================================== … … 24 24 We will create a new column a new constraint and fill this column with reprojected data 25 25 {{{ 26 select AddGeometryColumn('geobs ', 'obstacle_referentiel','ref_position_etrs89' , 3035,'POINT',2);26 select AddGeometryColumn('geobs2010', 'obstacle_referentiel','ref_position_etrs89' , 3035,'POINT',2); 27 27 -- this function also creates constraint « enforce_srid_ref_position_etrs89 28 select SRID (ref_position_locale) FROM geobs .obstacle_referentiel; -- all lines 27572 (Lambert II)29 update geobs .obstacle_referentiel set ref_position_etrs89 =ST_Transform(ref_position_locale,3035);28 select SRID (ref_position_locale) FROM geobs2010.obstacle_referentiel; -- all lines 27572 (Lambert II) 29 update geobs2010.obstacle_referentiel set ref_position_etrs89 =ST_Transform(ref_position_locale,3035); 30 30 }}} 31 31 … … 95 95 we have 43937 lines, after joining with France we should have less 96 96 {{{ 97 SELECT count(ref_id) from geobs .obstacle_referentiel -- 4393797 SELECT count(ref_id) from geobs2010.obstacle_referentiel -- 43937 98 98 }}} 99 99 {{{ … … 104 104 The following does not work and it makes sense, we should only have one geom of france 105 105 {{{ 106 SELECT count(ref_id) from geobs .obstacle_referentiel o106 SELECT count(ref_id) from geobs2010.obstacle_referentiel o 107 107 join france.departement f ON ST_DWithin(f.the_geom, o.ref_position_etrs89, 2000); --49468 108 108 }}} … … 113 113 I first aggregate all departements and then join this glued layer with the dam layer, the distance is 2000 114 114 {{{ 115 SELECT count(ref_id) from geobs .obstacle_referentiel o115 SELECT count(ref_id) from geobs2010.obstacle_referentiel o 116 116 join (SELECT ST_Union(f.the_geom) as singlegeom 117 117 FROM france.departement As f) as sub … … 130 130 -- Création de la table correspondance, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis 131 131 {{{ 132 CREATE INDEX indexgeobs ON geobs .obstacle_referentiel USING GIST (ref_position_etrs89 GIST_GEOMETRY_OPS);133 DROP TABLE IF EXISTS geobs .correspondance;134 CREATE TABLE geobs .correspondance as (132 CREATE INDEX indexgeobs ON geobs2010.obstacle_referentiel USING GIST (ref_position_etrs89 GIST_GEOMETRY_OPS); 133 DROP TABLE IF EXISTS geobs2010.correspondance; 134 CREATE TABLE geobs2010.correspondance as ( 135 135 SELECT distinct on (ref_id) ref_id, gid, min(distance) as distance, ref_position_etrs89 as the_geom FROM ( 136 136 SELECT ref_id, gid ,CAST(distance(r.the_geom, b.ref_position_etrs89) as decimal(15,1)) as distance ,b.ref_position_etrs89 137 FROM geobs .obstacle_referentiel As b137 FROM geobs2010.obstacle_referentiel As b 138 138 INNER JOIN ccm21.riversegments r ON ST_DWithin(r.the_geom, b.ref_position_etrs89,1000) 139 139 -- WHERE b.goodproj IS TRUE -- Attention c'est faux … … 146 146 -- si la commande ci dessus ne marche pas ... 147 147 INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 148 SELECT '', 'geobs ', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom)149 FROM geobs .correspondance LIMIT 1;148 SELECT '', 'geobs2010', 'correspondance', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 149 FROM geobs2010.correspondance LIMIT 1; 150 150 151 151 -- creation d'index, clé primaire, et constraintes qui vont bien 152 alter table geobs .correspondance add column id serial PRIMARY KEY;153 alter table geobs .correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2);154 alter table geobs .correspondance add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL);155 alter table geobs .correspondance add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035);156 157 CREATE INDEX indexgeobscorrespondance ON geobs .correspondance152 alter table geobs2010.correspondance add column id serial PRIMARY KEY; 153 alter table geobs2010.correspondance add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 154 alter table geobs2010.correspondance add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 155 alter table geobs2010.correspondance add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 156 157 CREATE INDEX indexgeobscorrespondance ON geobs2010.correspondance 158 158 USING GIST ( the_geom GIST_GEOMETRY_OPS ); 159 159 }}} 160 160 The final script is below 161 161 {{{ 162 ALTER TABLE geobs .obstacle_referentiel ADD COLUMN goodproj boolean;163 UPDATE geobs .obstacle_referentiel set goodproj=FALSE ;164 UPDATE geobs .obstacle_referentiel set goodproj=TRUE where ref_id IN (165 SELECT ref_id from geobs .correspondance);162 ALTER TABLE geobs2010.obstacle_referentiel ADD COLUMN goodproj boolean; 163 UPDATE geobs2010.obstacle_referentiel set goodproj=FALSE ; 164 UPDATE geobs2010.obstacle_referentiel set goodproj=TRUE where ref_id IN ( 165 SELECT ref_id from geobs2010.correspondance); 166 166 }}} 167 167 We now have to use, and can display the dams left out in qgis 168 168 {{{ 169 select * from geobs .obstacle_referentiel where goodproj=TRUE169 select * from geobs2010.obstacle_referentiel where goodproj=TRUE 170 170 }}} 171 171 == Some statistics about the dam projection == … … 183 183 Calcul du pourcentage de barrages projetés par région. 184 184 {{{ 185 DROP TABLE if exists geobs .pourcentageprojette;186 CREATE TABLE geobs .pourcentageprojette AS(185 DROP TABLE if exists geobs2010.pourcentageprojette; 186 CREATE TABLE geobs2010.pourcentageprojette AS( 187 187 SELECT 100*JOINT/(JOINT +DISJOINT) as pourcentage, nom_region,the_geom FROM( 188 188 SELECT nom_region, sum(cast(cast(goodproj AS integer)as NUMERIC)) as joint, sum(cast(cast(NOT goodproj AS integer) AS NUMERIC)) as disjoint, the_geom 189 from france.region f, geobs .obstacle_referentiel g189 from france.region f, geobs2010.obstacle_referentiel g 190 190 WHERE ST_Intersects(f.the_geom,g.ref_position_etrs89) 191 191 group by nom_region, the_geom)as sub); 192 SELECT geometrytype(the_geom) FROM geobs .pourcentageprojette;193 ALTER TABLE geobs .pourcentageprojette ADD column pourc_id serial PRIMARY KEY;194 alter table geobs .pourcentageprojette add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2);195 alter table geobs .pourcentageprojette add CONSTRAINT enforce_geomtype_the_geom CHECK(geometrytype(the_geom) = 'MULTIPOLYGON'::text OR geometrytype(the_geom) = 'POLYGON'::text OR the_geom IS NULL);;196 alter table geobs .pourcentageprojette add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035);192 SELECT geometrytype(the_geom) FROM geobs2010.pourcentageprojette; 193 ALTER TABLE geobs2010.pourcentageprojette ADD column pourc_id serial PRIMARY KEY; 194 alter table geobs2010.pourcentageprojette add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 195 alter table geobs2010.pourcentageprojette add CONSTRAINT enforce_geomtype_the_geom CHECK(geometrytype(the_geom) = 'MULTIPOLYGON'::text OR geometrytype(the_geom) = 'POLYGON'::text OR the_geom IS NULL);; 196 alter table geobs2010.pourcentageprojette add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 197 197 }}} 198 198 Pourcentage de barrages projettés avec un buffer de 300 m … … 203 203 204 204 205 When we compare the geobs .correspondance and the geobs.obstacle_referentiel :[[BR]]206 [[Image(source:data/Docs/trac/ROE/Obstacle referentiel et correspondance.png,800px)]] 207 in red the dams in geobs .obstacle_referentiel which are not well projected205 When we compare the geobs2010.correspondance and the geobs2010.obstacle_referentiel :[[BR]] 206 [[Image(source:data/Docs/trac/ROE/Obstacle referentiel et correspondance.png,800px)]][[BR]] 207 in red the dams in geobs2010.obstacle_referentiel which are not well projected 208 208 in violet the dams which are "well" projected and projected in the CCM layer 209 209 There are two dams (in violet in the East) which are projected in the CCM layer but aren't in France