Copyright (c) 2001, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * */ include_once("/usr2/maps/seacoos/util/mk_legend_sst_carib.php"); include_once("/usr2/maps/seacoos/util/mk_imagemap.php"); include_once("/usr2/maps/seacoos/util/check_table_in_db.php"); include_once("/usr2/maps/seacoos/util/mk_contour.php"); include_once("/usr2/maps/seacoos/util/get_cached_image_root.php"); include_once("/usr2/maps/seacoos/util/build_nhc_storm_track_filters.php"); /***************************************************************************** * $Log: map_session.php.txt,v $ * Revision 1.1 2005/09/19 21:21:49 JeremyCothran * NA * * Revision 1.44 2002/10/11 20:15:42 sacha * added a way to exclude state keys from save. * * Revision 1.43 2002/07/22 20:32:35 sacha * Fix a typo. * * Revision 1.42 2002/07/07 17:28:30 pspencer * added optional flag to MapSession_R restoreState\nto override restoring layer visibility * * Revision 1.41 2002/07/05 21:02:02 pspencer * commented out warning re max extents * * Revision 1.40 2002/06/17 12:39:39 bronsema * Updated restoreState to change mapsize first then set extents. * * Revision 1.1 2002/06/14 17:28:35 bronsema * New addition * * Revision 1.39 2002/05/30 18:08:48 pspencer * fixed bug in writeMapFile * * Revision 1.38 2002/05/28 22:35:30 daniel * Check for layer status DEFAULT in MapSession_R.buildStateId() * * Revision 1.37 2002/05/15 13:37:49 bronsema * Removed the need to copy a temp mapfile beside the orignal in "restoreState" * function in R/W mode. * * Revision 1.36 2002/05/15 12:27:21 bronsema * Added additional "map path" parameter to the read/write "restoreState()" function. * * Revision 1.35 2002/05/01 18:35:33 sacha * Add a optional path when loading a map file. * * Revision 1.34 2002/04/23 01:28:00 bronsema * Changed BBOX to be comma de-limited instead of space de-limited in the * read-only statekey. * * Revision 1.3 2002/04/15 17:44:33 bronsema * Minor browser specific update - state key was invalid in Netscape 4.x * * Revision 1.33 2002/04/11 17:56:52 bronsema * Removed temp fix for drawing order on processLegendTemplate. * * Revision 1.32 2002/04/11 17:48:34 bronsema * Removed temp fix for drawing order on processLegendTemplate. * * Revision 1.31 2002/04/05 19:26:38 sacha * missing parameter. * * Revision 1.30 2002/04/05 19:20:40 pspencer * fixed merge error * * Revision 1.29 2002/04/01 19:40:00 pspencer * added preservation of drawing order in processLayerTemplate function * * Revision 1.28 2002/03/19 01:49:41 bronsema * Fixed set projection problem in MapSession_R * * Revision 1.27 2002/03/15 14:05:49 bronsema * Updated the MapSession class to allow the set/get of maximum extents and * adjusted the map naviagation to be restricted to those extents if they are set. * * Revision 1.26 2002/03/14 19:59:13 bronsema * Updated template functions to allow the aszTag parameters to be optional. * * Revision 1.25 2002/03/13 20:29:57 bronsema * no message * * Revision 1.24 2002/03/13 15:19:41 pspencer * added log again * ****************************************************************************/ /** * This class is the basic wrapper for the map file and provides basic file * i/o and state management. * It is assummed that the phpmapscript module is loaded prior to * instantiaiting this class. * * @author William A. Bronsema, C.E.T. (bronsema@dmsolutions.ca) * */ class MapSession extends Logger { /** * The current session map file object (private). */ var $oMap; /** * The current session map file (private). */ var $szMapFile; /** * The temp directory to write the sessions to (private). */ var $szTempDir; /** * Array of max extents (private). */ var $adMaxExtents; /** * Construct a new MapSession instance and initialize it. */ function MapSession() { // initialize variables $this->oMap = null; $this->szMapFile = ""; $this->szTempDir = ""; $this->adMaxExtents = array(); // set the scope for the logging functions $this->setScope( "MapSession" ); // end constructor } /** * This function sets temp directory for the MapSession. * * @param szTempDir string - Path to the tenp directory. */ function setTempDir($szTempDir) { //log entry $this->logFuncStart( LOG_VERBOSE, "setTempDir() starting" ); $this->szTempDir = $szTempDir; //log exit $this->logFuncEnd( LOG_ALL, "setTempDir() done" ); // end setTempDir function } /** * This function sets the optional maximum extents to be used to limit * zooming and panning. * * @param dMinX double - The min X extent to use. * @param dMinY double - The min Y extent to use. * @param dMaxX double - The max X extent to use. * @param dMaxY double - The max Y extent to use. * @return boolean - True if successful, False if not. **/ function setMaxExtents($dMinX, $dMinY, $dMaxX, $dMaxY) { //log entry $this->logFuncStart( LOG_VERBOSE, "setMaxExtents() starting" ); // check if the parameters are valid numbers and min is less than max if ( !( is_numeric($dMinX) && is_numeric($dMinY) && is_numeric($dMaxX) && is_numeric($dMaxY) && $dMinX < $dMaxX && $dMinY < $dMaxY)) { // generate error and return $this->error( ERR_CRITICAL, "Invalid extents given to ." ."setMaxExtents() function." ); return false; } // set the maxextent array $this->adMaxExtents["minX"] = $dMinX; $this->adMaxExtents["minY"] = $dMinY; $this->adMaxExtents["maxX"] = $dMaxX; $this->adMaxExtents["maxY"] = $dMaxY; //log exit $this->logFuncEnd( LOG_ALL, "setMaxExtents() done" ); // end setMaxExtents function } /** * This function returns an associative array of extents if they were set * or false if they were not. The indexes are as follows: * array["minX"] * array["minY"] * array["maxX"] * array["maxY"] * * @return mixed - Associative array of extents if set or false if not. **/ function getMaxExtents() { //log entry $this->logFuncStart( LOG_VERBOSE, "getMaxExtents() starting" ); // count the array items and if greater than 0 return if ( count( $this->adMaxExtents ) > 0 ) { // return the array because extents are set $ReturnValue = $this->adMaxExtents; } else { // return failure //$this->error( ERR_CRITICAL, "Maximum extents are not set."); $ReturnValue = false; } //log exit $this->logFuncEnd( LOG_ALL, "getMaxExtents() done" ); // return return $ReturnValue; // end getMaxExtents function } /** * This function opens a map file and sest oMap to a valid state. * * @param szMapFile string - Path and filename of the map to open. * @param szMapFilePath string - Path of the map to open. This is set * when a different path is used. * * @return boolean - True if successful, false if not. */ function readMapFile($szMapFile, $szMapFilePath="") { //log entry $this->logFuncStart( LOG_VERBOSE, "readMapFile() starting" ); // check to see if the map file exists if ( !file_exists($szMapFile) ) { // log error $this->error( ERR_FILE_IO, "The map file[".$szMapFile. "] is not valid." ); // return failure return false; } if ($szMapFilePath != "" && is_dir($szMapFilePath)) { $this->oMap = ms_newMapObj($szMapFile, $szMapFilePath); } else { // set the map object to be the phpmapscript map object $this->oMap = ms_newMapObj($szMapFile); } // check for errors if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "Unable to access map [".$szMapFile. "]. Check to see that the file exists and/or ". "that the path and filename are spelled ". "correctly" ); // return failure return false; } // set the extents to validate them $this->oMap->setextent($this->oMap->extent->minx, $this->oMap->extent->miny, $this->oMap->extent->maxx, $this->oMap->extent->maxy); // log successful open $this->log( LOG_VERBOSE, "readMapFile - Open map file[".$szMapFile. "] was successful" ); // record the map path and filename; $this->szMapFile = $szMapFile; //log exit $this->logFuncEnd( LOG_ALL, "readMapFile() done" ); // return success return true; // end readMapFile function } /** * This function saves the current map object to the mapfile. * * @param szMapFile string - Path and filename of the map to write to. * * @return boolean - True if successful, false if not. */ function writeMapFile($szMapFile) { $bResult = true; //log entry $this->logFuncStart( LOG_VERBOSE, "writeMapFile() starting" ); // check to see that there is a valid map file open if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "No valid map object to write." ); // return failure return false; } if ( file_exists( $szMapFile ) && !is_writable( $szMapFile ) ) { $this->error( 0, "$szMapFile is not writeable" ); $bResult = false; } else { // save the map object $this->oMap->save( $szMapFile ); } // log successful save $this->log( LOG_VERBOSE, "writeMapFile - Save map file[".$szMapFile. "] was successful" ); //log exit $this->logFuncEnd( LOG_ALL, "writeMapFile() done" ); // return success return $bResult; // end writeMapFile function } /** * This function returns a pointer to the current open map object. * * @return object - A pointer to the current open map object or null. */ function getMapObj() { //log entry $this->logFuncStart( LOG_VERBOSE, "getMapObj() starting" ); //log exit $this->logFuncEnd( LOG_ALL, "getMapObj() done" ); // return a pointer to the map object return $this->oMap; // end getMapObj function } /** * This function processes the template file as set in web object of the * current session's map object. It returns the processed file as string. * * @param aszTag array - Optional associative array of user defined tags * and their corresponding values to be processed. * i.e. $aszTag["my_tag"] = "My tag's value". In this example * all the tags [my_tag] will be replaced with the string "My * tag's value". * @param nGenerateImages integer - This optional flag indicates how * special tags are to be processed. The special tags: [img], * [scalebar], [ref], [legend] can be replaced with the * appropriate URL if this flag is set to MS_TRUE. * @return mixed - A string representation(typically HTML) of the template * file with all tags processed or false if failed. **/ function processTemplate( $aszTag = array(), $nGenerateImages = MS_FALSE ) { //log entry $this->logFuncStart( LOG_VERBOSE, "processTemplate() starting" ); // check to see that there is a valid map file open if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "No valid map object to write." ); // return failure return false; } // check to see if the the tag array is a valid array if ( !is_array( $aszTag ) ) { // log error $this->error( ERR_FILE_IO, "Supplied Tag array is not a valid array." ); // return failure return false; } //log exit $this->logFuncEnd( LOG_ALL, "processTemplate() done" ); // call mapscript's proceestemplate return $this->oMap->processtemplate( $aszTag, $nGenerateImages ); // end processTemplate function } /** * This function processes the query template file as set in each layer's * class object of the current session's map object. It returns the * processed file as string. * * @param aszTag array - Optional associative array of user defined tags * and their corresponding values to be processed. * i.e. $aszTag["my_tag"] = "My tag's value". In this example * all the tags [my_tag] will be replaced with the string "My * tag's value". * @return mixed - A string representation(typically HTML) of the template * file with all tags processed or false if failed. **/ function processQueryTemplate( $aszTag = array() ) { //log entry $this->logFuncStart( LOG_VERBOSE, "processQueryTemplate() starting" ); // check to see that there is a valid map file open if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "No valid map object to write." ); // return failure return false; } // check to see if the the tag array is a valid array if ( !is_array( $aszTag ) ) { // log error $this->error( ERR_FILE_IO, "Supplied Tag array is not a valid array." ); // return failure return false; } //log exit $this->logFuncEnd( LOG_ALL, "processQueryTemplate() done" ); // call mapscript's proceesquerytemplate return $this->oMap->processquerytemplate( $aszTag ); // end processQueryTemplate function } /** * This function processes the legend template file as set in the legend * object of the current session's map object. It returns the processed * file as string. * * @param aszTag array - Optional associative array of user defined tags * and their corresponding values to be processed. * i.e. $aszTag["my_tag"] = "My tag's value". In this example * all the tags [my_tag] will be replaced with the string "My * tag's value". * @return mixed - A string representation(typically HTML) of the template * file with all tags processed or false if failed. **/ function processLegendTemplate( $aszTag = array() ) { //log entry $this->logFuncStart( LOG_VERBOSE, "processLegendTemplate() starting" ); // check to see that there is a valid map file open if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "No valid map object to write." ); // return failure return false; } // check to see if the the tag array is a valid array if ( !is_array( $aszTag ) ) { // log error $this->error( ERR_FILE_IO, "Supplied Tag array is not a valid array." ); // return failure return false; } // process the template $szResult = $this->oMap->processlegendtemplate( $aszTag ); //log exit $this->logFuncEnd( LOG_ALL, "processLegendTemplate() done" ); return $szResult; // end processLegendTemplate function } // end MapSession class } /** * This class extends the base MapSession Class to allow a save and restore * state option. This class is the read only version meaning that the save & * restore sessions will NOT wrote to the physical disk. There is also a * read/write version of this class called MapSession_RW. * It is assummed that the phpmapscript module is loaded prior to * instantiaiting this class. * * @author William A. Bronsema, C.E.T. (bronsema@dmsolutions.ca) * */ class MapSession_R extends MapSession { /** * Construct a new MapSession instance and initialize it. */ function MapSession_R() { // call the constructor for the map session base class $this->MapSession(); // set the scope for the logging functions $this->setScope( "MapSession_R" ); // end constructor } /** * This function saves the current state of the map. * * @param - aszExcludeKeys array of state key to exclude * * @return string - A unique state ID or "" if failed. */ function saveState($aszExcludeKeys = array()) { //log entry $this->logFuncStart( LOG_VERBOSE, "saveState() starting" ); // check to see that there is a valid map file open if ( !isset($this->oMap) ) { // log error $this->error( ERR_FILE_IO, "No valid map object to write." ); // return failure return ""; } // build the state id from the bbox, projection, and list of layers $szStateID = $this->buildStateID( $this->oMap, $aszExcludeKeys ); // log the result $this->log( LOG_VERBOSE, "saveState new ID = ".$szStateID ); //log exit $this->logFuncEnd( LOG_ALL, "saveState() done" ); // return ID return $szStateID; // end the saveState function } /** * This function restores the state of a map file by applying the value * of the State ID to the map file. If no map fil eis given then the * State ID will be applied to the current map. If the state id is not * given but the map file is then the map file will be opened. * * @param szStateID - Optional unique state ID. * @param szMapFile - Optional mapfile to restore state to. * @param szMapFilePath - Optional mapfile path to restore state to. * @param bRestoreLayerState - Optionally turn on restoration of layer * state from the state key. * * @return boolean - True if successful, false if not. */ function restoreState( $szStateID = "", $szMapFile = "", $szMapFilePath = "", $bRestoreLayerState = true, $mk_imagemap = true) { //log entry $this->logFuncStart( LOG_VERBOSE, "restoreState() starting" ); // check if map file was supplied if ( $szMapFile != "" ) { // open the requested map file if ( !$this->readMapFile($szMapFile, $szMapFilePath) ) return false; } // check for a current map object if ( $this->oMap == "" ) { // log error $this->error( ERR_NOTICE, "No Valid map object to restore to." ); // return failure return "false"; } // if no state given then done if ( $szStateID == "" ) { // log finished $this->logFuncEnd( LOG_ALL, "restoreState() done" ); return true; } // process the ID $aszElements = explode( "|", $szStateID); // process map size $aszElement = explode( "=", $aszElements[2] ); // check if mapsize if ( $aszElement[0] != "MAPSIZE" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The third element is not the MAPSIZE." ); // return failure return "false"; } // set the mapsize if not empty if ( $aszElement[1] != "" ) { // get the mapsize items $anMapsize = explode( "," , $aszElement[1] ); $this->oMap->set( "width", $anMapsize[0]); $this->oMap->set( "height", $anMapsize[1]); // log $this->log( LOG_QUIET, "Set width and height [".$anMapsize[0]."x".$anMapsize[1]."]." ); } // process the BBOX $aszElement = explode( "=", $aszElements[0] ); // check if BBOX if ( $aszElement[0] != "BBOX" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The first element is not the BBOX." ); // return failure return "false"; } // separate out the extents $anExtents = explode(",",$aszElement[1]); // log $this->log( LOG_QUIET, "Setting new extents..."); // set the extents $this->oMap->setextent($anExtents[0],$anExtents[1], $anExtents[2],$anExtents[3]); // log current extent values $this->log( LOG_QUIET, "New extents: ".$this->oMap->extent->minx. ", ".$this->oMap->extent->miny. ", ".$this->oMap->extent->maxx. ", ".$this->oMap->extent->maxy. "." ); // process projection $aszElement = explode( "=", $aszElements[1] ); // check if projection if ( $aszElement[0] != "SRS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The second element is not the SRS." ); // return failure return "false"; } // set the projection if not empty if ( $aszElement[1] != "" ) { // srs can contain "=" $szTmpProj = substr($aszElements[1],4); $this->oMap->setprojection($szTmpProj); //$this->oMap->setprojection($aszElement[1]); } // process the active layers $aszElement = explode( "=", $aszElements[3] ); // check if projection if ( $aszElement[0] != "LAYERS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The third element is not the LAYERS." ); // return failure return "false"; } // cpurvis // get time stamp $aszElement_session_id = explode( "=", $aszElements[4] ); // check if time if ( $aszElement_session_id[0] != "IMAGEMAP_SESSION_ID" ) { // return failure return "false"; } // cpurvis // get time zone $aszElement_degree_units = explode( "=", $aszElements[5] ); // check if time if ( $aszElement_degree_units[0] != "DEGREE_UNITS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the DEGREE_UNITS." ); // return failure return "false"; } // cpurvis // get time zone $aszElement_velocity_units = explode( "=", $aszElements[6] ); // check if time if ( $aszElement_velocity_units[0] != "VELOCITY_UNITS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the VELOCITY_UNITS." ); // return failure return "false"; } // cpurvis // get time zone $aszElement_pressure_units = explode( "=", $aszElements[7] ); // check if time if ( $aszElement_pressure_units[0] != "PRESSURE_UNITS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the PRESSURE_UNITS." ); // return failure return "false"; } // cpurvis // get time zone $aszElement_elevation_units = explode( "=", $aszElements[8] ); // check if time if ( $aszElement_elevation_units[0] != "ELEVATION_UNITS" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the ELEVATION_UNITS." ); // return failure return "false"; } // cpurvis // get time stamp $aszElement_time = explode( "=", $aszElements[9] ); // check if time if ( $aszElement_time[0] != "TIME_STAMP" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the TIME_STAMP." ); // return failure return "false"; } if ( $aszElement_time[1] != "" ) { $this->logFuncStart(LOG_VERBOSE,"found a TIME_STAMP = $aszElement_time[1]"); } else { $this->logFuncStart(LOG_VERBOSE,"no time_stamp"); } // cpurvis // get time zone $aszElement_time_zone = explode( "=", $aszElements[10] ); // check if time if ( $aszElement_time_zone[0] != "TIME_ZONE" ) { // log error $this->error( ERR_NOTICE, "The given state ID is invalid. ". "The fourth element is not the TIME_ZONE." ); // return failure return "false"; } // cpurvis // Get optional params by looping through the | separated params. // This is somewhat bad form since we went thorugh hard-coded // ones above. // But first, assume defaults. $seacoos_credit_offsets = array(-1,0,0); $seacoos_url_offsets = array(-1,0,0); $legend_offsets = array(100,100); $scalebar_units = MS_KILOMETERS; $scalebar_pixel_width = 70; $scalebar_position = MS_LR; for ($param_count = 0; $param_count < count($aszElements); $param_count++) { // get optional seacoos credit & url offsets // e.g. seacoos_credit50,50seacoos_logo50,50 if (preg_match("/SEACOOS_CREDIT_OFFSETS=/",$aszElements[$param_count])) { $this_element = explode( "=", $aszElements[$param_count] ); if (strlen($this_element[1]) > 0) { if (stristr($this_element[1],'seacoos_credit')) { preg_match("/seacoos_credit(\d+),(\d+)/",$this_element[1],$seacoos_credit_offsets); } if (stristr($this_element[1],'seacoos_url')) { preg_match("/seacoos_url(\d+),(\d+)/",$this_element[1],$seacoos_url_offsets); } } } // get optional seacoos legend offsets if (preg_match("/LEGEND_OFFSETS=/",$aszElements[$param_count])) { $this_element = explode( "=", $aszElements[$param_count] ); $legend_offsets = explode (',',$this_element[1]); } // get optional scalebar units if (preg_match("/SCALEBAR_UNITS=/",$aszElements[$param_count])) { $this_element = explode( "=", $aszElements[$param_count] ); if (strlen($this_element[1]) > 0) { $string_units = $this_element[1]; if ($string_units == 'MILES') { $scalebar_units = MS_MILES; } else if ($string_units == 'METERS') { $scalebar_units = MS_METERS; } else if ($string_units == 'KILOMETERS') { $scalebar_units = MS_KILOMETERS; } } } // get optional scalebar pixel width if (preg_match("/SCALEBAR_PIXEL_WIDTH=/",$aszElements[$param_count])) { $this_element = explode( "=", $aszElements[$param_count] ); if (strlen($this_element[1]) > 0) { $scalebar_pixel_width = $this_element[1]; } } // get optional scalebar position if (preg_match("/SCALEBAR_POSITION=/",$aszElements[$param_count])) { $this_element = explode( "=", $aszElements[$param_count] ); if (strlen($this_element[1]) > 0) { $string_units = $this_element[1]; if ($string_units == 'UL') { $scalebar_position = MS_UL; } else if ($string_units == 'LR') { $scalebar_position = MS_LR; } else if ($string_units == 'UR') { $scalebar_position = MS_UR; } else if ($string_units == 'LL') { $scalebar_position = MS_LL; } else if ($string_units == 'CR') { $scalebar_position = MS_CR; } else if ($string_units == 'CL') { $scalebar_position = MS_CL; } else if ($string_units == 'UC') { $scalebar_position = MS_UC; } else if ($string_units == 'LC') { $scalebar_position = MS_LC; } else if ($string_units == 'CC') { $scalebar_position = MS_CC; } } } } if ($bRestoreLayerState) { // go ahead and set the scalebar stuff $this_scalebar = $this->oMap->scalebar; $this_scalebar->set('width',$scalebar_pixel_width); $this_scalebar->set('units',$scalebar_units); $this_scalebar->set('position',$scalebar_position); // split the string into an array if ( $aszElement[1] != "" ) { // split $anLayers = split(",",$aszElement[1] ); // want seacoos credits to always appear $seacoos_credit_layer = $this->oMap->getLayerByName('seacoos_credit'); $seacoos_url_layer = $this->oMap->getLayerByName('seacoos_url'); array_push($anLayers, $seacoos_credit_layer->index, $seacoos_url_layer->index); // put land on top of following layers (if land is turned on): // water_level_unc $world_filled_bottom_layer = $this->oMap->getLayerByName('world_filled_bottom'); $us_filled_bottom_layer = $this->oMap->getLayerByName('us_filled_bottom'); if (in_array($world_filled_bottom_layer->index,$anLayers) && in_array($us_filled_bottom_layer->index,$anLayers)) { $water_level_unc_layer = $this->oMap->getLayerByName('water_level_unc'); if (in_array($water_level_unc_layer->index,$anLayers)) { $world_filled_layer = $this->oMap->getLayerByName('world_filled'); $us_filled_layer = $this->oMap->getLayerByName('us_filled'); array_push($anLayers, $world_filled_layer->index, $us_filled_layer->index); } } $formatted_timestamp = date("Y_m_d_H_00_00", mktime(substr($aszElement_time[1],11,2), 0, 0, substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4) ) - 60*60 * $aszElement_time_zone[1] ); $sst_obs_layer = $this->oMap->getLayerByName('sst_obs'); $sst_obs_cache_layer = $this->oMap->getLayerByName('sst_obs_cache'); if (in_array($sst_obs_cache_layer->index,$anLayers)) { $ret = get_cached_image_root($this->oMap, substr($sst_obs_cache_layer->name,0, strlen($sst_obs_cache_layer->name) - strlen('_cache')), $formatted_timestamp, $aszElement_degree_units[1]); if (strlen($ret) > 0) { $sst_obs_cache_layer->set('data', $ret.'.png'); // go grab the imagemap $cmd = "cp $ret.imagemap.txt " .'/tmp/'.$aszElement_session_id[1].'.sst_obs'; `$cmd`; } else { // if not cached, put the regular layer in the queue array_push($anLayers,$sst_obs_layer->index); } } // only keep unique layer #'s $anLayers = array_unique($anLayers); $legend_sst_zoom_layer = $this->oMap->getLayerByName('legend_sst_zoom'); $legend_sst_zoom_cache_layer = $this->oMap->getLayerByName('legend_sst_zoom_cache'); if (in_array($legend_sst_zoom_cache_layer->index,$anLayers)) { $ret = get_cached_image_root($this->oMap, substr($legend_sst_zoom_cache_layer->name,0, strlen($legend_sst_zoom_cache_layer->name) - strlen('_cache')), $formatted_timestamp, $aszElement_degree_units[1]); if (strlen($ret) > 0) { $legend_sst_zoom_cache_layer->set('data', $ret.'.png'); `$cmd`; } else { // if not cached, put the regular layer in the queue array_push($anLayers,$legend_sst_zoom_layer->index); } } $wind_obs_layer = $this->oMap->getLayerByName('wind_obs'); $wind_obs_cache_layer = $this->oMap->getLayerByName('wind_obs_cache'); if (in_array($wind_obs_cache_layer->index,$anLayers)) { $ret = get_cached_image_root($this->oMap, substr($wind_obs_cache_layer->name,0, strlen($wind_obs_cache_layer->name) - strlen('_cache')), $formatted_timestamp, $aszElement_velocity_units[1]); if (strlen($ret) > 0) { $wind_obs_cache_layer->set('data', $ret.'.png'); // go grab the imagemap $cmd = "cp $ret.imagemap.txt " .'/tmp/'.$aszElement_session_id[1].'.wind_obs'; `$cmd`; } else { // if not cached, put the regular layer in the queue array_push($anLayers,$wind_obs_layer->index); } } $normalized_wind_obs_layer = $this->oMap->getLayerByName('normalized_wind_obs'); $normalized_wind_obs_cache_layer = $this->oMap->getLayerByName('normalized_wind_obs_cache'); if (in_array($normalized_wind_obs_cache_layer->index,$anLayers)) { $ret = get_cached_image_root($this->oMap, substr($normalized_wind_obs_cache_layer->name,0, strlen($normalized_wind_obs_cache_layer->name) - strlen('_cache')), $formatted_timestamp, $aszElement_velocity_units[1]); if (strlen($ret) > 0) { $normalized_wind_obs_cache_layer->set('data', $ret.'.png'); // go grab the imagemap $cmd = "cp $ret.imagemap.txt " .'/tmp/'.$aszElement_session_id[1].'.normalized_wind_obs'; `$cmd`; } else { // if not cached, put the regular layer in the queue array_push($anLayers,$normalized_wind_obs_layer->index); } } $quikscat_wind_layer = $this->oMap->getLayerByName('quikscat_wind'); $quikscat_wind_cache_layer = $this->oMap->getLayerByName('quikscat_wind_cache'); if (in_array($quikscat_wind_cache_layer->index,$anLayers)) { $ret = get_cached_image_root($this->oMap, substr($quikscat_wind_cache_layer->name,0, strlen($quikscat_wind_cache_layer->name) - strlen('_cache')), $formatted_timestamp, $aszElement_velocity_units[1]); if (strlen($ret) > 0) { $quikscat_wind_cache_layer->set('data', $ret.'.png'); // go grab the imagemap $cmd = "cp $ret.imagemap.txt " .'/tmp/'.$aszElement_session_id[1].'.quikscat_wind'; `$cmd`; } else { // if not cached, put the regular layer in the queue array_push($anLayers,$quikscat_wind_layer->index); } } sort($anLayers); reset($anLayers); } else { // otherwise default $anLayers = array(); } // initialize the array counter $j = 0; // do some global setup $sea_coos_obs_range_days = $this->oMap->getMetadata('sea_coos_obs_range_days'); $time_stamp_php_time = strtotime(substr($aszElement_time[1],0,4).'-' .substr($aszElement_time[1],5,2).'-' .substr($aszElement_time[1],8,2).' ' .substr($aszElement_time[1],11,2).':' .substr($aszElement_time[1],14,2).':' .substr($aszElement_time[1],17,4)) - $aszElement_time_zone[1] * 60*60; // Go ahead and set the units even if they aren't selected. // set the temperature units if ($aszElement_degree_units[1] == 'F') { $legend_sst_layer = $this->oMap->getLayerByName('legend_sst'); $legend_sst_layer->set('labelitem','degrees_label_fahrenheit'); $legend_sst_layer_zoom = $this->oMap->getLayerByName('legend_sst_zoom'); $legend_sst_layer_zoom->set('labelitem','deg_lab_f'); } else { $legend_sst_layer = $this->oMap->getLayerByName('legend_sst'); $legend_sst_layer->set('labelitem','degrees_label'); $legend_sst_layer_zoom = $this->oMap->getLayerByName('legend_sst_zoom'); $legend_sst_layer_zoom->set('labelitem','deg_lab'); } // set the pressure units (only used to complete the GMT grid filename if ($aszElement_pressure_units[1] == 'INCHES_MERCURY') { $pressure_units_str = '_inches_mercury'; } else { $pressure_units_str = ''; } // set the elevation units $legend_water_level_layer = $this->oMap->getLayerByName('legend_water_level'); if ($aszElement_elevation_units[1] == 'FEET') { $legend_water_level_layer->set('labelitem','water_level_label_ft'); } else { $legend_water_level_layer->set('labelitem','water_level_label'); } // set the speed units // also set the class expressions (class[0] = not_calm; class[1] = calm) $wind_obs_layer = $this->oMap->getLayerByName('wind_obs'); $normalized_wind_obs_layer = $this->oMap->getLayerByName('normalized_wind_obs'); // wind_grid's regular wind_speed = normalized_wind_speed $quickscat_wind_layer = $this->oMap->getLayerByName('quikscat_wind'); $met_wind_layer = $this->oMap->getLayerByName('met_wind'); $legend_particle_trajectory_layer = $this->oMap->getLayerByName('legend_particle_trajectory'); $legend_current_label_layer = $this->oMap->getLayerByName('legend_current_label'); if ($aszElement_velocity_units[1] == 'MPS') { $wind_obs_layer->set('labelitem','label_char'); $wind_obs_class_0 = $wind_obs_layer->getClass(0); $wind_obs_class_0->setexpression('([wind_speed] >= 3)'); $wind_obs_class_1 = $wind_obs_layer->getClass(1); $wind_obs_class_1->setexpression('([wind_speed] < 3)'); $normalized_wind_obs_layer->set('labelitem','normalized_label_char'); $normalized_wind_obs_class_0 = $normalized_wind_obs_layer->getClass(0); $normalized_wind_obs_class_0->setexpression('([normalized_wind_speed] >= 3)'); $normalized_wind_obs_class_1 = $normalized_wind_obs_layer->getClass(1); $normalized_wind_obs_class_1->setexpression('([normalized_wind_speed] < 3)'); $quickscat_wind_layer->set('labelitem','label_char'); $quickscat_wind_class_0 = $quickscat_wind_layer->getClass(0); $quickscat_wind_class_0->setexpression('([wind_speed] >= 3)'); $quickscat_wind_class_1 = $quickscat_wind_layer->getClass(1); $quickscat_wind_class_1->setexpression('([wind_speed] < 3)'); $met_wind_layer->set('labelitem','label_char'); $met_wind_class_0 = $met_wind_layer->getClass(0); $met_wind_class_0->setexpression('([wind_speed] >= 3)'); $met_wind_class_1 = $met_wind_layer->getClass(1); $met_wind_class_1->setexpression('([wind_speed] < 3)'); $legend_particle_trajectory_layer->set('labelitem','speed_label'); $legend_current_label_layer->setmetadata('LABEL_PREFIX', $legend_current_label_layer->getmetadata('LABEL_PREFIX').' '); } else if ($aszElement_velocity_units[1] == 'KNOTS') { $wind_obs_layer->set('labelitem','label_char_knots'); $wind_obs_class_0 = $wind_obs_layer->getClass(0); $wind_obs_class_0->setexpression('([wind_speed_knots] >= 3)'); $wind_obs_class_1 = $wind_obs_layer->getClass(1); $wind_obs_class_1->setexpression('([wind_speed_knots] < 3)'); $normalized_wind_obs_layer->set('labelitem','normalized_label_char_knots'); $normalized_wind_obs_class_0 = $normalized_wind_obs_layer->getClass(0); $normalized_wind_obs_class_0->setexpression('([normalized_wind_speed_knots] >= 3)'); $normalized_wind_obs_class_1 = $normalized_wind_obs_layer->getClass(1); $normalized_wind_obs_class_1->setexpression('([normalized_wind_speed_knots] < 3)'); $quickscat_wind_layer->set('labelitem','label_char_knots'); $quickscat_wind_class_0 = $quickscat_wind_layer->getClass(0); $quickscat_wind_class_0->setexpression('([wind_speed_knots] >= 3)'); $quickscat_wind_class_1 = $quickscat_wind_layer->getClass(1); $quickscat_wind_class_1->setexpression('([wind_speed_knots] < 3)'); $met_wind_layer->set('labelitem','label_char_knots'); $met_wind_class_0 = $met_wind_layer->getClass(0); $met_wind_class_0->setexpression('([wind_speed_knots] >= 3)'); $met_wind_class_1 = $met_wind_layer->getClass(1); $met_wind_class_1->setexpression('([wind_speed_knots] < 3)'); $legend_particle_trajectory_layer->set('labelitem','speed_label_knots'); $legend_current_label_layer->setmetadata('FULL_SCALE_VALUE', $legend_current_label_layer->getmetadata('FULL_SCALE_VALUE_KNOTS')); $legend_current_label_layer->setmetadata('LABEL_SUFFIX', $legend_current_label_layer->getmetadata('LABEL_SUFFIX_KNOTS')); } else if ($aszElement_velocity_units[1] == 'MPH') { $wind_obs_layer->set('labelitem','label_char_mph'); $wind_obs_class_0 = $wind_obs_layer->getClass(0); $wind_obs_class_0->setexpression('([wind_speed_mph] >= 3)'); $wind_obs_class_1 = $wind_obs_layer->getClass(1); $wind_obs_class_1->setexpression('([wind_speed_mph] < 3)'); $normalized_wind_obs_layer->set('labelitem','normalized_label_char_mph'); $normalized_wind_obs_class_0 = $normalized_wind_obs_layer->getClass(0); $normalized_wind_obs_class_0->setexpression('([normalized_wind_speed_mph] >= 3)'); $normalized_wind_obs_class_1 = $normalized_wind_obs_layer->getClass(1); $normalized_wind_obs_class_1->setexpression('([normalized_wind_speed_mph] < 3)'); $quickscat_wind_layer->set('labelitem','label_char_mph'); $quickscat_wind_class_0 = $quickscat_wind_layer->getClass(0); $quickscat_wind_class_0->setexpression('([wind_speed_mph] >= 3)'); $quickscat_wind_class_1 = $quickscat_wind_layer->getClass(1); $quickscat_wind_class_1->setexpression('([wind_speed_mph] < 3)'); $met_wind_layer->set('labelitem','label_char_mph'); $met_wind_class_0 = $met_wind_layer->getClass(0); $met_wind_class_0->setexpression('([wind_speed_mph] >= 3)'); $met_wind_class_1 = $met_wind_layer->getClass(1); $met_wind_class_1->setexpression('([wind_speed_mph] < 3)'); $legend_particle_trajectory_layer->set('labelitem','speed_label_mph'); $legend_current_label_layer->setmetadata('FULL_SCALE_VALUE', $legend_current_label_layer->getmetadata('FULL_SCALE_VALUE_MPH')); $legend_current_label_layer->setmetadata('LABEL_SUFFIX', $legend_current_label_layer->getmetadata('LABEL_SUFFIX_MPH')); $legend_current_label_layer->setmetadata('LABEL_PREFIX', $legend_current_label_layer->getmetadata('LABEL_PREFIX').' '); } // loop through all the layers and set their values for ($i=0;$i<$this->oMap->numlayers;$i++) { // get layer object $oLayer = $this->oMap->getlayer($i); // check if the current layer matches the "ON" array if ( $i == $anLayers[$j] ) { // log the check $this->log(LOG_QUIET,"Layer ".$i." is ON."); // turn the layer on $oLayer->set("status",MS_ON); // turn off the in-situ legend if other RS SST layers are on $avhrr_sst_layer = $this->oMap->getLayerByName('avhrr_sst'); $modis_sst_layer = $this->oMap->getLayerByName('modis_sst'); $oi_sst_layer = $this->oMap->getLayerByName('oi_sst'); $sst_zoom_legend = $this->oMap->getLayerByName('legend_sst_zoom'); $sst_zoom_cache_legend = $this->oMap->getLayerByName('legend_sst_zoom_cache'); if ($avhrr_sst_layer->status == MS_ON || $modis_sst_layer->status == MS_ON || $oi_sst_layer->status == MS_ON) { $sst_zoom_legend->set('status',MS_OFF); $sst_zoom_cache_legend->set('status',MS_OFF); } // only one colorbar can be diplayed at a time // hi to low order is SST : Chl : water_level : legend_particle_trajectory : tamu_level_III $modis_chl_legend_carib_layer = $this->oMap->getLayerByName('modis_chl_legend_carib'); $legend_water_level_layer = $this->oMap->getLayerByName('legend_water_level'); $legend_particle_trajectory_layer = $this->oMap->getLayerByName('legend_particle_trajectory'); $tamu_level_III_legend_carib = $this->oMap->getLayerByName('tamu_level_III_legend_carib'); if ($avhrr_sst_layer->status == MS_ON || $modis_sst_layer->status == MS_ON || $oi_sst_layer->status == MS_ON || $sst_zoom_legend->status == MS_ON || $sst_zoom_cache_legend->status == MS_ON) { $tamu_level_III_legend_carib->set('status',MS_OFF); $modis_chl_legend_carib_layer->set('status',MS_OFF); $legend_water_level_layer->set('status',MS_OFF); $legend_particle_trajectory_layer->set('status',MS_OFF); } else if ($modis_chl_legend_carib_layer->status == MS_ON) { $legend_water_level_layer->set('status',MS_OFF); $legend_particle_trajectory_layer->set('status',MS_OFF); $tamu_level_III_legend_carib->set('status',MS_OFF); } else if ($legend_water_level_layer->status == MS_ON) { $legend_particle_trajectory_layer->set('status',MS_OFF); $tamu_level_III_legend_carib->set('status',MS_OFF); } else if ($legend_particle_trajectory_layer->status == MS_ON) { $tamu_level_III_legend_carib->set('status',MS_OFF); } // cpurvis // set the FILTER part of a layer that needs a time_stamp if ( $oLayer->name == 'wind_obs' && $aszElement_time[1] != "" ) { if ($time_stamp_php_time < (time() - 60*60*24*$sea_coos_obs_range_days)) { $oLayer->set('connection', 'user=postgres dbname=sea_coos_obs_archive host=nemo.baruch.sc.edu'); $archive_flag = 1; } $oLayer->setFilter( '(report_time_stamp ' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'))' ); $this_filter = '(report_time_stamp ' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'))'; if (strlen($aszElement_session_id[1]) > 0 && $mk_imagemap) $this_imagemap = mk_imagemap($this->oMap, 'wind_obs', $this_filter, $aszElement_session_id[1].'.wind_obs', $aszElement_velocity_units[1], $archive_flag); } elseif ( stristr($oLayer->name, 'particle_trajectories_old_') && $aszElement_time[1] != "" ) { // get # of real dots we're showing $particle_trajectories_layer = $this->oMap->getLayerByName('particle_trajectories_' .substr($oLayer->name,strlen('particle_trajectories_old_'))); $num_showing_particles = $particle_trajectories_layer->numclasses; // make all points < now white $oLayer->setFilter( '(date_trunc(\'hour\',time_stamp + ' .'interval \'1 hour\' * ' .$aszElement_time_zone[1] .') < ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\')' .'and (lower(institution_code) = \'' .substr($oLayer->name,strlen('particle_trajectories_old_')) .'\')' .')' ); } elseif ( stristr($oLayer->name,'particle_trajectories_') && $aszElement_time[1] != "" ) { // cpurvis // for now, set an expression for each of the 5 classes $num_classes = $oLayer->numclasses; for ($q = 0;$q < $num_classes; $q++) { $this_class = $oLayer->getClass($q); $time_stamp = date('Y-m-d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1] - 60*60*$q ); $this_class->setexpression($time_stamp); } $oLayer->setFilter('(lower(institution_code) = \'' .substr($oLayer->name,strlen('particle_trajectories_')) .'\')'); } elseif ( stristr($oLayer->name,'particle_line_trajectories_') && $aszElement_time[1] != "" ) { $oLayer->setFilter( '(time_stamp <= ' .'timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'and (lower(institution_code) = \'' .substr($oLayer->name,strlen('particle_line_trajectories_')) .'\')' .')' ); } elseif ( stristr($oLayer->name,'particle_head_trajectories_point') && $aszElement_time[1] != "" ) { $oLayer->setFilter( '(time_stamp = ' .'timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'and (lower(institution_code) = \'' .substr($oLayer->name,strlen('particle_head_trajectories_point_')) .'\')' .')' ); } elseif ( stristr($oLayer->name,'particle_head_trajectories_') && $aszElement_time[1] != "" ) { $oLayer->setFilter( '(time_stamp = ' .'timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'and (lower(institution_code) = \'' .substr($oLayer->name,strlen('particle_head_trajectories_')) .'\')' .')' ); } elseif ( $oLayer->name == 'quikscat_wind' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=neptune.baruch.sc.edu"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select pass_timestamp, min_lon, min_lat from grid_quickscat_wind_composite" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from grid_quickscat_wind_composite)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) { $time_filter = "report_time_stamp = timestamp without time zone" ." '$row[0]'"; $this_min_lon = $row[1]; $this_min_lat = $row[2]; } else { $time_filter = "1 = 2"; $this_min_lon = 0; $this_min_lat = 0; } // calculate SCALE (used for quikscat and met_wind) $gd = $this->oMap->extent->maxx - $this->oMap->extent->minx; $md = ($this->oMap->width - 1) / (72 * 39.3701); $map_scale = abs($gd / $md); $this_scale = round($map_scale * 4 / 140); if ($this_scale <= 1) { $this_scale = 1; } else if ($this_scale >= 5) { $this_scale = 5; } $oLayer->setFilter("$time_filter"); $oLayer->set('data',"the_geom from quickscat_wind_composite_scale_$this_scale USING UNIQUE seq"); } elseif ( $oLayer->name == 'met_wind' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_model user=postgres host=nemo.baruch.sc.edu"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select time_stamp, min_lon, min_lat from grid_met_wind" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from grid_met_wind)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) { $time_filter = "time_stamp = timestamp without time zone" ." '$row[0]'"; $this_min_lon = $row[1]; $this_min_lat = $row[2]; } else { $time_filter = "1 = 2"; $this_min_lon = 0; $this_min_lat = 0; } // calculate SCALE (used for quikscat and met_wind) $gd = $this->oMap->extent->maxx - $this->oMap->extent->minx; $md = ($this->oMap->width - 1) / (72 * 39.3701); $map_scale = abs($gd / $md); $this_scale = round($map_scale * 4 / 140); if ($this_scale <= 1) { $this_scale = 1; } else if ($this_scale >= 5) { $this_scale = 5; } $oLayer->setFilter("$time_filter"); $oLayer->set('data',"the_geom from met_wind_unc_prod_scale_$this_scale USING UNIQUE seq"); } elseif ( $oLayer->name == 'met_air_pressure_contour' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_model user=postgres host=nemo.baruch.sc.edu"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select to_char(time_stamp,'YYYY_MM_DD_HH24_MI_SS')" ." from grid_met_sea_level_pressure" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from grid_met_sea_level_pressure)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from time_stamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) { $grd_filename = '/usr2/maps/seacoos/data' .'/model_gmt_grids/met_sea_level_pressure'.$pressure_units_str.'_unc_prod_' .$row[0].'.grd'; $img = mk_contour($this->oMap,$oLayer->name,$grd_filename,time().'_'.rand(1000,9999)); $oLayer->set('data',$img); } } elseif ( $oLayer->name == 'normalized_wind_obs' && $aszElement_time[1] != "" ) { if ($time_stamp_php_time < (time() - 60*60*24*$sea_coos_obs_range_days)) { $oLayer->set('connection', 'user=postgres dbname=sea_coos_obs_archive host=nemo.baruch.sc.edu'); $archive_flag = 1; } $oLayer->setFilter( '(report_time_stamp ' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .') and can_be_normalized = \'yes\')' ); $this_filter = '(report_time_stamp ' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .') and can_be_normalized = \'yes\')'; if (strlen($aszElement_session_id[1]) > 0 && $mk_imagemap) $this_imagemap = mk_imagemap($this->oMap, 'normalized_wind_obs', $this_filter, $aszElement_session_id[1].'.normalized_wind_obs', $aszElement_velocity_units[1], $archive_flag); } elseif ( $oLayer->name == 'wind_obs_png' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $oLayer->set('data', './stage/wind_' .substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00' // ss .'.png' ); } elseif ( $oLayer->name == 'sst_obs' && $aszElement_time[1] != "" ) { if ($time_stamp_php_time < (time() - 60*60*24*$sea_coos_obs_range_days)) { $oLayer->set('connection', 'user=postgres dbname=sea_coos_obs_archive host=nemo.baruch.sc.edu'); $archive_flag = 1; } $oLayer->setFilter( '(report_time_stamp' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .')' .' and (label_z <= 5 or label_z is null)' .')' ); $this_filter = '(report_time_stamp ' .' = ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .')' .' and (label_z <= 5 or label_z is null)' .')'; if (strlen($aszElement_session_id[1]) > 0 && $mk_imagemap) $this_imagemap = mk_imagemap($this->oMap, 'sst_obs', $this_filter, $aszElement_session_id[1].'.sst_obs',$aszElement_degree_units[1], $archive_flag); } elseif ( $oLayer->name == 'sst_obs_png' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $oLayer->set('data', './stage/sst_' .substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00' // ss .'.png' ); } elseif ( $oLayer->name == 'nhc_storm_tracks_line' && $aszElement_time[1] != "" ) { $time_stamp = date('Y-m-d H:i:s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $val = build_nhc_storm_track_filters ($time_stamp); if (strlen($val['line']) > 0) { $oLayer->setFilter('('.$val['line'].')'); } else { $oLayer->setFilter('(1=2)'); } } elseif ( $oLayer->name == 'nhc_storm_tracks_point' && $aszElement_time[1] != "" ) { $time_stamp = date('Y-m-d H:i:s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $val = build_nhc_storm_track_filters ($time_stamp); if (strlen($val['point']) > 0) { $oLayer->setFilter('('.$val['point'].')'); } else { $oLayer->setFilter('(1=2)'); } } elseif ( $oLayer->name == 'nhc_storm_tracks_now_point' && $aszElement_time[1] != "" ) { $time_stamp = date('Y-m-d H:i:s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $val = build_nhc_storm_track_filters ($time_stamp); if (strlen($val['now_point']) > 0) { $oLayer->setFilter('('.$val['now_point'].')'); } else { $oLayer->setFilter('(1=2)'); } } elseif ( $oLayer->name == 'nhc_storm_tracks_now_label' && $aszElement_time[1] != "" ) { $time_stamp = date('Y-m-d H:i:s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $val = build_nhc_storm_track_filters ($time_stamp); if (strlen($val['now_label']) > 0) { $oLayer->setFilter('('.$val['now_label'].')'); } else { $oLayer->setFilter('(1=2)'); } } elseif ( $oLayer->name == 'avhrr_sst' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_avhrr_sst" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_avhrr_sst)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'oi_sst' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_oi_sst" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_oi_sst)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*3"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_sst' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_sst" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_sst)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'tamu_level_III' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_tamu_level_III" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_tamu_level_III)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'tamu_usrad' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_tamu_usrad" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_tamu_usrad)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_composite' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_composite" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_composite)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_ergb_composite' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_ergb_composite" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_ergb_composite)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_chesapeake_bay' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_chesapeake_bay" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_chesapeake_bay)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_florida_bay' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_florida_bay" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_florida_bay)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_miss_plume' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_miss_plume" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_miss_plume)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_suwannee_river' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_suwannee_river" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_suwannee_river)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_rgb_tampa_bay' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_rgb_tampa_bay" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_rgb_tampa_bay)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_ergb' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_ergb" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_ergb)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'modis_chl' && $aszElement_time[1] != "" ) { $time_stamp = date('Y/m/d H:i:s', mktime(substr($aszElement_time[1],11,2), substr($aszElement_time[1],14,2), substr($aszElement_time[1],17,2), substr($aszElement_time[1],5,2), substr($aszElement_time[1],8,2), substr($aszElement_time[1],0,4))); $conn = pg_pconnect("dbname=sea_coos_obs user=postgres host=localhost"); if (!$conn) { echo "An error occured.\n"; exit; } $querystr = "select local_filename from raster_modis_chl" ." where abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." = (select min(abs((extract(epoch from timestamp without time zone '$time_stamp'))" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1])))" ." from raster_modis_chl)" ." and abs(extract(epoch from timestamp without time zone '$time_stamp')" ." - extract(epoch from pass_timestamp + interval '1 hour' * $aszElement_time_zone[1]))" ." <= 60*60*24*2"; $result = pg_query($conn, $querystr); $row = pg_fetch_row($result, 0); if (strlen($row[0]) > 0) $oLayer->set('data', './usf/'.$row[0]); else $oLayer->set('data', ''); } elseif ( $oLayer->name == 'legend_sst_zoom' && $aszElement_time[1] != "" ) { if ($time_stamp_php_time < (time() - 60*60*24*$sea_coos_obs_range_days)) { $oLayer->set('connection', 'user=postgres dbname=sea_coos_obs_archive host=nemo.baruch.sc.edu'); $archive_flag = 1; } $time_stamp = date('Y/m/d H:00:00',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $legend_file = mk_legend_sst($this->oMap,$time_stamp, $legend_offsets[0], $legend_offsets[1], $archive_flag); $oLayer->set('data',$legend_file); } elseif ( $oLayer->name == 'legend_sst' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $legend_offsets[0]/100 * ($this->oMap->width); $y_offset = $legend_offsets[1]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select degrees_label, degrees_value, rgb, map_size,' .' degrees_label_fahrenheit, degrees_value_fahrenheit, oid,' .' translate(the_geom,' .$x_offset.'-697.5,'.$y_offset.'-371.25,0)' .' as the_geom from' .' sst_legend_carib' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'legend_water_level' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $legend_offsets[0]/100 * ($this->oMap->width); $y_offset = $legend_offsets[1]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select water_level_label, water_level_value, rgb, map_size, oid, water_level_label_ft,' .' translate(the_geom,' .$x_offset.'-697.5,'.$y_offset.'-371.25,0)' .' as the_geom from' .' zetai_legend_carib' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'legend_particle_trajectory' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $legend_offsets[0]/100 * ($this->oMap->width); $y_offset = $legend_offsets[1]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select speed_label, speed_value, rgb, map_size, oid,' .' speed_value_knots, speed_label_knots,' .' speed_value_mph, speed_label_mph,' .' translate(the_geom,' .$x_offset.'-697.5,'.$y_offset.'-371.25,0)' .' as the_geom from' .' particle_trajectory_legend_carib' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'modis_chl_legend_carib' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $legend_offsets[0]/100 * ($this->oMap->width); $y_offset = $legend_offsets[1]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select chl_label, chl_value, rgb, map_size, oid,' .' translate(the_geom,' .$x_offset.'-697.5,'.$y_offset.'-371.25,0)' .' as the_geom from' .' modis_chl_legend_carib' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'tamu_level_III_legend_carib' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $legend_offsets[0]/100 * ($this->oMap->width); $y_offset = $legend_offsets[1]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select reflectivity_label, reflectivity_value, rgb, map_size, oid,' .' translate(the_geom,' .$x_offset.'-697.5,'.$y_offset.'-371.25,0)' .' as the_geom from' .' tamu_level_III_legend_carib' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'toolbar_box' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $val = 'the_geom from' .' (select ' .' oid, translate(the_geom,' .$this->oMap->width.'-697.5,0,0)' .' as the_geom from' .' toolbar_box_polygon' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'seacoos_credit' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $seacoos_credit_offsets[1]/100 * ($this->oMap->width); $y_offset = $seacoos_credit_offsets[2]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select ' .' oid, translate(the_geom,' ."$x_offset,$y_offset,0)" .' as the_geom from' .' seacoos_credit' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'seacoos_url' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $x_offset = $seacoos_url_offsets[1]/100 * ($this->oMap->width); $y_offset = $seacoos_url_offsets[2]/100 * ($this->oMap->height); $val = 'the_geom from' .' (select ' .' oid, translate(the_geom,' ."$x_offset,-$y_offset + ".$this->oMap->height.'-371.25,0)' .' as the_geom from' .' seacoos_url' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'seacoos_credit_background' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $val = 'the_geom from' .' (select ' .' oid, translate(the_geom,' .'0,'.$this->oMap->height.'-371.25,0)' .' as the_geom from' .' seacoos_credit_background' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'legend_current_arrow' ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $val = 'the_geom from' .' (select ' .' oid, type, translate(the_geom,' .$this->oMap->width.'-697.5,0,0)' .' as the_geom from' .' legend_current_arrow' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); } elseif ( $oLayer->name == 'obs_site' && $aszElement_time[1] != "" ) { if ($time_stamp_php_time < (time() - 60*60*24*$sea_coos_obs_range_days)) { $oLayer->set('connection', 'user=postgres dbname=sea_coos_obs_archive host=nemo.baruch.sc.edu'); $archive_flag = 1; } $oLayer->setFilter( '(report_time_stamp ' .' >= ' .'(date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .') - interval \'2 days\') ' .'and ' .'report_time_stamp ' .' <= ' .'date_trunc(\'hour\',timestamp without time zone \'' .substr($aszElement_time[1],0,4).'-' // yyyy .substr($aszElement_time[1],5,2).'-' // mm .substr($aszElement_time[1],8,2).' ' // dd .substr($aszElement_time[1],11,2).':' // hh .substr($aszElement_time[1],14,2).':' // mm .substr($aszElement_time[1],17,4) // ss .'\' - interval \'1 hour\' * ' .$aszElement_time_zone[1] .'))' ); } elseif ( $oLayer->name == 'obs_site_png' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $oLayer->set('data', './stage/obs_site_' .substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00' // ss .'.png' ); } elseif ( $oLayer->name == 'current' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'bari_merged_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'bari_merged_'.$local_time_stamp_str .' USING UNIQUE seq'); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } // cpurvis // need to do some scaling so that it isn't to cluttered // the constant was taken from carib_extents_scale $this_scale = $this->oMap->scale; if ($this_scale < 3600000) $this_scale = 1; else $this_scale = round($this->oMap->scale * (5 / 25198583.04)); $this_incr = $oLayer->getMetaData("grid_increment"); $this_min_lon = $oLayer->getMetaData("min_lon"); $this_min_lat = $oLayer->getMetaData("min_lat"); $this_val = "(abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0 "; $oLayer->setFilter("((abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0)"); } elseif ( $oLayer->name == 'water_level' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'zetai_merged_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'zetai_merged_'.$local_time_stamp_str .' USING UNIQUE seq'); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'water_level_usf' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'zetai_usf_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'zetai_usf_'.$local_time_stamp_str .' USING UNIQUE seq'); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'water_level_um' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'zetai_um_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'zetai_um_'.$local_time_stamp_str .' USING UNIQUE seq'); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'water_level_unc' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'zetai_unc_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'zetai_unc_'.$local_time_stamp_str .' USING UNIQUE seq'); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'current_usf' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'bari_usf_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'bari_usf_'.$local_time_stamp_str .' USING UNIQUE seq'); // cpurvis // need to do some scaling so that it isn't to cluttered // the constant was taken from carib_extents_scale $this_scale = $this->oMap->scale; if ($this_scale < 3600000) $this_scale = 1; else $this_scale = round($this->oMap->scale * (6 / 25198583.04)); $this_incr = $oLayer->getMetaData("grid_increment"); $this_min_lon = $oLayer->getMetaData("min_lon"); $this_min_lat = $oLayer->getMetaData("min_lat"); $this_val = "(abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0 "; $oLayer->setFilter("((abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0)"); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'current_um' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'bari_um_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'bari_um_'.$local_time_stamp_str .' USING UNIQUE seq'); // cpurvis // need to do some scaling so that it isn't to cluttered // the constant was taken from carib_extents_scale $this_scale = $this->oMap->scale; if ($this_scale < 3600000) $this_scale = 1; else $this_scale = round($this->oMap->scale * (6 / 25198583.04)); $this_incr = $oLayer->getMetaData("grid_increment"); $this_min_lon = $oLayer->getMetaData("min_lon"); $this_min_lat = $oLayer->getMetaData("min_lat"); $this_val = "(abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0 "; $oLayer->setFilter("((abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0)"); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'current_unc' && $aszElement_time[1] != "" ) { $time_stamp = date('Y_m_d_H_i_s',mktime(substr($aszElement_time[1],11,2),substr($aszElement_time[1],14,2),substr($aszElement_time[1],17,2),substr($aszElement_time[1],5,2),substr($aszElement_time[1],8,2),substr($aszElement_time[1],0,4)) - 60*60*$aszElement_time_zone[1]); $local_time_stamp_str = substr($time_stamp,0,4).'_' // yyyy .substr($time_stamp,5,2).'_' // mm .substr($time_stamp,8,2).'_' // dd .substr($time_stamp,11,2).'_' // hh .'00'.'_' // mm .'00'; // ss $this_tablename = 'bari_unc_'.$local_time_stamp_str; if ( check_table_in_db($this_tablename) == 1 ) { $oLayer->set('data', 'the_geom from ' .'bari_unc_'.$local_time_stamp_str .' USING UNIQUE seq'); // cpurvis // need to do some scaling so that it isn't to cluttered // the constant was taken from carib_extents_scale $this_scale = $this->oMap->scale; if ($this_scale < 3600000) $this_scale = 1; else $this_scale = round($this->oMap->scale * (6 / 25198583.04)); $this_incr = $oLayer->getMetaData("grid_increment"); $this_min_lon = $oLayer->getMetaData("min_lon"); $this_min_lat = $oLayer->getMetaData("min_lat"); $this_val = "(abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0 "; $oLayer->setFilter("((abs(xi::numeric) - $this_min_lon) % ($this_scale * $this_incr) = 0 and (abs(yi::numeric) - $this_min_lat) % ($this_scale * $this_incr) = 0)"); } else { if ( stristr ( $oLayer->name, 'current') ) $oLayer->set('data','the_geom from empty_bari'); else $oLayer->set('data','the_geom from empty_zetai'); } } elseif ( $oLayer->name == 'legend_current_label' && $aszElement_time[1] != "" ) { # compute the position of the legend dynamically # use original /rs map dims to compute offset $val = 'the_geom from' .' (select ' .' oid, type, translate(the_geom,' .$this->oMap->width.'-697.5,0,0)' .' as the_geom from' .' legend_current_arrow' .') as foo USING UNIQUE oid USING SRID=-1'; $oLayer->set('data',$val); $this_scale = $this->oMap->scale; $full_scale_value = $oLayer->getMetaData("full_scale_value"); $label_prefix = $oLayer->getMetaData("label_prefix"); $label_suffix = $oLayer->getMetaData("label_suffix"); $map_full_scale = $oLayer->getMetaData("map_full_scale"); $label_text = $label_prefix .sprintf("%1.2f",$full_scale_value * ($this_scale / $map_full_scale)) .$label_suffix; $label_class = $oLayer->getClass(0); $name = $label_class->name; $val = $label_class->settext($oLayer, $label_text); } // get next item in the array $j++; } else { // log the check $this->log(LOG_QUIET,"Layer ".$i." is OFF."); // turn the layer on $oLayer->set("status",MS_OFF); } } $imagemap_sst_file = file_exists('/tmp/'.$aszElement_session_id[1].'.sst_obs'); $imagemap_normalized_wind_file = file_exists('/tmp/'.$aszElement_session_id[1].'.normalized_wind_obs'); $imagemap_wind_file = file_exists('/tmp/'.$aszElement_session_id[1].'.wind_obs'); // let the normalized winds override the winds if ($imagemap_normalized_wind_file) { $cmd = "cp /tmp/$aszElement_session_id[1].normalized_wind_obs /tmp/$aszElement_session_id[1].wind_obs"; `$cmd`; $imagemap_wind_file = $imagemap_normalized_wind_file; } if ($imagemap_sst_file) { if ($imagemap_wind_file) { // merge them $cmd = "/usr/bin/perl /usr2/maps/seacoos/util/mergemaps.pl obs_imagemap /tmp/$aszElement_session_id[1].sst_obs /tmp/$aszElement_session_id[1].wind_obs /tmp/$aszElement_session_id[1]"; `$cmd`; } else { $cmd = "cp /tmp/$aszElement_session_id[1].sst_obs /tmp/$aszElement_session_id[1]"; `$cmd`; } } else if ($imagemap_wind_file) { $cmd = "cp /tmp/$aszElement_session_id[1].wind_obs /tmp/$aszElement_session_id[1]" ; `$cmd`; } } //log exit $this->logFuncEnd( LOG_ALL, "restoreState() done" ); // return success return true; // end the restoreState function } /** * This function reads the given map object and builds a string to * to represent the state of the file in terms of: * 1) extents - key is "BBOX", values are space de-limited. * 2) projection - key is "SRS". * 3) map size - key is "MAPSIZE", values are comma de-limited. * 4) active layers - key is "LAYERS", values are comma de-limited. * * The three sections of the string will be separated by a "|". Each * individual section will be in the following format: * key=value (i.e. BBOX=0 0 100 100) * * @param oMap - Map file object to read. * @param aszExcludeKeys - Dont save Keys specified in array * * @return string - The state ID representing the current state if the * give map file. */ function buildStateID( $oMap, $aszExcludeKeys = array() ) { // initialize the return string $szReturn = ""; // get the current extents if (!in_array("BBOX", $aszExcludeKeys)) $szReturn = "BBOX=".$oMap->extent->minx.",".$oMap->extent->miny.",". $oMap->extent->maxx.",".$oMap->extent->maxy; // get the current map projection if (!in_array("RSR", $aszExcludeKeys)) $szReturn .= "|SRS=".$oMap->getProjection(); // get the current map size if (!in_array("MAPSIZE", $aszExcludeKeys)) $szReturn .= "|MAPSIZE=".$oMap->width.",".$oMap->height; // build the list of active layers if (!in_array("LAYERS", $aszExcludeKeys)) { $szReturn .= "|LAYERS="; // get the drawing order $anDrawingOrder = $oMap->getlayersdrawingorder(); // loop to build list foreach ( $anDrawingOrder as $nIndex ) { // create the layer object $oLayer = $oMap->getlayer( $nIndex );; // check it's status and add if on if ( $oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT ) { $szReturn .= $oLayer->index.","; } } // remove the trailing "," $szReturn = substr($szReturn,0,strlen($szReturn)-1); } // cpurvis if (!in_array("IMAGEMAP_SESSION_ID")) { $szReturn .= '|IMAGEMAP_SESSION_ID='.$oMap->getMetaData('imagemap_session_id'); } // cpurvis if (!in_array("DEGREE_UNITS")) { $szReturn .= '|DEGREE_UNITS='.$oMap->getMetaData('degree_units'); } // cpurvis if (!in_array("VELOCITY_UNITS")) { $szReturn .= '|VELOCITY_UNITS='.$oMap->getMetaData('velocity_units'); } // cpurvis if (!in_array("PRESSURE_UNITS")) { $szReturn .= '|PRESSURE_UNITS='.$oMap->getMetaData('pressure_units'); } // cpurvis if (!in_array("ELEVATION_UNITS")) { $szReturn .= '|ELEVATION_UNITS='.$oMap->getMetaData('elevation_units'); } // cpurvis if (!in_array("TIME_STAMP", $aszExcludeKeys) && !in_array("TIME_ZONE", $aszExcludeKeys)) { // loop to build list foreach ( $anDrawingOrder as $nIndex ) { // create the layer object $oLayer = $oMap->getlayer( $nIndex ); // check it's status and add if on if ( $oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT ) { // cpurvis // pull time_stamp from header if ( stristr ( $oLayer->name, 'wind' ) ) { $time_stamp .= substr($oLayer->header, strlen($oLayer->header)-strlen('yyyy_mm_dd_hh_mm_ss')); $time_zone = $oLayer->footer; } elseif ( stristr ( $oLayer->name, 'sst' ) ) { $time_stamp .= substr($oLayer->header, strlen($oLayer->header)-strlen('yyyy_mm_dd_hh_mm_ss')); $time_zone = $oLayer->footer; } } } } if (strlen($time_stamp) > 0 && strlen($time_zone) > 0) { // append the time_stamp $szReturn .= '|TIME_STAMP='.$time_stamp.'|TIME_ZONE='.$time_zone; } // return the string return $szReturn; } // end MapSession_R class } /** * This class extends the base MapSession Class to allow a save and restore * state option. This class is the read-write version meaning that the save & * restore sessions will write/read to the physical disk. There is also a read- * only version of this class called MapSession_R * It is assummed that the phpmapscript module is loaded prior to * instantiaiting this class. * * @author William A. Bronsema, C.E.T. (bronsema@dmsolutions.ca) * */ class MapSession_RW extends MapSession { /** * Construct a new MapSession instance and initialize it. */ function MapSession_RW() { // call the constructor for the map session base class $this->MapSession(); // set the scope for the logging functions $this->setScope( "MapSession_RW" ); // end constructor } /** * This function saves the current state of the map. * It requires that the temp directory been set. * * @return string - A unique state ID or "" if failed. */ function saveState() { //log entry $this->logFuncStart( LOG_VERBOSE, "saveState() starting" ); // check to see if the temp directory has been set if ( !isset($this->szTempDir) ) { // log error $this->error( ERR_FILE_IO, "The temp directory has not been set." ); // return failure return ""; } // check to see if the temp directory is a valid directory if ( !is_dir($this->szTempDir) ) { // log error $this->error( ERR_FILE_IO, "The temp directory[".$this->szTempDir. "] does not exist." ); // return failure return ""; } // get the unique state identifier $szStateID = time()."-".rand(1000,9999); // log the result $this->log( LOG_VERBOSE, "saveState new ID = ".$szStateID ); // write the PrevStateID to the map object //$this->oMap->setmetadata( "PrevStateID", $this->szPrevStateID ); // write the map to a temp directory if ( !$this->writeMapFile( $this->szTempDir.$szStateID.".map" ) ) return ""; // update the previous state id //$this->szPrevStateID = $szStateID; //log exit $this->logFuncEnd( LOG_ALL, "saveState() done" ); // return ID return $szStateID; // end the saveState function } /** * This function restores the state of a map file by opening the map file * in the temp directory corresponding to the supplied ID. The restored * state becomes the current map object. * It requires that the temp directory been set. * * @param szStateID - Optional unique state ID. * @param szMapFile - Optional mapfile to restore state to. * @param szMapFilePath - Optional mapfile path to restore state to. * * @return boolean - True if successful, false if not. */ function restoreState( $szStateID = "", $szMapFile = "", $szMapFilePath = "" ) { //log entry $this->logFuncStart( LOG_VERBOSE, "restoreState() starting" ); // check if map file was supplied if ( $szMapFile == "" ) $szMapFile = $this->szMapFile; // check for a valid mapfile if ( $szMapFile == "" ) { // log error $this->error( ERR_FILE_IO, "The map file has not been set." ); // return failure return "false"; } // if no state given then just open the map if ( $szStateID == "" ) { // check for success if ( !$this->readMapFile($szMapFile, $szMapFilePath) ) return false; else $this->logFuncEnd( LOG_ALL, "restoreState() done" ); return true; } // check to see if the temp directory has been set if ( !isset($this->szTempDir) ) { // log error $this->error( ERR_FILE_IO, "The temp directory has not been set." ); // return failure return "false"; } // check to see if the temp directory is a valid directory if ( !is_dir($this->szTempDir) ) { // log error $this->error( ERR_FILE_IO, "The temp directory[".$this->szTempDir. "] does not exist." ); // return failure return "false"; } // build the map names $szSessionMap = $this->szTempDir.$szStateID.".map"; // check for a valid session map file if( !file_exists($szSessionMap) ) { // log error $this->error( ERR_FILE_IO, "The requested map session file[". $szSessionMap."] does not exist." ); // return failure return "false"; } // attempt to open the map if ( !$this->readMapFile( $szSessionMap, $szMapFilePath ) ) return false; // log the result $this->log( LOG_QUIET, "restoreState - successful for ID [". $szStateID."]." ); //log exit $this->logFuncEnd( LOG_ALL, "restoreState() done" ); // return success return true; // end the restoreState function } // end MapSession_RW class } ?>