Point.class.php in geoPHP 7
File
geoPHP/lib/geometry/Point.class.php
View source
<?php
class Point extends Geometry {
public $coords = array(
2,
);
protected $geom_type = 'Point';
protected $dimension = 2;
public function __construct($x = NULL, $y = NULL, $z = NULL) {
if ($x === NULL && $y === NULL) {
$this->coords = array(
NULL,
NULL,
);
$this->dimension = 0;
return;
}
$x = (double) str_replace(',', '.', $x);
$y = (double) str_replace(',', '.', $y);
if (!is_numeric($x) || !is_numeric($y)) {
throw new Exception("Cannot construct Point. x and y should be numeric");
}
if ($z !== NULL) {
if (!is_numeric($z)) {
throw new Exception("Cannot construct Point. z should be numeric");
}
$this->dimension = 3;
}
$x = floatval($x);
$y = floatval($y);
$z = floatval($z);
if ($this->dimension == 2) {
$this->coords = array(
$x,
$y,
);
}
if ($this->dimension == 3) {
$this->coords = array(
$x,
$y,
$z,
);
}
}
public function x() {
return $this->coords[0];
}
public function y() {
return $this->coords[1];
}
public function z() {
if ($this->dimension == 3) {
return $this->coords[2];
}
else {
return NULL;
}
}
public function centroid() {
return $this;
}
public function getBBox() {
return array(
'maxy' => $this
->getY(),
'miny' => $this
->getY(),
'maxx' => $this
->getX(),
'minx' => $this
->getX(),
);
}
public function asArray($assoc = FALSE) {
return $this->coords;
}
public function area() {
return 0;
}
public function length() {
return 0;
}
public function greatCircleLength() {
return 0;
}
public function haversineLength() {
return 0;
}
public function boundary() {
return $this;
}
public function dimension() {
return 0;
}
public function isEmpty() {
if ($this->dimension == 0) {
return TRUE;
}
else {
return FALSE;
}
}
public function numPoints() {
return 1;
}
public function getPoints() {
return array(
$this,
);
}
public function equals($geometry) {
if (get_class($geometry) != 'Point') {
return FALSE;
}
if (!$this
->isEmpty() && !$geometry
->isEmpty()) {
return $this
->x() == $geometry
->x() && $this
->y() == $geometry
->y();
}
else {
if ($this
->isEmpty() && $geometry
->isEmpty()) {
return TRUE;
}
else {
return FALSE;
}
}
}
public function isSimple() {
return TRUE;
}
public function numGeometries() {
return NULL;
}
public function geometryN($n) {
return NULL;
}
public function startPoint() {
return NULL;
}
public function endPoint() {
return NULL;
}
public function isRing() {
return NULL;
}
public function isClosed() {
return NULL;
}
public function pointN($n) {
return NULL;
}
public function exteriorRing() {
return NULL;
}
public function numInteriorRings() {
return NULL;
}
public function interiorRingN($n) {
return NULL;
}
public function pointOnSurface() {
return NULL;
}
public function explode() {
return NULL;
}
}
Classes
Name |
Description |
Point |
Point: The most basic geometry type. All other geometries
are built out of Points. |