Geometry.class.php in geoPHP 8
File
geoPHP/lib/geometry/Geometry.class.php
View source
<?php
abstract class Geometry {
private $geos = NULL;
protected $srid = NULL;
protected $geom_type;
public abstract function area();
public abstract function boundary();
public abstract function centroid();
public abstract function length();
public abstract function y();
public abstract function x();
public abstract function numGeometries();
public abstract function geometryN($n);
public abstract function startPoint();
public abstract function endPoint();
public abstract function isRing();
public abstract function isClosed();
public abstract function numPoints();
public abstract function pointN($n);
public abstract function exteriorRing();
public abstract function numInteriorRings();
public abstract function interiorRingN($n);
public abstract function dimension();
public abstract function equals($geom);
public abstract function isEmpty();
public abstract function isSimple();
public abstract function getBBox();
public abstract function asArray();
public abstract function getPoints();
public abstract function explode();
public abstract function greatCircleLength();
public abstract function haversineLength();
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']),
new Point($bbox['maxx'], $bbox['maxy']),
new Point($bbox['minx'], $bbox['maxy']),
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 function out() {
$args = func_get_args();
$format = array_shift($args);
$type_map = geoPHP::getAdapterMap();
$processor_type = $type_map[$format];
$processor = new $processor_type();
array_unshift($args, $this);
$result = call_user_func_array(array(
$processor,
'write',
), $args);
return $result;
}
public function getCentroid() {
return $this
->centroid();
}
public function getArea() {
return $this
->area();
}
public function getX() {
return $this
->x();
}
public function getY() {
return $this
->y();
}
public function getGeos() {
return $this
->geos();
}
public function getGeomType() {
return $this
->geometryType();
}
public function getSRID() {
return $this
->SRID();
}
public function asText() {
return $this
->out('wkt');
}
public function asBinary() {
return $this
->out('wkb');
}
public function geos() {
if ($this->geos && geoPHP::geosInstalled()) {
return $this->geos;
}
if (geoPHP::geosInstalled()) {
$reader = new GEOSWKBReader();
$this->geos = $reader
->readHEX($this
->out('wkb', TRUE));
}
else {
$this->geos = FALSE;
}
return $this->geos;
}
public function setGeos($geos) {
$this->geos = $geos;
}
public function pointOnSurface() {
if ($this
->geos()) {
return geoPHP::geosToGeometry($this
->geos()
->pointOnSurface());
}
}
public function equalsExact(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->equalsExact($geometry
->geos());
}
}
public function relate(Geometry $geometry, $pattern = NULL) {
if ($this
->geos()) {
if ($pattern) {
return $this
->geos()
->relate($geometry
->geos(), $pattern);
}
else {
return $this
->geos()
->relate($geometry
->geos());
}
}
}
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 $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 $geometry) {
if ($this
->geos()) {
return geoPHP::geosToGeometry($this
->geos()
->difference($geometry
->geos()));
}
}
public function symDifference(Geometry $geometry) {
if ($this
->geos()) {
return geoPHP::geosToGeometry($this
->geos()
->symDifference($geometry
->geos()));
}
}
public function union(Geometry $geometry) {
if ($this
->geos()) {
if (is_array($geometry)) {
$geom = $this
->geos();
foreach ($geometry as $item) {
$geom = $geom
->union($item
->geos());
}
return geoPHP::geosToGeometry($geos);
}
else {
return geoPHP::geosToGeometry($this
->geos()
->union($geometry
->geos()));
}
}
}
public function simplify($tolerance, $preserveTopology = FALSE) {
if ($this
->geos()) {
return geoPHP::geosToGeometry($this
->geos()
->simplify($tolerance, $preserveTopology));
}
}
public function disjoint(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->disjoint($geometry
->geos());
}
}
public function touches(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->touches($geometry
->geos());
}
}
public function intersects(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->intersects($geometry
->geos());
}
}
public function crosses(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->crosses($geometry
->geos());
}
}
public function within(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->within($geometry
->geos());
}
}
public function contains(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->contains($geometry
->geos());
}
}
public function overlaps(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->overlaps($geometry
->geos());
}
}
public function covers(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->covers($geometry
->geos());
}
}
public function coveredBy(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->coveredBy($geometry
->geos());
}
}
public function distance(Geometry $geometry) {
if ($this
->geos()) {
return $this
->geos()
->distance($geometry
->geos());
}
}
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 function hasZ() {
return FALSE;
}
public function is3D() {
return FALSE;
}
public function isMeasured() {
return FALSE;
}
public function coordinateDimension() {
return 2;
}
public function z() {
return NULL;
}
public function m() {
return NULL;
}
}