Skip to content

Commit

Permalink
Adding project method - other various cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phayes committed Aug 27, 2012
1 parent f3fc207 commit 91d37ec
Showing 1 changed file with 70 additions and 65 deletions.
135 changes: 70 additions & 65 deletions lib/geometry/Geometry.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class Geometry
private $geos = NULL;
protected $srid = NULL;
protected $geom_type;

// Abtract: Standard
// -----------------
abstract public function area();
Expand All @@ -32,35 +32,35 @@ abstract public function dimension();
abstract public function equals($geom);
abstract public function isEmpty();
abstract public function isSimple();

// Abtract: Non-Standard
// ---------------------
abstract public function getBBox();
abstract public function asArray();
abstract public function getPoints();
abstract public function explode();


// Public: Standard -- Common to all geometries
// --------------------------------------------
public function SRID() {
return $this->srid;
}

public function setSRID($srid) {
if ($this->geos()) {
$this->geos()->setSRID($srid);
}
$this->srid = $srid;
}

public function envelope() {
if ($this->isEmpty()) return new Polygon();

if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->envelope());
}

$bbox = $this->getBBox();
$points = array (
new Point($bbox['maxx'],$bbox['miny']),
Expand All @@ -69,22 +69,22 @@ public function envelope() {
new Point($bbox['minx'],$bbox['miny']),
new Point($bbox['maxx'],$bbox['miny']),
);

$outer_boundary = new LineString($points);
return new Polygon(array($outer_boundary));
}

public function geometryType() {
return $this->geom_type;
}

// Public: Non-Standard -- Common to all geometries
// ------------------------------------------------

// $this->out($format, $other_args);
public function out() {
$args = func_get_args();

$format = array_shift($args);
$type_map = geoPHP::getAdapterMap();
$processor_type = $type_map[$format];
Expand All @@ -95,22 +95,22 @@ public function out() {

return $result;
}


// Public: Aliases
// ---------------
public function getCentroid() {
return $this->centroid();
}

public function getArea() {
return $this->area();
}

public function getX() {
return $this->x();
}

public function getY() {
return $this->y();
}
Expand All @@ -130,11 +130,11 @@ public function getSRID() {
public function asText() {
return $this->out('wkt');
}

public function asBinary() {
return $this->out('wkb');
}

// Public: GEOS Only Functions
// ---------------------------
public function geos() {
Expand All @@ -156,20 +156,20 @@ public function geos() {
public function setGeos($geos) {
$this->geos = $geos;
}

public function pointOnSurface() {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->pointOnSurface());
}
}
public function equalsExact($geometry) {

public function equalsExact(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->equalsExact($geometry->geos());
}
}
public function relate($geometry, $pattern = NULL) {

public function relate(Geometry $geometry, $pattern = NULL) {
if ($this->geos()) {
if ($pattern) {
return $this->geos()->relate($geometry->geos(), $pattern);
Expand All @@ -179,45 +179,45 @@ public function relate($geometry, $pattern = NULL) {
}
}
}

public function checkValidity() {
if ($this->geos()) {
return $this->geos()->checkValidity();
}
}

public function buffer($distance) {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->buffer($distance));
}
}
public function intersection($geometry) {

public function intersection(Geometry $geometry) {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->intersection($geometry->geos()));
}
}

public function convexHull() {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->convexHull());
}
}
public function difference($geometry) {

public function difference(Geometry $geometry) {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->difference($geometry->geos()));
}
}
public function symDifference($geometry) {

public function symDifference(Geometry $geometry) {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->symDifference($geometry->geos()));
}
}

// Can pass in a geometry or an array of geometries
public function union($geometry) {
public function union(Geometry $geometry) {
if ($this->geos()) {
if (is_array($geometry)) {
$geom = $this->geos();
Expand All @@ -231,102 +231,107 @@ public function union($geometry) {
}
}
}

public function simplify($tolerance, $preserveTopology = FALSE) {
if ($this->geos()) {
return geoPHP::geosToGeometry($this->geos()->simplify($tolerance, $preserveTopology));
}
}
public function disjoint($geometry) {

public function disjoint(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->disjoint($geometry->geos());
}
}
public function touches($geometry) {

public function touches(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->touches($geometry->geos());
}
}
public function intersects($geometry) {

public function intersects(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->intersects($geometry->geos());
}
}
public function crosses($geometry) {

public function crosses(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->crosses($geometry->geos());
}
}

public function within($geometry) {
public function within(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->within($geometry->geos());
}
}
public function contains($geometry) {

public function contains(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->contains($geometry->geos());
}
}
public function overlaps($geometry) {

public function overlaps(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->overlaps($geometry->geos());
}
}
public function covers($geometry) {

public function covers(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->covers($geometry->geos());
}
}
public function coveredBy($geometry) {

public function coveredBy(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->coveredBy($geometry->geos());
}
}

public function distance($geometry) {
public function distance(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->distance($geometry->geos());
}
}
public function hausdorffDistance($geometry) {

public function hausdorffDistance(Geometry $geometry) {
if ($this->geos()) {
return $this->geos()->hausdorffDistance($geometry->geos());
}
}



public function project(Geometry $point, $normalized = NULL) {
if ($this->geos()) {
return $this->geos()->project($point->geos(), $normalized);
}
}

// Public - Placeholders
// ---------------------
public function hasZ() {
// geoPHP does not support Z values at the moment
return FALSE;
return FALSE;
}

public function is3D() {
// geoPHP does not support 3D geometries at the moment
return FALSE;
return FALSE;
}

public function isMeasured() {
// geoPHP does not yet support M values
return FALSE;
}

public function coordinateDimension() {
// geoPHP only supports 2-dimentional space
return 2;
}

public function z() {
// geoPHP only supports 2-dimentional space
return NULL;
Expand All @@ -336,5 +341,5 @@ public function m() {
// geoPHP only supports 2-dimentional space
return NULL;
}

}

0 comments on commit 91d37ec

Please sign in to comment.