You are here

public function Collection::__construct in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/lib/geometry/Collection.class.php \Collection::__construct()

Constructor: Checks and sets component geometries

Parameters

array $components array of geometries:

1 call to Collection::__construct()
LineString::__construct in geoPHP/lib/geometry/LineString.class.php
Constructor
1 method overrides Collection::__construct()
LineString::__construct in geoPHP/lib/geometry/LineString.class.php
Constructor

File

geoPHP/lib/geometry/Collection.class.php, line 20

Class

Collection
Collection: Abstract class for compound geometries

Code

public function __construct($components = array()) {
  if (!is_array($components)) {
    throw new Exception("Component geometries must be passed as an array");
  }
  foreach ($components as $component) {
    if ($component instanceof Geometry) {
      $this->components[] = $component;
    }
    else {
      throw new Exception("Cannot create a collection with non-geometries");
    }
  }
}