You are here

public function Geometry::envelope in geoPHP 8

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

File

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

Class

Geometry
Geometry abstract class

Code

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,
  ));
}