#!/usr/local/perl/bin/perl
use Image::Magick;
use DBI;
# params
my $image_path = @ARGV[0];
my $x_coord = @ARGV[1];
my $y_coord = @ARGV[2];
my $sst_col = @ARGV[3]; # degrees_value or degrees_value_fahrenheit
# db particulars
my $db_name = 'myGISdb';
my $user_name = 'xx';
my $user_pass = '';
my $host_name = 'xxx';
my $table_name = 'sst_legend_carib';
my $rgb_col = 'rgb';
# open the image
my $image = Image::Magick->new;
$image->Read($image_path);
# get the color at x,y
($r,$g,$b,$a) = split(',',$image->Get("pixel[$x_coord,$y_coord]"));
($r,$g,$b,$a) = ($r/257,$g/257,$b/257,$a/257);
my $this_rgb = "$r $g $b";
# establish database connection
my $dbh = DBI->connect ( "dbi:Pg:dbname=$db_name;host=$host_name", "$user_name", "$user_pass");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
# get the sst from the table
# (make sure we only get back one row)
my $sql = qq{ SELECT max($sst_col) from $table_name where rtrim($rgb_col) = '$this_rgb' };
my $sth = $dbh->prepare( $sql );
$sth->execute();
$sth->bind_columns(undef,\$this_sst);
$sth->fetch();
$sth->finish;
$dbh->disconnect();
# debug print
# print "IMAGE $image_path | POINT ($x_coord, $y_coord) | RGB $this_rgb | SST $this_sst\n";
# return value
if (length($this_sst) < 1) {
print "No value"
}
elsif ($sst_col =~ /fahrenheit/) {
print "$this_sst deg F";
}
else {
print "$this_sst deg C";
}
--
CharltonPurvis - 23 Mar 2005
to top