From bfa3ef7188c34dcb5941c0564479a9daf8973c44 Mon Sep 17 00:00:00 2001 From: Patrick Hayes Date: Fri, 22 Apr 2011 08:22:18 -0700 Subject: [PATCH] Removing LinearRing concept. We now only have LineString that are closed --- geoPHP.inc | 4 +-- lib/adapters/GPX.class.php | 1 - lib/adapters/GoogleGeocode.class.php | 2 +- lib/adapters/KML.class.php | 17 +++--------- lib/adapters/WKT.class.php | 4 +-- lib/geometry/Geometry.class.php | 2 +- lib/geometry/LinearRing.class.php | 39 ---------------------------- lib/geometry/Polygon.class.php | 4 +-- 8 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 lib/geometry/LinearRing.class.php diff --git a/geoPHP.inc b/geoPHP.inc index cdfa4cb0..656ed69e 100644 --- a/geoPHP.inc +++ b/geoPHP.inc @@ -22,7 +22,6 @@ include_once("lib/geometry/Point.class.php"); include_once("lib/geometry/Collection.class.php"); // Abtract class include_once("lib/geometry/LineString.class.php"); include_once("lib/geometry/MultiPoint.class.php"); -include_once("lib/geometry/LinearRing.class.php"); include_once("lib/geometry/Polygon.class.php"); include_once("lib/geometry/MultiLineString.class.php"); include_once("lib/geometry/MultiPolygon.class.php"); @@ -76,7 +75,6 @@ class geoPHP return array( 'point' => 'Point', 'linestring' => 'LineString', - 'linearring' => 'LinearRing', 'polygon' => 'Polygon', 'multipoint' => 'MultiPoint', 'multilinestring' => 'MultiLineString', @@ -120,7 +118,7 @@ class geoPHP // If the geometry cannot even theoretically be reduced more, then pass it back if (gettype($geometry) == 'object') { - $passbacks = array('Point','LineString','LinearRing','Polygon'); + $passbacks = array('Point','LineString','Polygon'); if (in_array($geometry->geometryType(),$passbacks)) { return $geometry; } diff --git a/lib/adapters/GPX.class.php b/lib/adapters/GPX.class.php index 858940c1..4a3cdb1e 100644 --- a/lib/adapters/GPX.class.php +++ b/lib/adapters/GPX.class.php @@ -132,7 +132,6 @@ protected function geometryToGPX($geom) { return $this->pointToGPX($geom); break; case 'linestring': - case 'linearring': return $this->linestringToGPX($geom); break; case 'polygon': diff --git a/lib/adapters/GoogleGeocode.class.php b/lib/adapters/GoogleGeocode.class.php index 98c17d07..bbf3ef37 100644 --- a/lib/adapters/GoogleGeocode.class.php +++ b/lib/adapters/GoogleGeocode.class.php @@ -118,7 +118,7 @@ private function getPolygon($delta = 0) { $this->getBottomLeft($delta), $this->getTopLeft($delta), ); - $outer_ring = new LinearRing($points); + $outer_ring = new LineString($points); return new Polygon(array($outer_ring)); } diff --git a/lib/adapters/KML.class.php b/lib/adapters/KML.class.php index 133d4991..63b19bdb 100644 --- a/lib/adapters/KML.class.php +++ b/lib/adapters/KML.class.php @@ -108,15 +108,6 @@ protected function parseLineString($xml) { return new LineString($point_array); } - protected function parseLinearRing($xml) { - $coordinates = $this->_extractCoordinates($xml); - $components = array(); - foreach ($coordinates as $set) { - $components[] = new Point($set[0],$set[1]); - } - return new LinearRing($components); - } - protected function parsePolygon($xml) { $components = array(); @@ -124,7 +115,7 @@ protected function parsePolygon($xml) { $outer_boundary_element = $outer_boundary_element_a[0]; $outer_ring_element_a = $this->childElements($outer_boundary_element, 'linearring'); $outer_ring_element = $outer_ring_element_a[0]; - $components[] = $this->parseLinearRing($outer_ring_element); + $components[] = $this->parseLineString($outer_ring_element); if (count($components) != 1) { throw new Exception("Invalid KML"); @@ -134,7 +125,7 @@ protected function parsePolygon($xml) { if (count($inner_boundary_element_a)) { $inner_boundary_element = $inner_boundary_element_a[0]; foreach ($this->childElements($inner_boundary_element, 'linearring') as $inner_ring_element) { - $components[] = $this->parseLinearRing($inner_ring_element); + $components[] = $this->parseLineString($inner_ring_element); } } @@ -145,7 +136,8 @@ protected function parseGeometryCollection($xml) { $components = array(); $geom_types = geoPHP::geometryList(); foreach ($xml->childNodes as $child) { - $function = 'parse'.$geom_types[$child->nodeName]; + $nodeName = ($child->nodeName == 'linearring') ? 'linestring' : $child->nodeName; + $function = 'parse'.$geom_types[$nodeName]; $components[] = $this->$function($child); } return new GeometryCollection($components); @@ -178,7 +170,6 @@ private function geometryToKML($geom) { return $this->pointToKML($geom); break; case 'linestring': - case 'linearring': return $this->linestringToKML($geom); break; case 'polygon': diff --git a/lib/adapters/WKT.class.php b/lib/adapters/WKT.class.php index 8489a218..bd365114 100644 --- a/lib/adapters/WKT.class.php +++ b/lib/adapters/WKT.class.php @@ -33,7 +33,6 @@ class WKT extends GeoAdapter const MULTIPOINT = 'multipoint'; const LINESTRING = 'linestring'; const MULTILINESTRING = 'multilinestring'; - const LINEARRING = 'linearring'; const POLYGON = 'polygon'; const MULTIPOLYGON = 'multipolygon'; const GEOMETRYCOLLECTION = 'geometrycollection'; @@ -128,7 +127,7 @@ public function parse($type, $str) { foreach ($rings as $r) { $ring = $this->trimParens( $r ); $linestring = $this->parse(self::LINESTRING, $ring); - $components[] = new LinearRing($linestring->getComponents()); + $components[] = new LineString($linestring->getComponents()); } return new Polygon($components); @@ -188,7 +187,6 @@ public function extract(Geometry $geometry) { case self::POINT: return $geometry->getX().' '.$geometry->getY(); case self::LINESTRING: - case self::LINEARRING: foreach ($geometry as $geom) { $array[] = $this->extract($geom); } diff --git a/lib/geometry/Geometry.class.php b/lib/geometry/Geometry.class.php index 61a37b80..679140b5 100644 --- a/lib/geometry/Geometry.class.php +++ b/lib/geometry/Geometry.class.php @@ -77,7 +77,7 @@ public function envelope() { new Point($bbox['miny'],$bbox['minx']), new Point($bbox['maxy'],$bbox['minx']), ); - $outer_boundary = new LinearRing($points); + $outer_boundary = new LineString($points); return new Polygon(array($outer_boundary)); } diff --git a/lib/geometry/LinearRing.class.php b/lib/geometry/LinearRing.class.php deleted file mode 100644 index c9bd0a05..00000000 --- a/lib/geometry/LinearRing.class.php +++ /dev/null @@ -1,39 +0,0 @@ - - * (c) Patrick Hayes - * - * This code is open-source and licenced under the Modified BSD License. - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * LineString : a LineString geometry. - * - * @package sfMapFishPlugin - * @subpackage GeoJSON - * @author Camptocamp - * @version - */ -class LinearRing extends LineString -{ - protected $geom_type = 'LineString'; - - /** - * Constructor - * - * @param array $positions The Point array - */ - public function __construct(array $positions) { - if (count($positions) > 1) - { - parent::__construct($positions); - } - else - { - throw new Exception("Linestring with less than two points"); - } - } -} - diff --git a/lib/geometry/Polygon.class.php b/lib/geometry/Polygon.class.php index eb55ec30..dbe45bf0 100644 --- a/lib/geometry/Polygon.class.php +++ b/lib/geometry/Polygon.class.php @@ -21,13 +21,11 @@ class Polygon extends Collection * * The first linestring is the outer ring * The subsequent ones are holes - * All linestrings should be a LinearRing + * All linestrings should be a closed LineString * * @param array $linestrings The LineString array */ public function __construct(array $linestrings) { - // the GeoJSON spec (http://geojson.org/geojson-spec.html) says nothing about linestring count. - // What should we do ? if (count($linestrings) > 0) { parent::__construct($linestrings); }