| 1 | back to first page[..] [[BR]] |
| 2 | back to ["WRBD"][[BR]] |
| 3 | |
| 4 | Station WRBD (Western River Basin District) |
| 5 | {{{ |
| 6 | #!sql |
| 7 | CREATE SCHEMA wrbd; |
| 8 | |
| 9 | drop table if exists wrbd.station_st; |
| 10 | create 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 | ); |
| 23 | alter table wrbd.station_st add constraint pk_st_id primary key (st_id); |
| 24 | set client_encoding to 'latin1'; |
| 25 | copy 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 |
| 27 | SELECT AddGeometryColumn('wrbd', 'station_st','the_geom', 3035,'POINT',2); |
| 28 | UPDATE wrbd.station_st SET the_geom=ST_Transform(PointFromText('POINT(' || st_eastings || ' ' || st_northing || ')',29901),3035); |
| 29 | ALTER TABLE wrbd.station_st SET WITH OIDS; |
| 30 | |
| 31 | --srid =29903 or srid=29901, 29900 |
| 32 | |
| 33 | CREATE 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 |
| 44 | 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.WFD_Rivers_Survey_Stations.csv' with csv delimiter as ';' header; |
| 45 | copy 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; |
| 48 | copy 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 |
| 62 | DROP TABLE IF EXISTS wrbd.wrbd_station_ccm_500; |
| 63 | CREATE 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 | ); |
| 72 | alter table wrbd.wrbd_station_ccm_500 add column id serial; |
| 73 | -- mise à jour de la table geometry_columns |
| 74 | INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") |
| 75 | SELECT '', 'wrbd', 'wrbd_station_ccm_500', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) |
| 76 | FROM wrbd.wrbd_station_ccm_500 LIMIT 1; |
| 77 | -- creation d'index, clé primaire, et constraintes qui vont bien |
| 78 | alter table wrbd.wrbd_station_ccm_500 add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 79 | alter table wrbd.wrbd_station_ccm_500 add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 80 | alter table wrbd.wrbd_station_ccm_500 add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 81 | alter table wrbd.wrbd_station_ccm_500 ADD CONSTRAINT pk_id PRIMARY KEY(id); |
| 82 | CREATE 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 |
| 90 | drop table if exists wrbd.operation_op; |
| 91 | |
| 92 | create table wrbd.operation_op ( |
| 93 | op_folio_no character varying(50), |
| 94 | op_st_id character varying(10), |
| 95 | ope_date date, |
| 96 | ope_year integer, |
| 97 | op_area numeric, |
| 98 | op_glass numeric, |
| 99 | op_elver numeric, |
| 100 | op_yellow numeric, |
| 101 | op_silver numeric, |
| 102 | op_not_recorded numeric, |
| 103 | op_eels_anaesthetized text, |
| 104 | op_num_fishing integer, |
| 105 | op_p1 integer, |
| 106 | op_p2 integer, |
| 107 | op_p3 integer, |
| 108 | op_p4 integer, |
| 109 | op_p5 integer, |
| 110 | op_total integer, |
| 111 | op_abundance_rating integer, |
| 112 | op_distribution character varying(15), |
| 113 | op_main_survey_target character varying(20), |
| 114 | opedisthwm numeric, |
| 115 | constraint c_fk_op_code FOREIGN KEY (op_st_id) REFERENCES wrbd.station_st(st_id) |
| 116 | ); |
| 117 | |
| 118 | alter table wrbd.operation_op add column op_nb_sets numeric; |
| 119 | alter table wrbd.operation_op rename column op_num_fishing to op_nb_pass; |
| 120 | alter table wrbd.operation_op add column op_density numeric; |
| 121 | alter table wrbd.operation_op add column op_equipment character varying(40); |
| 122 | update wrbd.operation_op set op_equipment='Handset'; |
| 123 | alter table wrbd.operation_op rename column op_num_fishing to op_nb_pass; |
| 124 | alter table wrbd.operation_op add column op_nbfem integer; |
| 125 | alter table wrbd.operation_op add column op_nbmal integer; |
| 126 | alter table wrbd.operation_op add column op_nbind integer; |
| 127 | copy wrbd.operation_op from 'C:/base/Operation_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';' ; |
| 128 | copy 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 |
| 134 | drop table if exists wrbd.operation_station; |
| 135 | create 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)); |
| 138 | alter table wrbd.operation_station add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); |
| 139 | alter table wrbd.operation_station add CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); |
| 140 | alter table wrbd.operation_station add CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); |
| 141 | |
| 142 | }}} |
| 143 | {{{ |
| 144 | #!sql |
| 145 | drop table if exists wrbd.operation_fish_fi; |
| 146 | |
| 147 | create table wrbd.operation_fish_fi ( |
| 148 | fi_folio_no character varying(50), |
| 149 | fi_st_id character varying(10), |
| 150 | fi_fish_id character varying(10), |
| 151 | fi_date date, |
| 152 | fi_year integer, |
| 153 | fi_individual_life character varying(10), |
| 154 | fi_retained character varying(10), |
| 155 | fi_length numeric |
| 156 | ); |
| 157 | |
| 158 | |
| 159 | copy wrbd.operation_fish_fi from 'C:/base/Operation_fish_14_Eel_Db_MI_Rivers.csv' with csv delimiter as ';' ; |
| 160 | copy 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 | }}} |