/**
  * @param string the content of the geometry tag of a KML. Note: KML 2.2 uses a 
  *               comma separated list, while KML OWS uses the GML syntax with 
  *               blanks as separators 
  */
 public function __construct($geometryString, $epsg)
 {
     # KML 2.2
     if (preg_match("/,/", $geometryString)) {
         $pointArray = explode(" ", $geometryString);
         for ($i = 0; $i < count($pointArray); $i++) {
             #
             # Some KMLs have a lot of whitespaces; this "if" is an
             # ugly hack to prevent adding empty points
             #
             if (preg_match("/,/", $pointArray[$i])) {
                 $aPoint = explode(",", $pointArray[$i]);
                 // KML only supperts EPSG 4326, so
                 // the coordinates are transformed
                 $pt = new Mapbender_point($aPoint[0], $aPoint[1], $aPoint[2], $epsg);
                 if (isset($epsg) && $epsg != 4326) {
                     $pt->transform(4326);
                 }
                 $point = array("x" => $pt->x, "y" => $pt->y, "z" => $pt->z);
                 array_push($this->pointArray, $point);
             }
         }
     } else {
         $pointArray = explode(" ", $geometryString);
         for ($i = 0; $i < count($pointArray); $i += 3) {
             #
             # Some KMLs have a lot of whitespaces; this "if" is an
             # ugly hack to prevent adding empty points
             #
             if ($pointArray[$i] && $pointArray[$i + 1]) {
                 $pt = new Mapbender_point($pointArray[$i], $pointArray[$i + 1], $pointArray[$i + 2], $epsg);
                 // KML only supperts EPSG 4326, so
                 // the coordinates are transformed
                 if (isset($epsg) && $epsg != 4326) {
                     $pt->transform(4326);
                 }
                 $point = array("x" => $pt->x, "y" => $pt->y, "z" => $pt->z);
                 array_push($this->pointArray, $point);
             }
         }
     }
 }
 /**
  * @param	string	the content of the geometry tag of a KML. Note: KML 2.2 uses a 
  *               	comma separated list, while KML OWS uses the GML syntax with 
  *               	blanks as separators 
  */
 public function __construct($geometryString, $epsg)
 {
     //TODO: parameter validation and exception handling
     // KML 2.2
     if (preg_match("/,/", $geometryString)) {
         $aPoint = explode(",", $geometryString);
         // ignore altitude
         $pt = new Mapbender_point($aPoint[0], $aPoint[1], $aPoint[2], $epsg);
     } else {
         $aPoint = explode(" ", $geometryString);
         // ignore altitude
         $pt = new Mapbender_point($aPoint[0], $aPoint[1], $aPoint[2], $epsg);
     }
     // KML only supperts EPSG 4326, so
     // the coordinates are transformed
     if (isset($epsg) && $epsg != 4326) {
         $pt->transform(4326);
     }
     $this->point = array("x" => $pt->x, "y" => $pt->y, "z" => $pt->z);
 }
 function insertLayerEPSG($i)
 {
     $sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = \$1";
     $v = array($this->objLayer[$i]->db_id);
     $t = array('i');
     $res = db_prep_query($sql, $v, $t);
     for ($j = 0; $j < count($this->objLayer[$i]->layer_epsg); $j++) {
         $sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
         $sql .= "VALUES(\$1,\$2,\$3,\$4,\$5,\$6)";
         $v = array($this->objLayer[$i]->db_id, $this->objLayer[$i]->layer_epsg[$j][epsg], $this->objLayer[$i]->layer_epsg[$j][minx], $this->objLayer[$i]->layer_epsg[$j][miny], $this->objLayer[$i]->layer_epsg[$j][maxx], $this->objLayer[$i]->layer_epsg[$j][maxy]);
         $t = array('i', 's', 'd', 'd', 'd', 'd');
         $res = db_prep_query($sql, $v, $t);
         if (!$res) {
             db_rollback();
         }
     }
     //		GET SRS_ARRAY of mapbender.conf
     if (SRS_ARRAY != "") {
         $confSrsArray = split(",", SRS_ARRAY);
         foreach ($confSrsArray as &$srs) {
             $srs = trim($srs);
         }
     }
     for ($index = 0; $index < sizeof($confSrsArray); $index++) {
         $confSrsArray[$index] = "EPSG:" . $confSrsArray[$index];
     }
     $sql_epsg = "SELECT * FROM layer_epsg WHERE fkey_layer_id = \$1";
     $v_epsg = array($this->objLayer[$i]->db_id);
     $t_epsg = array('i');
     $res_epsg = db_prep_query($sql_epsg, $v_epsg, $t_epsg);
     $epsg = array();
     $minx = array();
     $miny = array();
     $maxx = array();
     $maxy = array();
     $cnt = 0;
     while ($row_epsg = db_fetch_array($res_epsg)) {
         array_push($epsg, strtoupper($row_epsg['epsg']));
         array_push($minx, $row_epsg['minx']);
         array_push($miny, $row_epsg['miny']);
         array_push($maxx, $row_epsg['maxx']);
         array_push($maxy, $row_epsg['maxy']);
         $cnt++;
     }
     //get all srs which are supported by the parent layer and in array SRS_ARRAY from mapbender.conf
     $supportedSrs = $this->getSupportedSRS($this->objLayer[$i]->db_id, $confSrsArray);
     for ($k = 0; $k < count($supportedSrs); $k++) {
         if (!in_array($supportedSrs[$k], $epsg) && $supportedSrs[$k] != '') {
             $n = new mb_notice("Calculation for: " . $supportedSrs[$k]);
             $pointMin = new Mapbender_point($minx[0], $miny[0], $epsg[0]);
             $pointMax = new Mapbender_point($maxx[0], $maxy[0], $epsg[0]);
             $pointMin->transform($supportedSrs[$k]);
             $pointMax->transform($supportedSrs[$k]);
             if ($pointMin->epsg != '' && $pointMin->x != '' && $pointMin->y != '' && $pointMax->x != '' && $pointMax->y != '') {
                 $sql_bbox = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
                 $sql_bbox .= "VALUES(\$1,\$2,\$3,\$4,\$5,\$6)";
                 $v_bbox = array($this->objLayer[$i]->db_id, $pointMin->epsg, $pointMin->x, $pointMin->y, $pointMax->x, $pointMax->y);
                 $t_bbox = array('i', 's', 'd', 'd', 'd', 'd');
                 $res_bbox = db_prep_query($sql_bbox, $v_bbox, $t_bbox);
                 $n = new mb_notice("Calculation for: " . $supportedSrs[$k] . " finished successful.");
             } else {
                 $e = new mb_exception("Could not transform " . strtoupper($epsg[0]) . " to " . $supportedSrs[$k] . ".");
             }
         }
     }
 }
 /**
  * Computes a new bounding box, bbox1 UNION bbox2
  */
 static function union($bboxArray)
 {
     if (count($bboxArray) == 1) {
         return array_pop($bboxArray);
     } elseif (count($bboxArray) >= 2) {
         $bbox1 = array_pop($bboxArray);
         $bbox2 = Mapbender_bbox::union($bboxArray);
         if (!($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
             $e = new mb_exception("Mapbender_bbox: union: both parameters invalid!");
             return null;
         } elseif (!($bbox1 != null && $bbox1->isValid()) && ($bbox2 != null && $bbox2->isValid())) {
             $e = new mb_exception("Mapbender_bbox: union: first parameter invalid!");
             return $bbox2;
         } elseif ($bbox1 != null && $bbox1->isValid() && !($bbox2 != null && $bbox2->isValid())) {
             $e = new mb_exception("Mapbender_bbox: union: second parameter invalid!");
             return $bbox1;
         } else {
             if ($bbox1->epsg == $bbox2->epsg) {
                 $e = new mb_notice("Mapbender_bbox: union: bbox1 is: " . $bbox1);
                 $e = new mb_notice("Mapbender_bbox: union: bbox2 is: " . $bbox2);
                 $e = new mb_notice("Mapbender_bbox: union: merging bbox1 and bbox2...");
                 return new Mapbender_bbox(Mapbender_point::min($bbox1->min, $bbox2->min), Mapbender_point::max($bbox1->max, $bbox2->max), $bbox1->epsg);
             } else {
                 $e = new mb_exception("Mapbender_bbox: cannot process union with different EPSG codes");
             }
         }
     } else {
         $e = new mb_exception("Mapbender_bbox: Invalid parameter (Not an array)!");
     }
     return null;
 }