[Mapbender-commits] r1944 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jan 3 11:10:44 EST 2008
Author: christoph
Date: 2008-01-03 11:10:44 -0500 (Thu, 03 Jan 2008)
New Revision: 1944
Added:
trunk/mapbender/http/classes/class_kml_polygon.php
Log:
new class for kml polygons, formerly part of class_kml_ows.php
Added: trunk/mapbender/http/classes/class_kml_polygon.php
===================================================================
--- trunk/mapbender/http/classes/class_kml_polygon.php (rev 0)
+++ trunk/mapbender/http/classes/class_kml_polygon.php 2008-01-03 16:10:44 UTC (rev 1944)
@@ -0,0 +1,104 @@
+<?php
+/**
+ * $Id: class_wmc.php,v 1.31 2006/03/16 14:49:30 c_baudson Exp $
+ *
+ * @link http://www.mapbender.org/index.php/class_wmc.php
+ * @copyright 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)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+require_once("../classes/class_mb_exception.php");
+require_once("../classes/class_kml_geometry.php");
+
+/**
+ * Represents a polygon, consisting of 1 outer boundary and 0..n inner boundaries
+ * (these boundaries are of type {@link KMLLinearRing})
+ *
+ * @package KML
+ */
+class KMLPolygon extends KMLGeometry {
+
+ /**
+ * @param KMLLinearRing $aLinearRing the outer ring of the polygon
+ */
+ public function __construct ($aLinearRing) {
+ if ($aLinearRing instanceof KMLLinearRing) {
+ $this->outerBoundary = $aLinearRing;
+ }
+ $e = new mb_exception("class_kml_polygon.php: __construct: parameter not a linear ring.");
+ }
+
+ /**
+ * @return string a string representation of the object, currently
+ * {@link http://www.geojson.org GeoJSON}
+ */
+ public function __toString() {
+ return $this->toGeoJSON();
+ }
+
+ /**
+ * @return string the geoJSON representation of the object
+ */
+ public function toGeoJSON () {
+ $str = "";
+ if ($this->outerBoundary !== null) {
+ $str .= $this->outerBoundary->toGeoJSON();
+
+ $numberOfInnerBoundaries = count($this->innerBoundaryArray);
+ if ($numberOfInnerBoundaries > 0) {
+ $str .= ", ";
+ for ($i=0; $i < $numberOfInnerBoundaries; $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= $this->innerBoundaryArray[$i]->toGeoJSON();
+ }
+ }
+ $str .= "{\"type\": \"Polygon\", \"coordinates\": [" . $str . "]}";
+ }
+ else {
+ $e = new mb_exception("KMLPolygon: toGeoJSON: this point is null.");
+ }
+ return $str;
+ }
+
+ /**
+ * Cuts a hole in the polygon.
+ *
+ * @param KMLLinearRing $aLinearRing the linear ring describing the hole that is being cut.
+ * @return bool true, if the parameter is a linear ring; else false
+ */
+ public function appendInnerBoundary ($aLinearRing) {
+ if ($aLinearRing instanceof KMLLinearRing) {
+ array_push($this->innerBoundaryArray, $aLinearRing);
+ return true;
+ }
+ $e = new mb_exception("class_kml_polygon.php: appendInnerBoundary: parameter not a linear ring.");
+ return false;
+ }
+
+ /**
+ * @var KMLLinearRing The outer boundary of the polygon
+ */
+ private $outerBoundary;
+
+ /**
+ * @var KMLLinearRing[] The inner boundaries (holes) of the polygon
+ */
+ private $innerBoundaryArray = array();
+}
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list