x = $x; $this->y = $y; $this->z = $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 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); $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 (isset($this->z)) { $sql .= "Z(transform(GeometryFromText('POINT(".$this->x." ".$this->y." ".$this->z.")',".$currentEpsg."),".$targetEpsg.")) as z"; } $res = db_query($sql); 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 __toString() { if (isset($this->z)) { return (string) "(" . $this->x . "," . $this->y . "," . $this->z . ", " . $this->epsg . ")"; } else { return (string) "(" . $this->x . "," . $this->y . "," . $this->epsg . ")"; } } } ?>