x = is_array($x)&&count($x)>0 ? $x[0] : $x; $this->y = is_array($y)&&count($y)>0 ? $y[0] : $y; $this->z = is_array($z)&&count($z)>0 ? $z[0] : $z; $this->epsg = $epsg; } /** * computes a new point with the minimal coordinates of this point and $point */ static function min ($point1, $point2) { if ($point1->epsg == $point2->epsg) { if ($point1->isWestOf($point2)) { $minx = $point1->x; } else { $minx = $point2->x; } if ($point1->isSouthOf($point2)) { $miny = $point1->y; } else { $miny = $point2->y; } return new Mapbender_point($minx, $miny, $point1->epsg); } else { $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes"); } } /** * computes a new point with the maximal coordinates of this point and $point */ static function max ($point1, $point2) { if ($point1->epsg == $point2->epsg) { if ($point1->isWestOf($point2)) { $maxx = $point2->x; } else { $maxx = $point1->x; } if ($point1->isSouthOf($point2)) { $maxy = $point2->y; } else { $maxy = $point1->y; } return new Mapbender_point($maxx, $maxy, $point1->epsg); } else { $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes"); } } function equals($point) { if ($this->x === $point->x && $this->y === $point->y && $this->z === $point->z && $this->epsg === $point->epsg ) { return true; } } function isWestOf($point) { if ($this->x < $point->x) { return true; } } function isSouthOf($point) { if ($this->y < $point->y) { return true; } } /** * Addition * * @param anotherPoint another Mapbender_point */ function plus ($anotherPoint) { return new Mapbender_point($this->x + $anotherPoint->x, $this->y + $anotherPoint->y, $this->epsg); } /** * Subtraction * * @param anotherPoint another Mapbender_point */ function minus ($anotherPoint) { return $this->plus($anotherPoint->times(-1)); } /** * Scalar multiplication * * @param aFloat a floating point number */ function times ($aFloat) { return new Mapbender_point($this->x * $aFloat, $this->y * $aFloat, $this->epsg); } /** * transforms this point to another EPSG * * @param {Integer} toEpsg the coordinates are transformed to this EPSG code. */ function transform($toEpsg) { if(SYS_DBTYPE=='pgsql'){ $currentEpsg = preg_replace("/EPSG:/", "", $this->epsg); $targetEpsg = preg_replace("/EPSG:/", "", $toEpsg); //get EPSG:4326 extents for which $this->epsg are defined $geometryUnchanged = true; if (defined("SRS_ARRAY") && SRS_ARRAY !== "" ) { //check if this->epsg is 4326 - if if ($toEpsg == "4326") { //do nothing - every crs can be projected to latlon without any problems! } else { $posTargetEpsgBbox = array_search($targetEpsg,explode(",",SRS_ARRAY)); if ($posTargetEpsgBbox !== false) { //check if bboxes are defined for special epsg SRS_ARRAY_MAX_EXTENTS if (defined("SRS_ARRAY_MAX_EXTENTS") && SRS_ARRAY_MAX_EXTENTS !== "" ) { $bboxArray = explode("|",SRS_ARRAY_MAX_EXTENTS); $wgs84BboxTargetEpsg = explode(",",$bboxArray[$posTargetEpsgBbox]); //compare point values with bboxes and adopt them if needed //$e = new mb_exception("class_point: bbox compare started before transforming!!!"); //$e = new mb_exception("class_point: minx:".$wgs84BboxTargetEpsg[0]." - miny:".$wgs84BboxTargetEpsg[1]." - maxx:".$wgs84BboxTargetEpsg[2]." - maxy:".$wgs84BboxTargetEpsg[3]); if ($this->x < $wgs84BboxTargetEpsg[0]) { $this->x = $wgs84BboxTargetEpsg[0]; $geometryUnchanged = false; } if ($this->x > $wgs84BboxTargetEpsg[2]) { $this->x = $wgs84BboxTargetEpsg[2]; $geometryUnchanged = false; } if ($this->y < $wgs84BboxTargetEpsg[1]) { $this->y = $wgs84BboxTargetEpsg[1]; $geometryUnchanged = false; } if ($this->y > $wgs84BboxTargetEpsg[3]) { $this->y = $wgs84BboxTargetEpsg[3]; $geometryUnchanged = false; } } } } } db_begin(); $sql = "SELECT X(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as x, "; $sql .= "Y(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as y"; if (!$geometryUnchanged) { $e = new mb_exception("geometry changed!!!!!!"); } if (isset($this->z)) { $sql .= ", Z(transform(GeometryFromText('POINT(".$this->x." ".$this->y." ".$this->z.")',".$currentEpsg."),".$targetEpsg.")) as z"; } $res = db_query($sql); db_commit(); if (isset($this->z)) { $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), db_result($res,0,"z"), $toEpsg); } else { $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), $toEpsg); } $this->x = $point->x; $this->y = $point->y; $this->z = $point->z; $this->epsg = $point->epsg; } else { $e = new mb_exception("transformCoordinates needs PostgreSQL"); } } function toHtml () { $str = ""; $xArray = explode(".", strval($this->x)); $str .= $xArray[0] . "°"; if ($xArray[1]) { $str .= $xArray[1] . "'"; } $str .= " O / "; $yArray = explode(".", strval($this->y)); $str .= $yArray[0] . "°"; if ($yArray[1]) { $str .= $yArray[1] . "'"; } $str .= " N"; return $str; } function __toString() { return (string) "(" . $this->x . "," . $this->y . "," . $this->z . "," . $this->epsg . ")"; } } ?>