Skip to content

Commit

Permalink
Merge branch 'master' of github.com:phayes/geoPHP
Browse files Browse the repository at this point in the history
  • Loading branch information
phayes committed Jul 6, 2012
2 parents 668db9d + 98d3f1b commit 8943bed
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/adapters/GPX.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class GPX extends GeoAdapter
private $nss = ''; // Name-space string. eg 'georss:'

/**
* Read KML string into geometry objects
* Read GPX string into geometry objects
*
* @param string $kml A KML string
* @param string $gpx A GPX string
*
* @return Geometry|GeometryCollection
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ public function geomFromText($text) {
$text = strtolower($text);
$text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);

// Load into DOMDOcument
// Load into DOMDocument
$xmlobj = new DOMDocument();
@$xmlobj->loadXML($text);
if ($xmlobj === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/GeoJSON.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function read($input) {

// Check to see if it's a Feature
if ($input->type == 'Feature') {
return $this->read($feature->geometry);
return $this->read($input->geometry);
}

// It's a geometry - process it
Expand Down
2 changes: 1 addition & 1 deletion lib/geometry/Collection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function length() {
$next_point = $this->geometryN($delta);
if ($next_point) {
// Pythagorean Theorem
$distance = sqrt(($next_point->getX() - $point->getX())^2+($next_point->getY()- $point->getY())^2);
$distance = sqrt(pow(($next_point->getX() - $point->getX()), 2) + pow(($next_point->getY()- $point->getY()), 2));
$length += $distance;
}
}
Expand Down
22 changes: 22 additions & 0 deletions lib/geometry/Polygon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ public function centroid() {
return $centroid;
}

/**
* Find the outermost point from the centroid
*
* @returns Point The outermost point
*/
public function outermostPoint() {
$centroid = $this->getCentroid();

$max = array('length' => 0, 'point' => null);

foreach($this->getPoints() as $point) {
$lineString = new LineString(array($centroid, $point));

if($lineString->length() > $max['length']) {
$max['length'] = $lineString->length();
$max['point'] = $point;
}
}

return $max['point'];
}

public function exteriorRing() {
if ($this->isEmpty()) return new LineString();
return $this->components[0];
Expand Down
1 change: 1 addition & 0 deletions tests/input/paths_big.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/input/simple_point.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-80.73029, 35.3936]}}

0 comments on commit 8943bed

Please sign in to comment.