Changes between Initial Version and Version 1 of INTEGRATING stations


Ignore:
Timestamp:
Dec 3, 2010 4:57:29 PM (14 years ago)
Author:
celine
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • INTEGRATING stations

    v1 v1  
     1back to first page[..] [[BR]] 
     2back to ["WRBD"][[BR]] 
     3 
     4Station WRBD (Western River Basin District) 
     5{{{ 
     6#!sql 
     7CREATE SCHEMA wrbd; 
     8 
     9drop table if exists wrbd.station_st; 
     10create table wrbd.station_st (  
     11        st_foliono character varying(50), 
     12        st_id character varying(10), 
     13        st_district character varying(30), 
     14        st_catchment character varying(15), 
     15        st_river character varying(40), 
     16        st_sitetributary character(5), 
     17        st_eastings numeric, 
     18        st_northing numeric, 
     19        st_location text, 
     20        st_x numeric, 
     21        st_y numeric 
     22        ); 
     23alter table wrbd.station_st add constraint  pk_st_id primary key (st_id); 
     24set client_encoding to 'latin1'; 
     25copy wrbd.station_st  from 'D:/CelineJouanin/POSEProject/Ireland/DataIreland/Station_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';' header;  
     26-- projection sur le SRID 3035 
     27SELECT AddGeometryColumn('wrbd', 'station_st','the_geom', 3035,'POINT',2);  
     28UPDATE wrbd.station_st   SET the_geom=ST_Transform(PointFromText('POINT(' || st_eastings || ' ' || st_northing || ')',29901),3035); 
     29ALTER TABLE wrbd.station_st SET WITH OIDS; 
     30 
     31--srid =29903 or srid=29901, 29900 
     32 
     33CREATE INDEX indexstation_st ON wrbd.station_st 
     34  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     35 
     36/******************************************** 
     37*  INTEGRATING WFD stations 
     38*********************************************/ 
     39 alter table wrbd.station_st add column st_source character(25); 
     40 update  wrbd.station_st set st_source='MI electrofishing survey'; 
     41 alter table wrbd.station_st add column st_waterbody character(25); 
     42 update  wrbd.station_st set st_waterbody='river'; 
     43-- COPYING survey stations 
     44copy wrbd.station_st (st_id,st_waterbody,st_catchment,st_location, st_eastings,st_northing,st_x,st_y)  from 'D:/CelineJouanin/POSEProject/Ireland/DataIreland/8.WFD_Rivers_Survey_Stations.csv' with csv delimiter as ';' header;  
     45copy wrbd.station_st (st_id,st_waterbody,st_catchment,st_location, st_eastings,st_northing,st_x,st_y) from 'C:/base/8.WFD_Rivers_Survey_Stations.csv' with csv delimiter as ';' header;  
     46-- copying transitional water stations 
     47 copy wrbd.station_st (st_id,st_waterbody,st_catchment,st_location, st_eastings,st_northing,st_x,st_y)  from 'D:/CelineJouanin/POSEProject/Ireland/DataIreland/8.Lakes_TWaters_Surveys_Stations.csv' with csv delimiter as ';' header;  
     48copy wrbd.station_st (st_id,st_waterbody,st_catchment,st_location, st_eastings,st_northing,st_x,st_y) from 'C:/base/8.Lakes_TWaters_Surveys_Stations.csv' with csv delimiter as ';' header;  
     49-- I forgot to include st_source to differentiate 
     50 update  wrbd.station_st set st_source='WFD_Rivers_Surveys' where st_waterbody='River'; 
     51 update  wrbd.station_st set st_source='WFD_Lake_Surveys' where st_waterbody='Lake'; 
     52 update  wrbd.station_st set st_source='WFD_Lake_Surveys' where st_waterbody='Non-Freshwater'; 
     53  update  wrbd.station_st set st_waterbody='river' where st_waterbody='River'; 
     54 
     55  UPDATE wrbd.station_st SET the_geom=ST_Transform(PointFromText('POINT(' || st_eastings || ' ' || st_northing || ')',29903),3035) where wrbd.station_st.st_source='WFD_Rivers_Surveys'; 
     56   UPDATE wrbd.station_st SET the_geom=ST_Transform(PointFromText('POINT(' || st_eastings || ' ' || st_northing || ')',29903),3035) where wrbd.station_st.st_source='WFD_Lake_Surveys'; 
     57 
     58}}} 
     59 
     60{{{ 
     61#!sql 
     62DROP TABLE IF EXISTS wrbd.wrbd_station_ccm_500; 
     63CREATE TABLE wrbd.wrbd_station_ccm_500 as ( 
     64        SELECT distinct on (st_id ) st_id , gid, wso1_id, min(distance) as distance, the_geom FROM ( 
     65               SELECT st_id, gid , wso1_id, CAST(distance(r.the_geom, s.the_geom) as  decimal(15,1)) as distance,s.the_geom  
     66               FROM wrbd.station_st As s 
     67               INNER JOIN  ccm21.riversegments r ON ST_DWithin(r.the_geom, s.the_geom,500) 
     68               WHERE s.the_geom IS NOT NULL 
     69               ORDER BY st_id) AS sub  
     70        GROUP BY st_id, gid, wso1_id,  distance,the_geom 
     71); 
     72alter table wrbd.wrbd_station_ccm_500 add column id serial; 
     73-- mise à jour de la table geometry_columns 
     74INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
     75SELECT '', 'wrbd', 'wrbd_station_ccm_500', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     76FROM wrbd.wrbd_station_ccm_500 LIMIT 1; 
     77-- creation d'index, clé primaire, et constraintes qui vont bien 
     78alter table wrbd.wrbd_station_ccm_500 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     79alter table wrbd.wrbd_station_ccm_500 add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     80alter table wrbd.wrbd_station_ccm_500 add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     81alter table wrbd.wrbd_station_ccm_500 ADD CONSTRAINT pk_id PRIMARY KEY(id); 
     82CREATE INDEX indexstation_ccm_500 ON wrbd.wrbd_station_ccm_500 
     83  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     84}}} 
     85 
     86{{{ 
     87#!sql 
     88-- operations 
     89-- changing format of column i 
     90drop table if exists wrbd.operation_op; 
     91 
     92create table wrbd.operation_op ( 
     93op_folio_no character varying(50), 
     94op_st_id character varying(10), 
     95ope_date date, 
     96ope_year integer, 
     97op_area numeric, 
     98op_glass numeric,  
     99op_elver numeric, 
     100op_yellow numeric, 
     101op_silver numeric, 
     102op_not_recorded numeric, 
     103op_eels_anaesthetized text,  
     104op_num_fishing integer, 
     105op_p1 integer, 
     106op_p2 integer, 
     107op_p3 integer, 
     108op_p4 integer, 
     109op_p5 integer, 
     110op_total integer, 
     111op_abundance_rating integer, 
     112op_distribution character varying(15), 
     113op_main_survey_target character varying(20), 
     114opedisthwm numeric, 
     115constraint c_fk_op_code  FOREIGN KEY  (op_st_id) REFERENCES wrbd.station_st(st_id) 
     116); 
     117 
     118alter table wrbd.operation_op add column op_nb_sets numeric; 
     119alter table wrbd.operation_op rename column op_num_fishing  to op_nb_pass; 
     120alter table wrbd.operation_op add column op_density numeric; 
     121alter table wrbd.operation_op add column op_equipment character varying(40); 
     122update wrbd.operation_op set op_equipment='Handset'; 
     123alter table wrbd.operation_op rename column op_num_fishing  to op_nb_pass; 
     124alter table  wrbd.operation_op add column op_nbfem integer; 
     125alter table  wrbd.operation_op add column op_nbmal integer; 
     126alter table  wrbd.operation_op add column op_nbind integer; 
     127copy wrbd.operation_op from 'C:/base/Operation_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';'  ;  
     128copy wrbd.operation_op from 'D:/CelineJouanin/POSEProject/Ireland/DataIreland/Operation_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';'  ;  
     129 
     130}}} 
     131{{{ 
     132#!sql 
     133-- joining operations and stations 
     134drop table if exists wrbd.operation_station; 
     135create table wrbd.operation_station as ( 
     136        select * from wrbd.station_st join wrbd.operation_op on op_st_id=st_id 
     137        where st_id in (select st_id from wrbd.wrbd_station_ccm_500)); 
     138alter table wrbd.operation_station add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     139alter table wrbd.operation_station add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     140alter table wrbd.operation_station add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     141 
     142}}} 
     143{{{ 
     144#!sql 
     145drop table if exists wrbd.operation_fish_fi; 
     146 
     147create table wrbd.operation_fish_fi ( 
     148fi_folio_no character varying(50), 
     149fi_st_id character varying(10), 
     150fi_fish_id character varying(10), 
     151fi_date date, 
     152fi_year integer, 
     153fi_individual_life character varying(10), 
     154fi_retained character varying(10), 
     155fi_length numeric 
     156); 
     157 
     158 
     159copy wrbd.operation_fish_fi from 'C:/base/Operation_fish_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';'  ;  
     160copy wrbd.operation_fish_fi from 'D:/CelineJouanin/POSEProject/Ireland/DataIreland/Operation_fish_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';'  header;  
     161 
     162}}}