load('../../conf/'.$CONFIGURATION['mapbook']); return $mapbook; } function getUsername() { session_start(); return $_SESSION['username']; } # Select Functionality ONLY works for Mapserver Layers function getMapfile($mb, $layerName) { $services = $mb->getElementsByTagName('map-source'); $mapfiles = array(); for($i = 0; $i < $services->length; $i++) { $service = $services->item($i); $root = $service->getAttribute('name'); $layers = $service->getElementsByTagName('layer'); for($l = 0; $l < $layers->length; $l++) { $layer = $layers->item($l); $path = $root.'/'.$layer->getAttribute('name'); if($path == $layerName) { return $service->getElementsByTagName('file')->item(0)->nodeValue; } } } return null; } # get a source based on it's name function getMapSource($mb, $layerName) { $services = $mb->getElementsByTagName('map-source'); $mapfiles = array(); for($i = 0; $i < $services->length; $i++) { if($services->item($i)->getAttribute('name') == $layerName) { return $services->item($i); } } return null; } # # Function: reprojectWKT # Casts basic WKT strings between various projections. # Useful when data projections do not match incoming projections. # # Parameters: # inWkt - The WKT of the shape to reproject # inProjection - MapServer ProjectionObj for the incoming WKT. # outProjection - Target Projection. # # Returns: # Reprojected WKT string. # function reprojectWKT($inWkt, $inProjection, $outProjection) { $in_shape = ms_shapeObjFromWkt($inWkt); $in_shape->project($inProjection, $outProjection); return $in_shape->toWkt(); } # # Function: getUtmProjection # Get an apporpiate UTM projection for the shape. Possibly because UTM # preserves distance. # # Parameters: # longitude - The longitude of a shape # # Returns: # A EPSG string. # function getUtmProjection($longitude) { $code = (int)(ceil(((float)$longitude) / 6.0 + 30) + 32601); return 'EPSG:'.$code; } # # Function: saneBuffer # Buffers a shape in a projection that actually honors distance. # This is important because projections like Web Mercator and LatLong do # not have such honor. # # Parameters: # inShape - MapScript shapeObj # inProjection - MapServer ProjectionObj for the incoming WKT. If set to NULL, assumes shape is in WGS84. # meters - Distance in meters to buffer. # # Results: # A properly (sanely) buffered MapScript shapeObj # function saneBuffer($inShape, $inProjection, $meters, $debug=false) { $wgs84 = ms_newprojectionobj('epsg:4326'); # if inProjection is NULL, we assume wgs84 if($inProjection != NULL) { $shape = ms_shapeObjFromWkt(reprojectWkt($inShape->toWkt(), $inProjection, $wgs84)); } else { $shape = $inShape; } $utm_projection = ms_newprojectionobj(getUtmProjection($shape->bounds->minx)); if($debug) { error_log('saneBuffer :: MINX :'.$shape->bounds->minx); error_log('saneBuffer :: SELECTED ZONE :'.getUtmProjection($shape->bounds->minx)); } $shape->project($wgs84, $utm_projection); # I have no idea why, but if I don't call this, the whole thing creates an # invalid geometry, circa PHP MapScript 6.0.1, 20 January 2012 $shape->toWkt(); if($debug) { error_log('saneBuffer :: UTM PROJECTED SHAPE :'.$shape->toWkt()); } $shape = $shape->buffer(floatval($meters)); if($inProjection == NULL) { # convert it back to WGS84 $shape->project($utm_projection, $wgs84); } else { # back to native coordinates. $shape->project($utm_projection, $inProjection); } # Again, with PHP MapScript 6.0.2, I need to run toWkt # to have the projections "take". $shape->toWkt(); if($debug) { error_log('saneBuffer :: Back to projection :'.$shape->toWkt()); } return $shape; } # # Method: get_request_icase # Try to get both the lower and uppercase version of the parameter # from "$_REQUEST" # # Parameters: # param_name # # Returns: # God willing, the passed in parameter value. # function get_request_icase($param_name) { $lower_case = strtolower($param_name); $upper_case = strtoupper($param_name); $value = NULL; if(isset($_REQUEST[$lower_case])) { $value = $_REQUEST[$lower_case]; } if(!isset($value)) { $value = $_REQUEST[$upper_case]; } return $value; } # # Method: isset_icase # Checks to see if either the upper or lower case # versions of a parameter value are set. # # Parameters: # param_name # # Returns: # Boolean # function isset_icase($param_name) { $lower_case = strtolower($param_name); $upper_case = strtoupper($param_name); return (isset($_REQUEST[$lower_case]) or isset($_REQUEST[$upper_case])); } # # Method: processTemplate # Hokey-GeoMOOSE template processing utility. # # Parameters: # $str - A string with "[STUFF]" tags # $dict - An associative array with keys matching "STUFF" # # Returns: # Formatted string. # function processTemplate($str, $dict) { foreach($dict as $k => $v) { $str = str_replace('['.$k.']', $v, $str); } return $str; } # # Method: parseBoolean # Parses a string for a boolean value. # function parseBoolean($str) { $str = strtolower($str); return ($str == 'true' || $str == 'on' || $str == '1'); } ?>