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

Start of topic | Skip to actions
<?php
function build_composite_info ($raster_name, $time_stamp, $total_passes, $max_time_difference_sec) {
  $pass_timestamp_list = array();

  $conn = pg_pconnect("dbname=sea_coos_obs user=xxx host=xxx");
  if (!$conn) {
      echo "An error occured.\n";
      exit;
  }

  $querystr = "select local_filename, pass_timestamp from raster_$raster_name"
    ." where abs(extract(epoch from timestamp without time zone '$time_stamp')"
    ." - extract(epoch from pass_timestamp))"
    ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))"
    ." - extract(epoch from pass_timestamp)))"
    ." from raster_$raster_name)"
    ." and abs(extract(epoch from timestamp without time zone '$time_stamp')"
    ." - extract(epoch from pass_timestamp))"
    ." <= $max_time_difference_sec";

  $result = pg_query($conn, $querystr);
  while ($row = pg_fetch_row($result, $i)) {
    array_push($pass_timestamp_list,$row[0]);
    $top_pass_timestamp = $row[1];
  }

  $querystr = "select local_filename from raster_$raster_name"
    ." where pass_timestamp < timestamp without time zone '".$top_pass_timestamp."'"
    ." and abs(extract(epoch from timestamp without time zone '$time_stamp')"
    ." - extract(epoch from pass_timestamp))"
    ." <= $max_time_difference_sec"
    ." order by pass_timestamp desc"
    ." limit ".($total_passes-1);

  $result = pg_query($conn, $querystr);
  while ($row = pg_fetch_row($result, $i)) {
    array_push($pass_timestamp_list,$row[0]);
  }

  return $pass_timestamp_list;

  pg_close($conn);
}

function build_composite ($raster_name,
    $raster_src_dir, $raster_dest_dir,
    $time_stamp, $total_passes, $max_time_difference_sec) {
  $composite_info = build_composite_info ($raster_name, $time_stamp,
    $total_passes, $max_time_difference_sec);

  $composite_cmd = '/usr/local/bin/composite';

  $cmd = $composite_cmd;

  if (count($composite_info) <= 1) {
    echo '-1';
    exit;
  }

  for ($i = 0; $i < count($composite_info); $i++) {
    if ($i == 0) {
      $cmd .= ' '.$raster_src_dir.'/'.$composite_info[$i];
    }
    else if ($i == 1) {
      $cmd .= ' '.$raster_src_dir.'/'.$composite_info[$i];
      $cmd .= ' - |';
    }
    else {
      $cmd .= " $composite_cmd - $raster_src_dir/".$composite_info[$i];
      $cmd .= ' - |';
    }
  }

  $cmd = rtrim($cmd,' - |');

  preg_match("/.*(\d\d\d\d_\d\d_\d\d_\d\d_\d\d).*/",$composite_info[0],$matches);

  $time_stamp_str = $matches[1];

  $cmd .= " $raster_dest_dir/"
    .$raster_name.'_composite_'.$time_stamp_str.'.png'
    .";cp $raster_src_dir/".rtrim($composite_info[0],'png').'wld'
    ." $raster_dest_dir/"
    .$raster_name.'_composite_'.$time_stamp_str.'.wld';

  `$cmd`;
  return $raster_name.'_composite_'.$time_stamp_str;
}

$http_form_vars = count( $_POST ) > 0 ? $_POST :
  ( count($_GET) > 0 ? $_GET : array("") );

$raster_name             = urldecode($http_form_vars['raster_name']);
$raster_src_dir          = urldecode($http_form_vars['raster_src_dir']);
$raster_dest_dir         = urldecode($http_form_vars['raster_dest_dir']);
$time_stamp              = urldecode($http_form_vars['time_stamp']);
$total_passes            = urldecode($http_form_vars['total_passes']);
$max_time_difference_sec = urldecode($http_form_vars['max_time_difference_sec']);

echo build_composite($raster_name,
  $raster_src_dir,
  $raster_dest_dir,
  $time_stamp,
  $total_passes,
  $max_time_difference_sec
);
/*
echo build_composite('modis_rgb',
  '/usr2/maps/seacoos/data/usf','/usr2/home/cpurvis/Temp/composite',
  '2004-10-04 00:00:00', 4, 60*60*24*2)."\n";

http://nautilus.baruch.sc.edu/seacoos_misc/build_composite.php?raster_name=modis_rgb&raster_src_dir=/usr2/maps/seacoos/data/usf&raster_dest_dir=/usr2/home/cpurvis/Temp/composite&time_stamp=2004-10-04 00:00:00&total_passes=4&max_time_difference_sec=172800
*/
?>

-- CharltonPurvis - 23 Mar 2005
to top


You are here: Main > build_composite_php_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