You are here

abstract class Geometry in geoPHP 8

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

Geometry abstract class

Hierarchy

Expanded class hierarchy of Geometry

File

geoPHP/lib/geometry/Geometry.class.php, line 6

View source
abstract class Geometry {
  private $geos = NULL;
  protected $srid = NULL;
  protected $geom_type;

  // Abtract: Standard
  // -----------------
  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();

  // Mssing dependancy
  public abstract function isClosed();

  // Missing dependancy
  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();

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

  //meters
  public abstract function haversineLength();

  //degrees

  // 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']),
      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: 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];
    $processor = new $processor_type();
    array_unshift($args, $this);
    $result = call_user_func_array(array(
      $processor,
      'write',
    ), $args);
    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();
  }
  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: GEOS Only Functions
  // ---------------------------
  public function geos() {

    // If it's already been set, just return it
    if ($this->geos && geoPHP::geosInstalled()) {
      return $this->geos;
    }

    // It hasn't been set yet, generate it
    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()));
    }
  }

  // Can pass in a geometry or an array of geometries
  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 - Placeholders
  // ---------------------
  public function hasZ() {

    // geoPHP does not support Z values at the moment
    return FALSE;
  }
  public function is3D() {

    // geoPHP does not support 3D geometries at the moment
    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;
  }
  public function m() {

    // geoPHP only supports 2-dimentional space
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Geometry::$geom_type protected property 7
Geometry::$geos private property
Geometry::$srid protected property
Geometry::area abstract public function 2
Geometry::asArray abstract public function 2
Geometry::asBinary public function
Geometry::asText public function
Geometry::boundary abstract public function 2
Geometry::buffer public function
Geometry::centroid abstract public function 2
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::dimension abstract public function 2
Geometry::disjoint public function
Geometry::distance public function
Geometry::endPoint abstract public function 2
Geometry::envelope public function
Geometry::equals abstract public function 2
Geometry::equalsExact public function
Geometry::explode abstract public function 2
Geometry::exteriorRing abstract public function 2
Geometry::geometryN abstract public function 2
Geometry::geometryType public function
Geometry::geos public function
Geometry::getArea public function
Geometry::getBBox abstract public function 2
Geometry::getCentroid public function
Geometry::getGeomType public function
Geometry::getGeos public function
Geometry::getPoints abstract public function 2
Geometry::getSRID public function
Geometry::getX public function
Geometry::getY public function
Geometry::greatCircleLength abstract public function 2
Geometry::hasZ public function
Geometry::hausdorffDistance public function
Geometry::haversineLength abstract public function 2
Geometry::interiorRingN abstract public function 2
Geometry::intersection public function
Geometry::intersects public function
Geometry::is3D public function
Geometry::isClosed abstract public function 2
Geometry::isEmpty abstract public function 2
Geometry::isMeasured public function
Geometry::isRing abstract public function 2
Geometry::isSimple abstract public function 2
Geometry::length abstract public function 2
Geometry::m public function
Geometry::numGeometries abstract public function 2
Geometry::numInteriorRings abstract public function 2
Geometry::numPoints abstract public function 2
Geometry::out public function
Geometry::overlaps public function
Geometry::pointN abstract public function 2
Geometry::pointOnSurface public function 2
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::startPoint abstract public function 2
Geometry::symDifference public function
Geometry::touches public function
Geometry::union public function
Geometry::within public function
Geometry::x abstract public function 2
Geometry::y abstract public function 2
Geometry::z public function 1