[Mapbender-commits] r1966 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jan 15 03:25:15 EST 2008
Author: christoph
Date: 2008-01-15 03:25:15 -0500 (Tue, 15 Jan 2008)
New Revision: 1966
Modified:
trunk/mapbender/http/classes/class_kml_geometry.php
trunk/mapbender/http/classes/class_kml_line.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
Log:
bug fixes
Modified: trunk/mapbender/http/classes/class_kml_geometry.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_geometry.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_geometry.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -42,7 +42,7 @@
* {@link KMLMultiGeometry}, or instance of
* another class extending KMLGeometry.
*/
- protected static function isGeometry($obj) {
+ public static function isGeometry($obj) {
if ($obj instanceof KMLGeometry) {
return true;
}
Modified: trunk/mapbender/http/classes/class_kml_line.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_line.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_line.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_point.php");
require_once(dirname(__FILE__)."/../classes/class_kml_geometry.php");
/**
@@ -31,7 +32,7 @@
* comma separated list, while KML OWS uses the GML syntax with
* blanks as separators
*/
- public function __construct ($geometryString) {
+ public function __construct ($geometryString, $epsg) {
# KML 2.2
if (preg_match("/,/", $geometryString)) {
$pointArray = explode(" ", $geometryString);
@@ -43,7 +44,13 @@
if (preg_match("/,/", $pointArray[$i])) {
$aPoint = explode(",", $pointArray[$i]);
# ignore altitude
- $point = array("x" => $aPoint[0], "y" => $aPoint[1]);
+ // KML only supperts EPSG 4326, so
+ // the coordinates are transformed
+ $pt = new Mapbender_point($aPoint[0], $aPoint[1], $epsg);
+ if (isset($epsg) && $epsg != 4326) {
+ $pt->transform(4326);
+ }
+ $point = array("x" => $pt->x, "y" => $pt->y);
array_push($this->pointArray, $point);
}
}
@@ -57,7 +64,13 @@
#
if ($pointArray[$i] && $pointArray[$i+1]) {
# ignore altitude
- $point = array("x" => $pointArray[$i], "y" => $pointArray[$i+1]);
+ $pt = new Mapbender_point($pointArray[$i], $pointArray[$i+1], $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);
array_push($this->pointArray, $point);
}
}
Modified: trunk/mapbender/http/classes/class_kml_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_ows.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_ows.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -23,6 +23,7 @@
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
require_once(dirname(__FILE__)."/../extensions/JSON.php");
require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_point.php");
require_once(dirname(__FILE__)."/../classes/class_kml_geometry.php");
require_once(dirname(__FILE__)."/../classes/class_kml_placemark.php");
@@ -51,7 +52,8 @@
* @return string the KML document.
*/
public function __toString() {
-
+
+
if (!$this->kml) {
//KML 2.2 output
$doc = new DOMDocument("1.0", CHARSET);
@@ -64,14 +66,18 @@
$doc->appendChild($e_kml);
// attach placemarks
- for ($i = 0; $i < $this->placemarkArray; $i++) {
+ $e = new mb_notice("to string: #placemarks: " . count($this->placemarkArray));
+ for ($i = 0; $i < count($this->placemarkArray); $i++) {
$currentPlacemark = $this->placemarkArray[$i];
- switch ($this->placemarkArray[$i]->getGeometryType()) {
+ $e = new mb_notice("now: " . $i . " of " . (count($this->placemarkArray)-1) . " (is a " . get_class($currentPlacemark) . ")");
+
+
+ switch ($currentPlacemark->getGeometryType()) {
case "KMLPoint" :
$e_geometry = $doc->createElement("Point");
- $point = $currentPlacemark->getPoint();
- $coordinates = $point->x . "," . $point->y;
+ $point = $currentPlacemark->getGeometry()->getPoint();
+ $coordinates = $point["x"] . "," . $point["y"];
$e_coordinates = $doc->createElement("coordinates", $coordinates);
$e_geometry->appendChild($e_coordinates);
break;
@@ -96,15 +102,15 @@
break;
*/
- case "KMLLineString" :
+ case "KMLLine" :
$e_geometry = $doc->createElement("LineString");
- $coordinatesArray = $currentPlacemark->getPointArray();
+ $coordinatesArray = $currentPlacemark->getGeometry()->getPointArray();
$coordinates = "";
for ($j = 0; $j < count($coordinatesArray); $j++) {
if ($j > 0) {
$coordinates .= ",";
}
- $coordinates .= $coordinatesArray[$j]->x . "," . $coordinatesArray[$j]->y;
+ $coordinates .= $coordinatesArray[$j]["x"] . "," . $coordinatesArray[$j]["y"];
}
$e_coordinates = $doc->createElement("coordinates", $coordinates);
@@ -158,14 +164,22 @@
* @return boolean true if the parsing succeded, else false.
*/
public function parseGeoJSON ($geoJSON) {
- $parser = new KmlOwsParser($geoJSON);
- $this->placemarkArray = $parser->placemarkArray;
-
- $this->kml = $this->__toString();
+ $this->kml = "";
if (!$this->storeInDb()) {
return false;
}
+
+ $parser = new KmlOwsParser();
+ $parser->parseGeoJSON($geoJSON, $this->id);
+ $e = new mb_notice("parsing finished...#placemarks: " . count($this->placemarkArray) . " (" . count($parser->placemarkArray) . ")");
+ $this->placemarkArray = $parser->placemarkArray;
+
+ print_r($this);
+
+// $this->kml = $this->__toString();
+
+// $this->updateInDb($this->kml, $this->id);
return true;
}
Modified: trunk/mapbender/http/classes/class_kml_parser_ows.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_parser_ows.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_parser_ows.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -19,6 +19,7 @@
require_once(dirname(__FILE__)."/../extensions/JSON.php");
require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_point.php");
require_once(dirname(__FILE__)."/../classes/class_kml_polygon.php");
require_once(dirname(__FILE__)."/../classes/class_kml_linearring.php");
require_once(dirname(__FILE__)."/../classes/class_kml_line.php");
@@ -43,21 +44,34 @@
if (gettype($geometryFromGeoJSON) == "object" && $geometryFromGeoJSON->type == "FeatureCollection") {
// create Placemarks
for ($i = 0; $i < count($geometryFromGeoJSON->features); $i++) {
+ $e = new mb_notice("parsing plm #" . $i . "...length of placemarkArray: " . count($this->placemarkArray));
$feature = $geometryFromGeoJSON->features[$i];
if (gettype($feature) == "object" && $feature->type == "Feature") {
+ if ($feature->geometry->crs->type == "EPSG") {
+ $epsg = $feature->geometry->crs->properties->code;
+ }
+ $e = new mb_notice("EPSG: " . $epsg);
$geometry = $feature->geometry;
-
+
+ $currentGeometry = false;
+ //TODO: missing Polygon and MultiGeometry
switch ($geometry->type) {
case "LineString" :
- $pointList = implode(",", $geometry->coordinates);
- $coordinateList = implode(",", $pointList);
- $currentGeometry = new KMLLine($coordinateList);
+ $coordinateList = "";
+ for ($j = 0; $j < count($geometry->coordinates); $j++) {
+ if ($j > 0) {
+ $coordinateList .= " ";
+ }
+ $coordinateList .= implode(",", $geometry->coordinates[$j]);
+ }
+ $currentGeometry = new KMLLine($coordinateList, $epsg);
break;
case "Point" :
$coordinateList = implode(",", $geometry->coordinates);
- $currentGeometry = new KMLPoint($coordinateList);
+ $currentGeometry = new KMLPoint($coordinateList, $epsg);
break;
}
+
if ($currentGeometry) {
$currentPlacemark = new KMLPlacemark($currentGeometry);
@@ -68,7 +82,9 @@
$currentPlacemark->setProperty("Mapbender:name", "unknown");
$currentPlacemark->setProperty("Mapbender:id", $kmlId);
$currentPlacemark->setProperty("Mapbender:placemarkId", $id);
+ $e = new mb_notice("adding to placemarkArray (current length: " . count($this->placemarkArray) . ")");
array_push($this->placemarkArray, $currentPlacemark);
+ $e = new mb_notice("added...new length: " . count($this->placemarkArray));
$id ++;
}
}
@@ -165,7 +181,7 @@
private function getGeometryFromPointNode ($node) {
$coordinatesNode = $this->getCoordinatesNode($node);
$geomString = $coordinatesNode->nodeValue;
- return new KMLPoint($geomString);
+ return new KMLPoint($geomString, 4326);
}
/**
@@ -175,7 +191,7 @@
private function getGeometryFromLinestringNode ($node) {
$coordinatesNode = $this->getCoordinatesNode($node);
$geomString = $coordinatesNode->nodeValue;
- return new KMLLine($geomString);
+ return new KMLLine($geomString, 4326);
}
/**
Modified: trunk/mapbender/http/classes/class_kml_placemark.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_placemark.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_placemark.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -96,11 +96,18 @@
}
/**
+ * @return KMLGeometry the geometry of this placemark
+ */
+ public function getGeometry () {
+ return $this->geometry;
+ }
+
+ /**
* @return string class name of geometry
*/
public function getGeometryType () {
if (KMLGeometry::isGeometry($this->geometry)) {
- return $geometry->getGeometryType();
+ return $this->geometry->getGeometryType();
}
$e = new mb_exception("class_kml_placemark.php: getGeometryType: Geometry not set.");
return "";
Modified: trunk/mapbender/http/classes/class_kml_point.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_point.php 2008-01-15 08:24:29 UTC (rev 1965)
+++ trunk/mapbender/http/classes/class_kml_point.php 2008-01-15 08:25:15 UTC (rev 1966)
@@ -34,20 +34,27 @@
* comma separated list, while KML OWS uses the GML syntax with
* blanks as separators
*/
- public function __construct ($geometryString) {
+ public function __construct ($geometryString, $epsg) {
//TODO: parameter validation and exception handling
// KML 2.2
if (preg_match("/,/", $geometryString)) {
$aPoint = explode(",", $geometryString);
// ignore altitude
- $this->point = array("x" => $aPoint[0], "y" => $aPoint[1]);
+ $pt = new Mapbender_point($aPoint[0], $aPoint[1], $epsg);
}
else {
$aPoint = explode(" ", $geometryString);
// ignore altitude
- $this->point = array("x" => $aPoint[0], "y" => $aPoint[1]);
+ $pt = new Mapbender_point($aPoint[0], $aPoint[1], $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);
}
/**
More information about the Mapbender_commits
mailing list