[Mapbender-commits] r1740 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Oct 26 06:12:53 EDT 2007
Author: christoph
Date: 2007-10-26 06:12:53 -0400 (Fri, 26 Oct 2007)
New Revision: 1740
Modified:
trunk/mapbender/http/classes/class_bbox.php
Log:
new functions
more notices
more comments
Modified: trunk/mapbender/http/classes/class_bbox.php
===================================================================
--- trunk/mapbender/http/classes/class_bbox.php 2007-10-18 14:52:40 UTC (rev 1739)
+++ trunk/mapbender/http/classes/class_bbox.php 2007-10-26 10:12:53 UTC (rev 1740)
@@ -2,7 +2,7 @@
# $Id$
# http://www.mapbender.org/index.php/
# Copyright (C) 2002 CCGIS
-#
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
@@ -23,25 +23,25 @@
db_select_db(DB,$con);
/**
- * A Mapbender_point is a 2-dimensional point with an EPSG.
+ * A Mapbender_point is a 2-dimensional point with an EPSG.
*/
class Mapbender_point {
var $x;
var $y;
var $epsg;
-
+
/**
* @constructor
*/
- function Mapbender_point($x, $y, $epsg) {
- if ($x == null || $y == null || $epsg == null) {
- $e = new mb_exception("Mapbender_point: constructor: some parameters are not set!");
+ function __construct($x, $y, $epsg) {
+ if (!$x || !$y || !$epsg) {
+ $e = new mb_exception("Mapbender_point: constructor: some parameters are not set (set (x: ".$x.", y: ".$y.", epsg:".$epsg.")!");
}
$this->x = $x;
$this->y = $y;
$this->epsg = $epsg;
}
-
+
/**
* computes a new point with the minimal coordinates of this point and $point
*/
@@ -65,7 +65,7 @@
$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
*/
@@ -86,10 +86,10 @@
return new Mapbender_point($maxx, $maxy, $point1->epsg);
}
else {
- $e = new mb_exception("Mapbender_point: cannot process max with different EPSG codes");
+ $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes");
}
}
-
+
function isWestOf($point) {
if ($this->x < $point->x) {
return true;
@@ -101,8 +101,35 @@
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
*/
function transform($toEpsg) {
@@ -118,10 +145,10 @@
$this->epsg = $point->epsg;
}
else {
- $e = new mb_exception("Mapbender_point: transformCoordinates needs PostgreSQL");
+ $e = new mb_exception("transformCoordinates needs PostgreSQL");
}
}
-
+
function __toString() {
return (string) "(" . $this->x . "," . $this->y . "," . $this->epsg . ")";
}
@@ -134,26 +161,56 @@
var $min;
var $max;
var $epsg;
-
+
/**
* @constructor
*/
- function Mapbender_bbox($min, $max, $epsg) {
- if ($min->isWestOf($max) && $min->isSouthOf($max)) {
- if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
- $this->min = $min;
- $this->max = $max;
- $this->epsg = $epsg;
+ function __construct($param0, $param1, $param2, $param3, $param4) {
+ // params are point, point, epsg
+ if (is_a($param0, "Mapbender_point") && is_a($param1, "Mapbender_point") && !$param3 && !$param4) {
+ $e = new mb_notice("Mapbender_bbox: constructor: point1, point2, epsg");
+ $min = $param0; // is a Mapbender_point
+ $max = $param1; // is a Mapbender_point
+ $epsg = $param2; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
}
else {
- $e = new mb_exception("Mapbender_bbox: EPSG mismatch!");
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
}
}
+ // params are x1, y1, x2, xy, epsg
else {
- $e = new mb_exception("Mapbender_bbox: min is not southwest of max!");
+ $e = new mb_notice("Mapbender_bbox: constructor: x1, y1, x2, y2, epsg");
+ $min = new Mapbender_point($param0, $param1, $param4);
+ $max = new Mapbender_point($param2, $param3, $param4);
+ $epsg = $param4; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
+ }
+
}
}
-
+
/**
* Computes a new bounding box, bbox1 UNION bbox2
*/
@@ -162,24 +219,27 @@
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_notice("Mapbender_bbox: union: both parameters invalid!");
+ $e = new mb_exception("Mapbender_bbox: union: both parameters invalid!");
return null;
}
elseif (!($bbox1 != null && $bbox1->isValid()) && ($bbox2 != null && $bbox2->isValid())) {
- $e = new mb_notice("Mapbender_bbox: union: first parameter invalid!");
+ $e = new mb_exception("Mapbender_bbox: union: first parameter invalid!");
return $bbox2;
}
elseif (($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
- $e = new mb_notice("Mapbender_bbox: union: second parameter invalid!");
+ $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 {
@@ -192,9 +252,10 @@
}
return null;
}
-
+
/**
* transforms this bbox in another EPSG
+ * @param toEpsg transform the bbox to this EPSG code, example: "EPSG:4326"
*/
function transform($toEpsg) {
if ($this->isValid()) {
@@ -216,9 +277,9 @@
$e = new mb_exception("Mapbender_bbox: this is not a valid bbox!");
return false;
}
-
+
function __toString() {
- return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]";
+ return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]";
}
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list