Skip to topic | Skip to bottom
Home
Main
Main.xy2sst_coder1.1 - 23 Mar 2005 - 17:34 - CharltonPurvistopic end

Start of topic | Skip to actions
#!/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


You are here: Main > xy2sst_code

to top

Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DMCC? Send feedback