You are here

class Point in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/geometry/Point.class.php \Point

Point: The most basic geometry type. All other geometries are built out of Points.

Hierarchy

Expanded class hierarchy of Point

13 string references to 'Point'
AliasesTests::testAliases in geoPHP/tests/tests/aliasesTest.php
Collection::centroid in geoPHP/lib/geometry/Collection.class.php
Collection::getBBox in geoPHP/lib/geometry/Collection.class.php
EWKB::write in geoPHP/lib/adapters/EWKB.class.php
Serialize geometries into an EWKB binary string.
GeoHash::write in geoPHP/lib/adapters/GeoHash.class.php
Convert the geometry to geohash.

... See full list

File

geoPHP/lib/geometry/Point.class.php, line 7

View source
class Point extends Geometry {
  public $coords = array(
    2,
  );
  protected $geom_type = 'Point';
  protected $dimention = 2;

  /**
   * Constructor
   *
   * @param numeric $x The x coordinate (or longitude)
   * @param numeric $y The y coordinate (or latitude)
   * @param numeric $z The z coordinate (or altitude) - optional
   */
  public function __construct($x, $y, $z = NULL) {

    // Basic validation on x and y
    if (!is_numeric($x) || !is_numeric($y)) {
      throw new Exception("Cannot construct Point. x and y should be numeric");
    }

    // Check to see if this is a 3D point
    if ($z !== NULL) {
      if (!is_numeric($z)) {
        throw new Exception("Cannot construct Point. z should be numeric");
      }
      $this->dimention = 3;
    }

    // Convert to floatval in case they are passed in as a string or integer etc.
    $x = floatval($x);
    $y = floatval($y);
    $z = floatval($z);

    // Add poitional elements
    if ($this->dimention == 2) {
      $this->coords = array(
        $x,
        $y,
      );
    }
    if ($this->dimention == 3) {
      $this->coords = array(
        $x,
        $y,
        $z,
      );
    }
  }

  /**
   * Get X (longitude) coordinate
   *
   * @return float The X coordinate
   */
  public function x() {
    return $this->coords[0];
  }

  /**
   * Returns Y (latitude) coordinate
   *
   * @return float The Y coordinate
   */
  public function y() {
    return $this->coords[1];
  }

  /**
   * Returns Z (altitude) coordinate
   *
   * @return float The Z coordinate or NULL is not a 3D point
   */
  public function z() {
    if ($this->dimention == 3) {
      return $this->coords[2];
    }
    else {
      return NULL;
    }
  }

  // A point's centroid is itself
  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;
  }

  // The boundary of a point is itself
  public function boundary() {
    return $this;
  }
  public function dimension() {
    return 0;
  }
  public function isEmpty() {
    return FALSE;
  }
  public function numPoints() {
    return 1;
  }
  public function getPoints() {
    return array(
      $this,
    );
  }
  public function equals($geometry) {
    return $this
      ->x() == $geometry
      ->x() && $this
      ->y() == $geometry
      ->y();
  }
  public function isSimple() {
    return TRUE;
  }

  // Not valid for this geometry type
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Geometry::$geos private property
Geometry::$srid protected property
Geometry::asBinary public function
Geometry::asText public function
Geometry::buffer public function
Geometry::checkValidity public function
Geometry::contains public function
Geometry::convexHull public function
Geometry::coordinateDimension public function
Geometry::coveredBy public function
Geometry::covers public function
Geometry::crosses public function
Geometry::difference public function
Geometry::disjoint public function
Geometry::distance public function
Geometry::envelope public function
Geometry::equalsExact public function
Geometry::geometryType public function
Geometry::geos public function
Geometry::getArea public function
Geometry::getCentroid public function
Geometry::getGeomType public function
Geometry::getGeos public function
Geometry::getSRID public function
Geometry::getX public function
Geometry::getY public function
Geometry::hasZ public function
Geometry::hausdorffDistance public function
Geometry::intersection public function
Geometry::intersects public function
Geometry::is3D public function
Geometry::isMeasured public function
Geometry::m public function
Geometry::out public function
Geometry::overlaps public function
Geometry::project public function
Geometry::relate public function
Geometry::setGeos public function
Geometry::setSRID public function
Geometry::simplify public function
Geometry::SRID public function
Geometry::symDifference public function
Geometry::touches public function
Geometry::union public function
Geometry::within public function
Point::$coords public property
Point::$dimention protected property
Point::$geom_type protected property Overrides Geometry::$geom_type
Point::area public function Overrides Geometry::area
Point::asArray public function Overrides Geometry::asArray
Point::boundary public function Overrides Geometry::boundary
Point::centroid public function Overrides Geometry::centroid
Point::dimension public function Overrides Geometry::dimension
Point::endPoint public function Overrides Geometry::endPoint
Point::equals public function Overrides Geometry::equals
Point::explode public function Overrides Geometry::explode
Point::exteriorRing public function Overrides Geometry::exteriorRing
Point::geometryN public function Overrides Geometry::geometryN
Point::getBBox public function Overrides Geometry::getBBox
Point::getPoints public function Overrides Geometry::getPoints
Point::greatCircleLength public function Overrides Geometry::greatCircleLength
Point::haversineLength public function Overrides Geometry::haversineLength
Point::interiorRingN public function Overrides Geometry::interiorRingN
Point::isClosed public function Overrides Geometry::isClosed
Point::isEmpty public function Overrides Geometry::isEmpty
Point::isRing public function Overrides Geometry::isRing
Point::isSimple public function Overrides Geometry::isSimple
Point::length public function Overrides Geometry::length
Point::numGeometries public function Overrides Geometry::numGeometries
Point::numInteriorRings public function Overrides Geometry::numInteriorRings
Point::numPoints public function Overrides Geometry::numPoints
Point::pointN public function Overrides Geometry::pointN
Point::pointOnSurface public function Overrides Geometry::pointOnSurface
Point::startPoint public function Overrides Geometry::startPoint
Point::x public function Get X (longitude) coordinate Overrides Geometry::x
Point::y public function Returns Y (latitude) coordinate Overrides Geometry::y
Point::z public function Returns Z (altitude) coordinate Overrides Geometry::z
Point::__construct public function Constructor