15
CREATE TABLE <my_table> ( CREATE TABLE <my_table> ( row_id SERIAL PRIMARY KEY, row_id SERIAL PRIMARY KEY, row_entry_date TIMESTAMP with time zone, row_entry_date TIMESTAMP with time zone, row_update_date TIMESTAMP with time zone, row_update_date TIMESTAMP with time zone, platform_id INT NOT NULL, platform_id INT NOT NULL, sensor_id INT, sensor_id INT, measurement_date TIMESTAMP with time zone, measurement_date TIMESTAMP with time zone, measurement_value_<my_var> FLOAT, measurement_value_<my_var> FLOAT, -- other associated -- other associated measurement_value_<my_var> added here as well measurement_value_<my_var> added here as well latitude FLOAT, latitude FLOAT, longitude FLOAT, longitude FLOAT, z FLOAT, z FLOAT, z_desc VARCHAR(20), z_desc VARCHAR(20), qc_level INT, qc_level INT, qc_flag VARCHAR(32) qc_flag VARCHAR(32) ); );

CREATE TABLE ( CREATE TABLE ( row_id SERIAL PRIMARY KEY, row_id SERIAL PRIMARY KEY, row_entry_date TIMESTAMP with time zone, row_entry_date TIMESTAMP with

  • View
    276

  • Download
    3

Embed Size (px)

Citation preview

• CREATE TABLE <my_table> (CREATE TABLE <my_table> (• row_id SERIAL PRIMARY KEY,row_id SERIAL PRIMARY KEY,• row_entry_date TIMESTAMP with time zone,row_entry_date TIMESTAMP with time zone,• row_update_date TIMESTAMP with time zone,row_update_date TIMESTAMP with time zone,• platform_id INT NOT NULL,platform_id INT NOT NULL,• sensor_id INT,sensor_id INT,• measurement_date TIMESTAMP with time zone,measurement_date TIMESTAMP with time zone,• measurement_value_<my_var> FLOAT,measurement_value_<my_var> FLOAT,• -- other associated measurement_value_<my_var> -- other associated measurement_value_<my_var>

added here as welladded here as well• latitude FLOAT,latitude FLOAT,• longitude FLOAT,longitude FLOAT,• z FLOAT,z FLOAT,• z_desc VARCHAR(20),z_desc VARCHAR(20),• qc_level INT,qc_level INT,• qc_flag VARCHAR(32)qc_flag VARCHAR(32)• ););

• * <my_table> and <my_var> could be the same for simple variables like * <my_table> and <my_var> could be the same for simple variables like • 'sst'( <my_table> = 'sst', <my_var> = 'sst'> ) or different for tandemly 'sst'( <my_table> = 'sst', <my_var> = 'sst'> ) or different for tandemly • collected variables like where ( <my_table> = 'winds', collected variables like where ( <my_table> = 'winds', • <my_var_1> = 'wind_speed', <my_var_2> = 'wind_from_direction', <my_var_1> = 'wind_speed', <my_var_2> = 'wind_from_direction', • <my_var_3> = 'wind_gust' ).<my_var_3> = 'wind_gust' ).• * row_id, row_entry_date, row_update_date are my preferences for internal * row_id, row_entry_date, row_update_date are my preferences for internal • table row referencestable row references• * platform_id (or station_id, container_id) – an integer code which references* platform_id (or station_id, container_id) – an integer code which references• a lookup table for platform information. Could also be a string label for a lookup table for platform information. Could also be a string label for • simpler configurations. simpler configurations. • * sensor_id - an integer code which references a lookup table for platform * sensor_id - an integer code which references a lookup table for platform • information. Not neccessarily required for simpler configurations(or information. Not neccessarily required for simpler configurations(or • could be a string label) but adding an additional degree of detail and could be a string label) but adding an additional degree of detail and • flexibility at the sensor level. flexibility at the sensor level. • * measurement_date - the time the variable was measured with time zone* measurement_date - the time the variable was measured with time zone• referencereference• * measurement_value_<my_var> - the value(s) of the measured variable(s).* measurement_value_<my_var> - the value(s) of the measured variable(s).• There could be one or several measurement_value_<my_var> listed here.There could be one or several measurement_value_<my_var> listed here.• * latitude, longitude - unit decimal degree* latitude, longitude - unit decimal degree• * z - depth or height reference, unit meters* z - depth or height reference, unit meters• * z_desc - a string label which describes z for averaged values or specific * z_desc - a string label which describes z for averaged values or specific • boundaries such as 'surface', 'bottom', 'average', 'bin1','bin2'... boundaries such as 'surface', 'bottom', 'average', 'bin1','bin2'... • Optional.Optional.• * qc_level - integer value of [0,1,2,3,-9] corresponding to high-level qc * qc_level - integer value of [0,1,2,3,-9] corresponding to high-level qc • processprocess• * qc_flag - space separated listing of qc flags which may apply to this * qc_flag - space separated listing of qc flags which may apply to this • measurementmeasurement

• Adding a general index(assuming a station level reference Adding a general index(assuming a station level reference to individual variables) to prevent duplicate to individual variables) to prevent duplicate measurements.measurements.

• * CREATE UNIQUE INDEX i_<my_table> ON <my_table>* CREATE UNIQUE INDEX i_<my_table> ON <my_table>• (platform_id,sensor_id,z,z_desc,measurement_date);(platform_id,sensor_id,z,z_desc,measurement_date);

• Adding a PostGIS 2-dimensional geospatial reference Adding a PostGIS 2-dimensional geospatial reference column type (see this link on PostGIS enabling a column type (see this link on PostGIS enabling a PostgreSQL database).PostgreSQL database).

• -- add the geometries-- add the geometries• select select

AddGeometryColumn('<my_dbinstance>','<my_table>','tAddGeometryColumn('<my_dbinstance>','<my_table>','the_geom',-1,'POINT',2);he_geom',-1,'POINT',2);

• -- add geometry index-- add geometry index• create index <my_table>_gist on <my_table> using create index <my_table>_gist on <my_table> using

gist(the_geom);gist(the_geom);

#SELECT#SELECT

sea_coos_obs=# select * from wind_prod where sea_coos_obs=# select * from wind_prod where station_id like 'carocoops_%' order by station_id like 'carocoops_%' order by time_stamp desc limit 1;time_stamp desc limit 1;

#INSERT#INSERT• print WIND_SQLFILE "INSERT INTO wind_prod (";print WIND_SQLFILE "INSERT INTO wind_prod (";• print WIND_SQLFILE "station_id,";print WIND_SQLFILE "station_id,";• print WIND_SQLFILE "time_stamp,";print WIND_SQLFILE "time_stamp,";• print WIND_SQLFILE "z,";print WIND_SQLFILE "z,";• ……• print WIND_SQLFILE ") ";print WIND_SQLFILE ") ";• print WIND_SQLFILE "VALUES (";print WIND_SQLFILE "VALUES (";• print WIND_SQLFILE '\''.$institution_code_value.'_'.print WIND_SQLFILE '\''.$institution_code_value.'_'.

$platform_code_value.'_'.$package_code_value.'\'';$platform_code_value.'_'.$package_code_value.'\'';• print WIND_SQLFILE ','.'timestamp without time zone \''.print WIND_SQLFILE ','.'timestamp without time zone \''.

$time_formatted_values[$k].'\'';$time_formatted_values[$k].'\'';• if ($wind_speed[$i]{'height'} == $missing_value_valueif ($wind_speed[$i]{'height'} == $missing_value_value• || $wind_speed[$i]{'height'} == $Fill_value_value) {|| $wind_speed[$i]{'height'} == $Fill_value_value) {• print WIND_SQLFILE ','.'\'\'';print WIND_SQLFILE ','.'\'\'';• }}

#UPDATE#UPDATE

update <my_table> setupdate <my_table> set

<column_1> = <value_1>,<column_1> = <value_1>,

<column_2> = <value_2>,<column_2> = <value_2>,

……

where <condition>;where <condition>;

#DELETE#DELETE

delete from <my_table> where delete from <my_table> where <condition>;<condition>;

• LAYERLAYER• NAME "wind_obs_hourly_recent"NAME "wind_obs_hourly_recent"• STATUS OFFSTATUS OFF• DATA "the_geom from (select station_id, time_stamp, z, label_z, wind_speed, wind_speed_knots, normalized_wind_speed, DATA "the_geom from (select station_id, time_stamp, z, label_z, wind_speed, wind_speed_knots, normalized_wind_speed,

normalized_wind_speed_knots, wind_from_direction, label_theta, %wind_label_char_column% as this_label_char, label_char, normalized_wind_speed_knots, wind_from_direction, label_theta, %wind_label_char_column% as this_label_char, label_char, normalized_label_char, lon, lat, title, institution, institution_url, institution_dods_url, source, refs, contact, report_time_stamp, the_geom, normalized_label_char, lon, lat, title, institution, institution_url, institution_dods_url, source, refs, contact, report_time_stamp, the_geom, wind_from_direction_compass, wind_speed_mph, normalized_wind_speed_mph, label_char_knots, label_char_mph, wind_from_direction_compass, wind_speed_mph, normalized_wind_speed_mph, label_char_knots, label_char_mph, normalized_label_char_knots, normalized_label_char_mph, value, value_knots, value_mph, normalized_value, normalized_value_knots, normalized_label_char_knots, normalized_label_char_mph, value, value_knots, value_mph, normalized_value, normalized_value_knots, normalized_value_mph, seq, can_be_normalized from wind_map) as foo USING UNIQUE seq USING SRID=-1"normalized_value_mph, seq, can_be_normalized from wind_map) as foo USING UNIQUE seq USING SRID=-1"

• FILTER "report_time_stamp = date_trunc('hour',timestamp without time zone '%formatted_time_stamp%') and station_id like '%%station_idFILTER "report_time_stamp = date_trunc('hour',timestamp without time zone '%formatted_time_stamp%') and station_id like '%%station_id%%'"%%'"

• DUMP TRUEDUMP TRUE• TEMPLATE "dummy"TEMPLATE "dummy"• TOLERANCE 5TOLERANCE 5• TOLERANCEUNITS pixelsTOLERANCEUNITS pixels• TYPE POINTTYPE POINT• CONNECTIONTYPE POSTGISCONNECTIONTYPE POSTGIS• CONNECTION "user=postgres dbname=sea_coos_obs host=neptune.baruch.sc.edu"CONNECTION "user=postgres dbname=sea_coos_obs host=neptune.baruch.sc.edu"• LABELITEM "this_label_char"LABELITEM "this_label_char"• LABELANGLEITEM "label_theta"LABELANGLEITEM "label_theta"• CLASSCLASS• EXPRESSION ([wind_speed] * 1.945 >= 3)EXPRESSION ([wind_speed] * 1.945 >= 3)• LABELLABEL• FORCE TRUEFORCE TRUE• TYPE TRUETYPETYPE TRUETYPE• FONT weatherFONT weather• ANTIALIAS TRUEANTIALIAS TRUE• COLOR 0 0 0COLOR 0 0 0• POSITION CCPOSITION CC• OFFSET 2 -9OFFSET 2 -9• BUFFER 0BUFFER 0• PARTIALS TRUEPARTIALS TRUE• SIZE 25SIZE 25• ENDEND• STYLE ENDSTYLE END• ENDEND• CLASSCLASS• EXPRESSION ([wind_speed] * 1.942 < 3)EXPRESSION ([wind_speed] * 1.942 < 3)• SIZE 5SIZE 5• SYMBOL 'circle'SYMBOL 'circle'• OUTLINECOLOR 0 0 0OUTLINECOLOR 0 0 0• COLOR 255 255 255COLOR 255 255 255• ENDEND• ENDEND

• LAYERLAYER

• NAME "carocoops_surge_products" NAME "carocoops_surge_products"

• STATUS DEFAULTSTATUS DEFAULT

• DATA "the_geom from surge_products"DATA "the_geom from surge_products"

• FILTER "(catalog_id = %catalog_id%) and (track_id FILTER "(catalog_id = %catalog_id%) and (track_id = %track_id%) and (product_id = %product_id%) and = %track_id%) and (product_id = %product_id%) and (time_frame = %time_frame%)"(time_frame = %time_frame%)"

• DUMP TRUEDUMP TRUE

• TEMPLATE "dummy"TEMPLATE "dummy"

• TYPE POINTTYPE POINT

• CONNECTIONTYPE POSTGISCONNECTIONTYPE POSTGIS

• CONNECTION "user=postgres dbname=hurricane CONNECTION "user=postgres dbname=hurricane host=neptune.baruch.sc.edu"host=neptune.baruch.sc.edu"

• TRANSPARENCY 80TRANSPARENCY 80