Skip to content

Commit

Permalink
Removing LinearRing concept. We now only have LineString that are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
phayes committed Apr 22, 2011
1 parent efb8e54 commit bfa3ef7
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 64 deletions.
4 changes: 1 addition & 3 deletions geoPHP.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -76,7 +75,6 @@ class geoPHP
return array(
'point' => 'Point',
'linestring' => 'LineString',
'linearring' => 'LinearRing',
'polygon' => 'Polygon',
'multipoint' => 'MultiPoint',
'multilinestring' => 'MultiLineString',
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion lib/adapters/GPX.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected function geometryToGPX($geom) {
return $this->pointToGPX($geom);
break;
case 'linestring':
case 'linearring':
return $this->linestringToGPX($geom);
break;
case 'polygon':
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/GoogleGeocode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
17 changes: 4 additions & 13 deletions lib/adapters/KML.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,14 @@ 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();

$outer_boundary_element_a = $this->childElements($xml, 'outerboundaryis');
$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");
Expand All @@ -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);
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -178,7 +170,6 @@ private function geometryToKML($geom) {
return $this->pointToKML($geom);
break;
case 'linestring':
case 'linearring':
return $this->linestringToKML($geom);
break;
case 'polygon':
Expand Down
4 changes: 1 addition & 3 deletions lib/adapters/WKT.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/geometry/Geometry.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
39 changes: 0 additions & 39 deletions lib/geometry/LinearRing.class.php

This file was deleted.

4 changes: 1 addition & 3 deletions lib/geometry/Polygon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit bfa3ef7

Please sign in to comment.