getLayerByName($layer_name); // pick the correct metadata incrs based on the gmt grid filename if (strpos($input_grd,'_inches_mercury') !== false) { $contour_metadata_item = 'contour_incr_inches_mercury'; $annotation_metadata_item = 'annotation_incr_inches_mercury'; } else { $contour_metadata_item = 'contour_incr'; $annotation_metadata_item = 'annotation_incr'; } $contour_incr = $this_layer->getMetadata($contour_metadata_item); $annotation_incr = $this_layer->getMetadata($annotation_metadata_item); // get the extents $grd_format_bounds = $this_map->extent->minx .'/'.$this_map->extent->maxx .'/'.$this_map->extent->miny .'/'.$this_map->extent->maxy; // set the WIDTH & HEIGHT of the new .map $this_width = $this_map->width; $this_height = $this_map->height; $command_filename = '/tmp/ms_tmp/' .$scratch_prefix.'_' .$layer_name .'_GMT.bash'; $dest_ps = '/tmp/ms_tmp/' .$scratch_prefix.'_' .$layer_name.'.ps'; $dest_png = '/tmp/ms_tmp/' .$scratch_prefix.'_' .$layer_name.'.png'; $dest_wld = '/tmp/ms_tmp/' .$scratch_prefix.'_' .$layer_name.'.wld'; $command_file = fopen($command_filename,"w"); $grd_header = '#!/bin/bash'."\n" ."cd /tmp\n" ."rm -f .gmt*\n" ."/usr2/local/gmt/GMT3.4.3/bin/gmtset PAPER_MEDIA A0\n"; fwrite($command_file,$grd_header); // add color if this is ssh if (strpos($input_grd,'sea_surface_height') !== false) { $color_table = $this_layer->getMetadata('color_table'); $contour_limits = $this_layer->getMetadata('contour_limits'); $grdimage_str = '/usr2/local/gmt/GMT3.4.3/bin/grdimage' ." $input_grd" ." -R$grd_format_bounds" .' -JX'.($this_width/72.0).'i' .'/'.($this_height/72.0).'i' ." -C$color_table" .' -P -X0 -Y0 -S3 -T -K > '.$dest_ps."\n"; fwrite($command_file, $grdimage_str); $grdcontour_str = '/usr2/local/gmt/GMT3.4.3/bin/grdcontour' ." $input_grd" ." -R$grd_format_bounds" .' -JX'.($this_width/72.0).'i' .'/'.($this_height/72.0).'i' ." -C$contour_incr -A$annotation_incr -L$contour_limits" .' -G3i/10 -P -X0 -Y0 -S3 -O >> '.$dest_ps."\n"; fwrite($command_file, $grdcontour_str); } else if (strpos($layer_name,'etopo2_bathy_relief') !== false) { $input_grd = $this_layer->getMetadata('gmt_grid'); $color_table = $this_layer->getMetadata('color_table'); $grdimage_str = '/usr2/local/gmt/GMT3.4.3/bin/grdimage' ." $input_grd" ." -R$grd_format_bounds" .' -JX'.($this_width/72.0).'i' .'/'.($this_height/72.0).'i' ." -C$color_table" .' -P -X0 -Y0 -K > '.$dest_ps."\n"; fwrite($command_file, $grdimage_str); } else if (strpos($layer_name,'etopo2_bathy_contour_only') !== false) { $input_grd = $this_layer->getMetadata('gmt_grid'); $contour_limits = $this_layer->getMetadata('contour_limits'); $contour_incr_table = $this_layer->getMetadata('contour_incr_table'); $grdcontour_str = '/usr2/local/gmt/GMT3.4.3/bin/grdcontour' ." $input_grd" ." -R$grd_format_bounds" .' -JX'.($this_width/72.0).'i' .'/'.($this_height/72.0).'i' ." -C$contour_incr_table" ." -As -L$contour_limits" .' -Wc2/150/150/150' .' -Wa2/150/150/150' .' -G'.($this_width/72.0*0.95).'i/10 -P -X0 -Y0 >> '.$dest_ps."\n"; fwrite($command_file, $grdcontour_str); } else { $grdcontour_str = '/usr2/local/gmt/GMT3.4.3/bin/grdcontour' ." $input_grd" ." -R$grd_format_bounds" .' -JX'.($this_width/72.0).'i' .'/'.($this_height/72.0).'i' ." -C$contour_incr -A$annotation_incr" .' -G3i/10 -P -X0 -Y0 > '.$dest_ps."\n"; fwrite($command_file, $grdcontour_str); } $imagemagick_cmd = '/usr/local/bin/convert' ." $dest_ps" .' -size 2380x3368' .' -crop '.$this_width.'x'.$this_height .'+0+'.(3368-$this_height) .' -transparent "rgb(255,255,255)" -type TrueColor' .' '.$dest_png."\n"; fwrite($command_file, $imagemagick_cmd); fclose($command_file); putenv("PATH=/usr2/local/gmt/GMT3.4.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/pgsql/bin:/usr2/installation_files/mapserver-4.1"); putenv("GMTHOME=/usr2/local/gmt/GMT3.4.3"); `echo "$command_filename" >> /tmp/maplog`; $res = shell_exec('/bin/bash '.$command_filename." 2>&1"); $x_incr = abs($this_map->extent->maxx - $this_map->extent->minx); $y_incr = abs($this_map->extent->maxy - $this_map->extent->miny); $wld_file = fopen($dest_wld,"w"); $wld_contents = ($x_incr / $this_width)."\n" ."0\n0\n" .(-$y_incr / $this_height)."\n" .$this_map->extent->minx."\n" .($this_map->extent->miny + $y_incr)."\n"; fwrite($wld_file, $wld_contents); fclose($wld_file); return $dest_png; } ?>