1 |
#! /usr/bin/perl -w |
---|
2 |
|
---|
3 |
## NAME: allinsitu_2_shape.pl |
---|
4 |
## |
---|
5 |
## Converts an hourly WFS request to a shapefile for NCCOOS IM mouseovers |
---|
6 |
## |
---|
7 |
## This script makes an hourly WFS request to the main SEACOOS OBS DB via an OGC wrapper |
---|
8 |
## that returns a GML containing formatted strings of the latest observations for each station in the BBOX. |
---|
9 |
## The resultant GML is then reformatted to make its subsequent conversion to shapefile |
---|
10 |
## more clean. OGR2OGR does the conversion on only the fields of interest. The new shapefile |
---|
11 |
## is placed in a directory to be SFTP.d to Maury. This shapefile is used on Maury to power |
---|
12 |
## the Mouse Over Observations layer in the NCCOOS Interactive Map. |
---|
13 |
|
---|
14 |
use LWP::Simple; |
---|
15 |
use warnings; |
---|
16 |
use lib "."; |
---|
17 |
|
---|
18 |
my ($dest_dir, $file_url, $target); |
---|
19 |
|
---|
20 |
|
---|
21 |
# data directory |
---|
22 |
$dest_dir='/home/jcleary/data/'; |
---|
23 |
|
---|
24 |
# GML data from Nautilus |
---|
25 |
#$file_url='http://nautilus.baruch.sc.edu/wfs/seacoos_in_situ?version=1.0.0&service=WFS&request=getfeature&bbox=-79.2,32.5,-73.9,37.2&typename=latest_in_situ_obs&time_offset_hours=2'; |
---|
26 |
|
---|
27 |
# GML data from Maury |
---|
28 |
$file_url='http://maury.marine.unc.edu/cgi-bin/wfs_seacoos_in_situ?version=1.0.0&service=WFS&request=getfeature&bbox=-79.2,32.5,-73.9,37.2&typename=latest_in_situ_obs&time_offset_hours=2'; |
---|
29 |
|
---|
30 |
|
---|
31 |
# get the data saved locally |
---|
32 |
$filename = $dest_dir.'in_situ.gml'; |
---|
33 |
getstore($file_url,$filename); |
---|
34 |
|
---|
35 |
|
---|
36 |
if(-e $filename) |
---|
37 |
{ |
---|
38 |
open (IN, $filename) || die("Error Reading File: $filename $!"); |
---|
39 |
{ |
---|
40 |
undef $/; |
---|
41 |
$infile = <IN>; |
---|
42 |
} |
---|
43 |
close (IN) || die("Error Closing File: $filename $!"); |
---|
44 |
|
---|
45 |
$infile =~ s/ms:station_id\>/STATION_ID\>/gi; |
---|
46 |
$infile =~ s/ms:air_pressure_mb\>/PRESSURE\>/gi; |
---|
47 |
$infile =~ s/ms:air_temperature_fahrenheit\>/AIR_TEMP\>/gi; |
---|
48 |
$infile =~ s/ms:salinity_ppt\>/SALINITY\>/gi; |
---|
49 |
$infile =~ s/ms:water_level_msl_ft\>/WATERLEVEL\>/gi; |
---|
50 |
$infile =~ s/ms:wind_speed_and_dir_knots\>/WIND_SPEED\>/gi; |
---|
51 |
$infile =~ s/ms:sea_surface_temperature_fahrenheit\>/SEA_TEMP\>/gi; |
---|
52 |
$infile =~ s/ms:sea_surface_current_speed_and_dir_knots\>/SURFC_CURR\>/gi; |
---|
53 |
$infile =~ s/ms:report_time_stamp\>/TIMESTAMP\>/gi; |
---|
54 |
$infile =~ s/ms:water_level_time_stamp\>/WL_TIME\>/gi; |
---|
55 |
$infile =~ s/ms:sea_surface_temperature_time_stamp\>/SST_TIME\>/gi; |
---|
56 |
$infile =~ s/ms:wind_speed_and_dir_time_stamp\>/WIND_TIME\>/gi; |
---|
57 |
$infile =~ s/ms:sea_surface_current_speed_and_dir_time_stamp\>/SCUR_TIME\>/gi; |
---|
58 |
|
---|
59 |
# eliminate whitespace as the last character of any attribute strings - causes issues with subsequent maptips rendering |
---|
60 |
$infile =~ s/\s\<\//\<\//gi; |
---|
61 |
|
---|
62 |
# write complete file |
---|
63 |
open (PROD, ">$filename") || die("Error Writing to File: $filename $!"); |
---|
64 |
print PROD $infile; |
---|
65 |
close (PROD) || die("Error Closing File: $filename $!"); |
---|
66 |
|
---|
67 |
# command line utlities to create to shapefile |
---|
68 |
# ogr2ogr |
---|
69 |
system ("/usr/local/bin/ogr2ogr -f 'ESRI Shapefile' -lco SHPT=POINT -select 'STATION_ID,PRESSURE,AIR_TEMP,SALINITY,WATERLEVEL,WIND_SPEED,SEA_TEMP,SURFC_CURR,TIMESTAMP,WL_TIME,SST_TIME,WIND_TIME,SCUR_TIME' ".$dest_dir."in_situ ".$filename); |
---|
70 |
|
---|
71 |
# copy files into SFTP dir for SFTPing to Maury |
---|
72 |
system ("mv ".$dest_dir."in_situ/ms:latest_in_situ_obs.* /home/jcleary/data/data_for_sftp/"); |
---|
73 |
|
---|
74 |
# remove gml/gfs files from data dir |
---|
75 |
system ("rm ".$dest_dir."in_situ.g*"); |
---|
76 |
} |
---|
77 |
|
---|
78 |
else |
---|
79 |
{ |
---|
80 |
exit (0); |
---|
81 |
} |
---|
82 |
|
---|
83 |
|
---|
84 |
exit (0); |
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|