transform(4326); } $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+=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]) { $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, "z" => $pt->z); array_push($this->pointArray, $point); } } } } /** * @return string a string representation of the object, currently geoJSON. */ public function __toString() { return $this->toGeoJSON(); } /** * @return string a geoJSON string representation of the object. */ public function toGeoJSON () { $numberOfPoints = count($this->pointArray); if ($numberOfPoints > 0) { $str = ""; for ($i=0; $i < $numberOfPoints; $i++) { if ($i > 0) { $str .= ","; } 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 . "]}"; } $e = new mb_exception("KMLLine: toGeoJSON: this line has no points."); return ""; } /** * @return array an array of points as associative array, coordinates as ["x"] and ["y"] and ["z"] */ public function getPointArray () { return $this->pointArray; } /** * An array of points, with a point being an associative * array consisting of attributes "x" and "y" and "z" */ protected $pointArray = array(); } ?>