39 | | CREATE INDEX indexhylcov_arc ON hylcov_arc |
40 | | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
41 | | CREATE INDEX indexStationsp2 ON stationsp2 |
42 | | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
43 | | }}} |
44 | | |
45 | | |
46 | | Joining the hylcovarc and stationsp2, the_geom is that of stationsp2, first version at source:trunk/EDAcommun/sql/bd_map_bd_carthage_version1.sql [[BR]] |
47 | | Script correspond to trial 3 above is written below |
48 | | One big error solved ticket #72 |
49 | | {{{ |
50 | | #!sql |
51 | | CREATE INDEX indexhylcov_arc_dist2 ON hylcov_arc_dist2 |
52 | | USING GIST ( the_geom GIST_GEOMETRY_OPS ); |
| 41 | -- Here we project dams on the bd_carthage |
| 42 | -- The result is stored in table roe_bd_carthage |
| 43 | -- I'm changing ref_position_etrs89 => the_geom |
| 44 | |
54 | | -- creation de la table bd_map_bd_carthage la jointure entre la bd_carthage et la table des distances par Cédric est déjà faite dans un left join. |
55 | | -- Ici on projette les stations de pêche sur la bd_carthage |
56 | | |
57 | | DROP TABLE IF EXISTS bd_map_bd_carthage; |
58 | | CREATE TABLE bd_map_bd_carthage as ( |
59 | | SELECT distinct on (st_codecsp) st_codecsp, dist_source,dist_sea,strahler,id_trhyd, min(distance) as distance, the_geom FROM ( |
60 | | SELECT st_codecsp, n.distance_mer as dist_sea,n.strahler ,d.id_trhyd ,d.dist_source_max as dist_source, CAST(distance(d.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
61 | | FROM stationsp2 As s |
62 | | INNER JOIN hylcov_arc_dist2 d ON ST_DWithin(d.the_geom, s.the_geom,300) |
| 46 | DROP TABLE IF EXISTS roe_bd_carthage; |
| 47 | CREATE TABLE roe_bd_carthage as ( |
| 48 | SELECT distinct on (ref_id) ref_id, dist_source,dist_sea,strahler,id_trhyd, min(distance) as distance, the_geom FROM ( |
| 49 | SELECT ob.ref_id, n.distance_mer as dist_sea,n.strahler ,d.id_trhyd ,d.dist_source_max as dist_source, CAST(distance(d.the_geom, ob.ref_position_etrs89) as decimal(15,1)) as distance,ob.ref_position_etrs89 as the_geom |
| 50 | FROM obstacle_referentiel As ob |
| 51 | INNER JOIN hylcov_arc_dist2 d ON ST_DWithin(d.the_geom, ob.the_geom,300) |
64 | | WHERE s.the_geom IS NOT NULL |
65 | | ORDER BY st_codecsp) as sub |
66 | | GROUP BY st_codecsp, distance, dist_source,dist_sea,strahler, id_trhyd, the_geom |
| 53 | ORDER BY ob.ref_id) as sub |
| 54 | GROUP BY ref_id, distance, dist_source,dist_sea,strahler, id_trhyd, the_geom |
71 | | SELECT '', 'public', 'bd_map_bd_carthage', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
72 | | FROM bd_map_bd_carthage LIMIT 1; |
| 59 | SELECT '', 'public', 'roe_bd_carthage', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 60 | FROM roe_bd_carthage LIMIT 1; |
75 | | alter table bd_map_bd_carthage add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
76 | | alter table bd_map_bd_carthage add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
77 | | alter table bd_map_bd_carthage add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
78 | | alter table bd_map_bd_carthage ADD CONSTRAINT pk_id PRIMARY KEY(id); |
79 | | CREATE INDEX indexbd_map_bd_carthage ON bd_map_bd_carthage |
| 63 | alter table roe_bd_carthage add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 64 | alter table roe_bd_carthage add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 65 | alter table roe_bd_carthage add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 66 | alter table roe_bd_carthage ADD CONSTRAINT pk_id_roe_bd_carthage PRIMARY KEY(id); |
| 67 | CREATE INDEX indexroe_bd_carthage ON roe_bd_carthage |
87 | | C:\"Program Files"\PostgreSQL\8.4\bin\pg_dump -U postgres -p 5433 -t bd_map_bd_carthage bd_carthage> bd_map_bd_carthage.sql |
88 | | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "drop table if exists bd_map.bd_map_bd_carthage" |
89 | | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -f bd_map_bd_carthage.sql |
90 | | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "alter table bd_map_bd_carthage drop CONSTRAINT pk_id;" |
91 | | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "alter table bd_map_bd_carthage ADD CONSTRAINT pk_id_bd_map_bd_carthage PRIMARY KEY(id); |
92 | | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "alter table bd_map_bd_carthage set schema bd_map" |
| 75 | C:\"Program Files"\PostgreSQL\8.4\bin\pg_dump -U postgres -p 5433 -t roe_bd_carthage bd_carthage> roe_bd_carthage.sql |
| 76 | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "drop table if exists geobs2010.roe_bd_carthage" |
| 77 | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -f roe_bd_carthage.sql |
| 78 | C:\"Program Files"\PostgreSQL\8.4\bin\psql -d eda2.0 -p 5433 -U postgres -c "alter table roe_bd_carthage set schema geobs2010" |
97 | | Below this table does not only select minimum distance but all ccm segments which are within a 300 m distance from the electrofishing station. [[BR]] |
98 | | |
| 83 | -- the table geobs2010.roe_ccm_300 was created in ["CookBook join ROE_CCM"] but we need to add some columns |
| 84 | -- launch in eda2.0 |
| 85 | {{{ |
| 86 | DROP TABLE IF EXISTS geobs2010.roe_ccm_300_2; |
| 87 | CREATE TABLE geobs2010.roe_ccm_300_2 as ( |
| 88 | SELECT ref_id, r.cum_len_sea as dist_sea_ccm, r.distance_source as dist_source_ccm, r.strahler as strahler_ccm,gid ,CAST(distance(r.the_geom, s.ref_position_etrs89) as decimal(15,1)) as distance,s.ref_position_etrs89 |
| 89 | FROM geobs2010.obstacle_referentiel As s |
| 90 | INNER JOIN ccm21.riversegments r ON ST_DWithin(r.the_geom, s.ref_position_etrs89,300) |
| 91 | ORDER BY ref_id |
| 92 | ); |
| 93 | alter table geobs2010.roe_ccm_300_2 add column id serial; |
| 94 | }}} |
| 95 | |
| 96 | |
| 97 | The table from the request joining geobs2010.roe_bd_carthage with the geobs2010.roe_ccm_300 is exported there (use .csv exort to C:\Documents and Settings\cedric\Mes documents\Migrateur\programmes\workspace3.5\EDAdata\dataEDAccm\export_jointure_roe_ccm.csv |
101 | | -- launch in eda2.0 |
102 | | DROP TABLE IF EXISTS bd_map.bdmap_ccm2; |
103 | | CREATE TABLE bd_map.bdmap_ccm2 as ( |
104 | | SELECT st_codecsp, r.cum_len_sea as dist_sea_ccm, r.distance_source as dist_source_ccm, r.strahler as strahler_ccm,gid ,CAST(distance(r.the_geom, s.the_geom) as decimal(15,1)) as distance,s.the_geom |
105 | | FROM bd_map.stationsp2 As s |
106 | | INNER JOIN ccm21.riversegments r ON ST_DWithin(r.the_geom, s.the_geom,300) |
107 | | WHERE s.the_geom IS NOT NULL |
108 | | ORDER BY st_codecsp |
109 | | |
110 | | ); |
111 | | alter table bd_map.bdmap_ccm2 add column id serial; |
112 | | }}} |
113 | | |
114 | | The table from the request joining bd_map.bd_map_bd_carthage with the bd_map.bdmap_ccm2 is exported there (use .csv exort to C:\Documents and Settings\cedric\Mes documents\Migrateur\programmes\workspace3.5\EDAdata\dataEDAccm\export_jointure_bdcarthage_ccm.csv |
115 | | {{{ |
116 | | #!sql |
117 | | select * from bd_map.bd_map_bd_carthage b join bd_map.bdmap_ccm2 c on b.st_codecsp=c.st_codecsp; |
| 100 | select * from geobs2010.roe_bd_carthage b join geobs2010.roe_ccm_300 c on b.st_codecsp=c.st_codecsp; |