[Mapbender-commits] r3092 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Oct 1 09:50:57 EDT 2008
Author: christoph
Date: 2008-10-01 09:50:57 -0400 (Wed, 01 Oct 2008)
New Revision: 3092
Modified:
trunk/mapbender/http/classes/class_bbox.php
trunk/mapbender/http/classes/class_kml_line.php
trunk/mapbender/http/classes/class_kml_linearring.php
trunk/mapbender/http/classes/class_kml_ows.php
trunk/mapbender/http/classes/class_kml_parser_ows.php
trunk/mapbender/http/classes/class_kml_placemark.php
trunk/mapbender/http/classes/class_kml_point.php
trunk/mapbender/http/classes/class_point.php
Log:
added 3rd dimension (merged from 2.5)
Modified: trunk/mapbender/http/classes/class_bbox.php
===================================================================
--- trunk/mapbender/http/classes/class_bbox.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_bbox.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_point.php");
/**
* A bounding box consisting of an lower left and an upper right point, and an EPSG.
Modified: trunk/mapbender/http/classes/class_kml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_line.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_line.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -44,34 +44,32 @@
#
if (preg_match("/,/", $pointArray[$i])) {
$aPoint = explode(",", $pointArray[$i]);
- # ignore altitude
// KML only supperts EPSG 4326, so
// the coordinates are transformed
- $pt = new Mapbender_point($aPoint[0], $aPoint[1], $epsg);
+ $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);
+ $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+=2) {
+ 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]) {
- # ignore altitude
- $pt = new Mapbender_point($pointArray[$i], $pointArray[$i+1], $epsg);
+ $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);
+ $point = array("x" => $pt->x, "y" => $pt->y, "z" => $pt->z);
array_push($this->pointArray, $point);
}
}
@@ -96,7 +94,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ if ($this->pointArray[$i]["z"]) {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"].",".$this->pointArray[$i]["z"]."]";
+ }
+ else {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
}
return "{\"type\": \"LineString\", \"coordinates\":[" . $str . "]}";
}
@@ -106,7 +109,7 @@
}
/**
- * @return array an array of points as associative array, coordinates as ["x"] and ["y"]
+ * @return array an array of points as associative array, coordinates as ["x"] and ["y"] and ["z"]
*/
public function getPointArray () {
return $this->pointArray;
@@ -114,7 +117,7 @@
/**
* An array of points, with a point being an associative
- * array consisting of attributes "x" and "y".
+ * array consisting of attributes "x" and "y" and "z"
*/
protected $pointArray = array();
}
Modified: trunk/mapbender/http/classes/class_kml_linearring.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_linearring.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_linearring.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -42,7 +42,12 @@
if ($i > 0) {
$str .= ",";
}
- $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ if ($this->pointArray[$i]["z"]) {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"].",".$this->pointArray[$i]["z"]."]";
+ }
+ else {
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
}
return "[" . $str . "]";
}
Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_ows.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -45,6 +45,114 @@
public function __construct() {
}
+ public function toSingleLineStringKml() {
+ //KML 2.2 output
+ $doc = new DOMDocument("1.0", CHARSET);
+ $doc->preserveWhiteSpace = false;
+
+ // attach kml and Document tag
+ $e_kml = $doc->createElementNS("http://earth.google.com/kml/2.2", "kml");
+ $e_document = $doc->createElement("Document");
+ $e_kml->appendChild($e_document);
+ $doc->appendChild($e_kml);
+
+ // attach placemarks
+ $e = new mb_notice("to string: #placemarks: " . count($this->placemarkArray));
+
+ $lineStyleNode = $doc->createElement("Style");
+ $lineStyleNode->setAttribute("id", "linestyleExample");
+ $lineStyleColorNode = $doc->createElement("color", "7f0000ff");
+ $lineStyleWidthNode = $doc->createElement("width", 4);
+ $lineStyleNode->appendChild($lineStyleColorNode);
+ $lineStyleNode->appendChild($lineStyleWidthNode);
+ $e_document->appendChild($lineStyleNode);
+
+ //
+ // line segments first
+ //
+ $coordinates = "";
+
+ for ($i = 0; $i < count($this->placemarkArray); $i++) {
+ $currentPlacemark = $this->placemarkArray[$i];
+ $e = new mb_notice("now: " . $i . " of " . (count($this->placemarkArray)-1) . " (is a " . get_class($currentPlacemark) . ")");
+
+ switch ($currentPlacemark->getGeometryType()) {
+ case "KMLLine" :
+ $coordinatesArray = $currentPlacemark->getGeometry()->getPointArray();
+ for ($j = 0; $j < count($coordinatesArray); $j++) {
+ if (!($j == 0 && $i == 0)) {
+ $coordinates .= " ";
+ }
+ $coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"] . "," . $coordinatesArray[$j]["z"];
+
+ }
+ break;
+ }
+ }
+ // create a placemark tag with a geometry and add it to the document
+ $e_coordinates = $doc->createElement("coordinates", $coordinates);
+ $e_geometry = $doc->createElement("LineString");
+ $e_geometry->appendChild($e_coordinates);
+ $e_placemark = $doc->createElement("Placemark");
+ $e_placemark->appendChild($e_geometry);
+ $e_pl_name = $doc->createElement("name", "Route");
+ $e_placemark->appendChild($e_pl_name);
+ $e_pl_style = $doc->createElement("styleUrl", "#linestyleExample");
+ $e_placemark->appendChild($e_pl_style);
+ $e_document->appendChild($e_placemark);
+
+/*
+ //
+ // now pois
+ //
+ // attach placemarks
+ $e = new mb_notice("to string: #placemarks: " . count($this->placemarkArray));
+ for ($i = 0; $i < count($this->placemarkArray); $i++) {
+ $currentPlacemark = $this->placemarkArray[$i];
+
+ $e = new mb_notice("now: " . $i . " of " . (count($this->placemarkArray)-1) . " (is a " . get_class($currentPlacemark) . ")");
+
+ $pl_instructions = $currentPlacemark->getProperty("instruction");
+ $pl_name_array = array();
+ $pl_name = false;
+ $pl_description = false;
+ if ($pl_instructions != null) {
+ $pl_name_array = explode("|", $pl_instructions);
+ }
+
+ switch ($currentPlacemark->getGeometryType()) {
+ case "KMLPoint" :
+ if (count($pl_name_array) > 2) {
+ $pl_name = $pl_name_array[0];
+ $pl_description = $pl_name_array[1];
+ }
+ $e_geometry = $doc->createElement("Point");
+ $point = $currentPlacemark->getGeometry()->getPoint();
+ $coordinates = $point["x"] . "," . $point["y"];
+ $e_coordinates = $doc->createElement("coordinates", $coordinates);
+ $e_geometry->appendChild($e_coordinates);
+ break;
+
+ }
+ // create a placemark tag with a geometry and add it to the document
+ if ($e_geometry) {
+ $e_placemark = $doc->createElement("Placemark");
+ $e_placemark->appendChild($e_geometry);
+ if ($pl_name) {
+ $e_pl_name = $doc->createElement("name", $pl_name);
+ $e_placemark->appendChild($e_pl_name);
+ }
+ if ($pl_description) {
+ $e_pl_description = $doc->createElement("description", $pl_description);
+ $e_placemark->appendChild($e_pl_description);
+ }
+ $e_document->appendChild($e_placemark);
+ }
+ }
+*/
+ return $doc->saveXML();
+ }
+
/**
* @return string the KML document.
*/
@@ -69,9 +177,20 @@
$e = new mb_notice("now: " . $i . " of " . (count($this->placemarkArray)-1) . " (is a " . get_class($currentPlacemark) . ")");
+ $pl_instructions = $currentPlacemark->getProperty("instruction");
+ $pl_name_array = array();
+ $pl_name = false;
+ $pl_description = false;
+ if ($pl_instructions != null) {
+ $pl_name_array = explode("|", $pl_instructions);
+ }
switch ($currentPlacemark->getGeometryType()) {
case "KMLPoint" :
+ if (count($pl_name_array) > 2) {
+ $pl_name = $pl_name_array[0];
+ $pl_description = $pl_name_array[1];
+ }
$e_geometry = $doc->createElement("Point");
$point = $currentPlacemark->getGeometry()->getPoint();
$coordinates = $point["x"] . "," . $point["y"];
@@ -100,6 +219,9 @@
break;
*/
case "KMLLine" :
+ if (count($pl_name_array) > 2) {
+ $pl_description = $pl_name_array[1];
+ }
$e_geometry = $doc->createElement("LineString");
$coordinatesArray = $currentPlacemark->getGeometry()->getPointArray();
$coordinates = "";
@@ -107,7 +229,7 @@
if ($j > 0) {
$coordinates .= " ";
}
- $coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"] . ",0";
+ $coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"] . "," . $coordinatesArray[$j]["z"];
}
$e_coordinates = $doc->createElement("coordinates", $coordinates);
@@ -123,6 +245,14 @@
if ($e_geometry) {
$e_placemark = $doc->createElement("Placemark");
$e_placemark->appendChild($e_geometry);
+ if ($pl_name) {
+ $e_pl_name = $doc->createElement("name", $pl_name);
+ $e_placemark->appendChild($e_pl_name);
+ }
+ if ($pl_description) {
+ $e_pl_description = $doc->createElement("description", $pl_description);
+ $e_placemark->appendChild($e_pl_description);
+ }
$e_document->appendChild($e_placemark);
}
}
@@ -300,23 +430,29 @@
* @return boolean true, if the KML could be stored in the database; else false.
*/
private function storeInDb () {
- $con = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB,$con);
-
- $sql = "INSERT INTO gui_kml ";
- $sql .= "(fkey_mb_user_id, fkey_gui_id, kml_doc, kml_name, kml_description, kml_timestamp) ";
- $sql .= "VALUES ";
- $sql .= "($1, $2, $3, $4, $5, $6)";
- $v = array ($_SESSION["mb_user_id"], $_SESSION["mb_user_gui"], $this->kml, "name", "description", time());
- $t = array ("i", "s", "s", "s", "s", "s");
- $res = db_prep_query($sql, $v, $t);
- if (!$res) {
- $e = new mb_exception("class_kml.php: storeInDb: failed to store KML in database: " . db_error());
- return false;
+ if ($_SESSION["mb_user_id"] && $_SESSION["mb_user_gui"]) {
+ $con = db_connect(DBSERVER,OWNER,PW);
+ db_select_db(DB,$con);
+
+ $sql = "INSERT INTO gui_kml ";
+ $sql .= "(fkey_mb_user_id, fkey_gui_id, kml_doc, kml_name, kml_description, kml_timestamp) ";
+ $sql .= "VALUES ";
+ $sql .= "($1, $2, $3, $4, $5, $6)";
+ $v = array ($_SESSION["mb_user_id"], $_SESSION["mb_user_gui"], $this->kml, "name", "description", time());
+ $t = array ("i", "s", "s", "s", "s", "s");
+ $res = db_prep_query($sql, $v, $t);
+ if (!$res) {
+ $e = new mb_exception("class_kml.php: storeInDb: failed to store KML in database: " . db_error());
+ return false;
+ }
+
+ $this->id = db_insert_id($con, "gui_kml", "kml_id");
+ return true;
}
-
- $this->id = db_insert_id($con, "gui_kml", "kml_id");
- return true;
+ else {
+ // should be false, but code in caller has to be changed first.
+ return true;
+ }
}
/**
Modified: trunk/mapbender/http/classes/class_kml_parser_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_ows.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_parser_ows.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -44,6 +44,9 @@
$id = 0;
if (gettype($geometryFromGeoJSON) == "object" && $geometryFromGeoJSON->type == "FeatureCollection") {
+ if ($geometryFromGeoJSON->crs->type == "EPSG" && $geometryFromGeoJSON->crs->properties->code) {
+ $epsg = $geometryFromGeoJSON->crs->properties->code;
+ }
// create Placemarks
for ($i = 0; $i < count($geometryFromGeoJSON->features); $i++) {
$e = new mb_notice("parsing plm #" . $i . "...length of placemarkArray: " . count($this->placemarkArray));
@@ -52,7 +55,9 @@
if ($feature->geometry->crs->type == "EPSG") {
$epsg = $feature->geometry->crs->properties->code;
}
- $e = new mb_notice("EPSG: " . $epsg);
+ if (!$epsg) {
+ $e = new mb_notice("EPSG is not set! Aborting...(" . $epsg . ")");
+ }
$geometry = $feature->geometry;
$currentGeometry = false;
Modified: trunk/mapbender/http/classes/class_kml_placemark.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_placemark.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_placemark.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -54,7 +54,7 @@
* @return mixed the property value; if none exists, null.
*/
public function getProperty ($key) {
- if (array_key_exists($key)) {
+ if (array_key_exists($key, $this->properties)) {
return $this->properties[$key];
}
$e = new mb_exception("class_kml_placemark.php: getProperty: no value for key '" . $key . "'");
Modified: trunk/mapbender/http/classes/class_kml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_point.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_kml_point.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -41,12 +41,12 @@
if (preg_match("/,/", $geometryString)) {
$aPoint = explode(",", $geometryString);
// ignore altitude
- $pt = new Mapbender_point($aPoint[0], $aPoint[1], $epsg);
+ $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], $epsg);
+ $pt = new Mapbender_point($aPoint[0], $aPoint[1], $aPoint[2], $epsg);
}
// KML only supperts EPSG 4326, so
@@ -54,7 +54,7 @@
if (isset($epsg) && $epsg != 4326) {
$pt->transform(4326);
}
- $this->point = array("x" => $pt->x, "y" => $pt->y);
+ $this->point = array("x" => $pt->x, "y" => $pt->y, "z" => $pt->z);
}
/**
@@ -69,7 +69,12 @@
*/
public function toGeoJSON () {
if ($this->point !== null) {
- return "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"]."]}";
+ if ($this->point["z"]) {
+ return "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"].",".$this->point["z"]."]}";
+ }
+ else {
+ return "{\"type\": \"Point\", \"coordinates\": [".$this->point["x"].",".$this->point["y"]."]}";
+ }
}
$e = new mb_exception("KMLPoint: toGeoJSON: this point is null.");
@@ -77,14 +82,14 @@
}
/**
- * @return array a point as associative array, coordinates as ["x"] and ["y"]
+ * @return array a point as associative array, coordinates as ["x"] and ["y"] and ["z"]
*/
public function getPoint () {
return $this->point;
}
/**
- * @var float[] an associative array, with "x", and "y" being float values.
+ * @var float[] an associative array, with "x", and "y" and "z" being float values.
*/
private $point;
}
Modified: trunk/mapbender/http/classes/class_point.php
===================================================================
--- trunk/mapbender/http/classes/class_point.php 2008-10-01 13:50:03 UTC (rev 3091)
+++ trunk/mapbender/http/classes/class_point.php 2008-10-01 13:50:57 UTC (rev 3092)
@@ -20,22 +20,30 @@
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
/**
- * A Mapbender_point is a 2-dimensional point with an EPSG.
+ * A Mapbender_point is a 2- or 3-dimensional point with an EPSG.
*/
class Mapbender_point {
var $x;
var $y;
+ var $z;
var $epsg;
/**
* @constructor
*/
- 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.")!");
+ function __construct($x, $y, $z, $epsg) {
+ // may be called without $z; so $epsg is the third parameter, $z
+ if (isset($x) && isset($y) && isset($z) && !isset($epsg)) {
+ $e = new mb_notice("Mapbender_point: constructor: probably 2d call (x: ".$x.", y: ".$y.", z: ".$z.", epsg:".$epsg.")!");
+ $epsg = $z;
+ $z = false;
}
+ if (!isset($x) || !isset($y) || !isset($epsg)) {
+ $e = new mb_exception("Mapbender_point: constructor: some parameters are not set (set (x: ".$x.", y: ".$y.", z: ".$z.", epsg:".$epsg.")!");
+ }
$this->x = $x;
$this->y = $y;
+ $this->z = $z;
$this->epsg = $epsg;
}
@@ -136,11 +144,20 @@
$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";
+ $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);
- $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), $toEpsg);
+ 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 {
@@ -169,7 +186,7 @@
}
function __toString() {
- return (string) "(" . $this->x . "," . $this->y . "," . $this->epsg . ")";
+ return (string) "(" . $this->x . "," . $this->y . "," . $this->z . "," . $this->epsg . ")";
}
}
?>
More information about the Mapbender_commits
mailing list