addGeometry($Geometry); } } } public function getBoundingBox() { if ($this->isEmpty()) { return null; } $ret = $this->getCustomBoundingBox(); if (!$ret) { $is_z = $this->isZ(); $is_m = $this->isM(); foreach ($this->geometries as $Geometry) { $bbox = $Geometry->getBoundingBox(); if (!$ret) { $ret = $bbox; } elseif ($bbox) { if ($bbox['xmin'] < $ret['xmin']) { $ret['xmin'] = $bbox['xmin']; } if ($bbox['xmax'] > $ret['xmax']) { $ret['xmax'] = $bbox['xmax']; } if ($bbox['ymin'] < $ret['ymin']) { $ret['ymin'] = $bbox['ymin']; } if ($bbox['ymax'] > $ret['ymax']) { $ret['ymax'] = $bbox['ymax']; } if ($is_z) { if ($bbox['zmin'] < $ret['zmin']) { $ret['zmin'] = $bbox['zmin']; } if ($bbox['zmax'] > $ret['zmax']) { $ret['zmax'] = $bbox['zmax']; } } if ($is_m) { if ($ret['mmin'] === false || $bbox['mmin'] < $ret['mmin']) { $ret['mmin'] = $bbox['mmin']; } if ($ret['mmax'] === false || $bbox['mmax'] > $ret['mmax']) { $ret['mmax'] = $bbox['mmax']; } } } } } return $ret; } /////////////////////////////// PROTECTED /////////////////////////////// /** * Adds a Geometry to the collection. * It enforces all geometries to be of the same type. * * @param \Shapefile\Geometry\Geometry $Geometry * * @return self Returns $this to provide a fluent interface. */ protected function addGeometry(Geometry $Geometry) { if (!is_a($Geometry, $this->getCollectionClass())) { throw new ShapefileException(Shapefile::ERR_INPUT_GEOMETRY_TYPE_NOT_VALID, $this->getCollectionClass()); } if (!$Geometry->isEmpty()) { if ($this->isEmpty()) { $this->setFlagEmpty(false); $this->setFlagZ($Geometry->isZ()); $this->setFlagM($Geometry->isM()); } else { if ($this->isZ() !== $Geometry->isZ() || $this->isM() !== $Geometry->isM()) { throw new ShapefileException(Shapefile::ERR_GEOM_MISMATCHED_DIMENSIONS); } } $this->geometries[] = $Geometry; } return $this; } /** * Gets a Geometry at specified index from the collection. * * @param int $index The index of the Geometry. * * @return \Shapefile\Geometry\Geometry */ protected function getGeometry($index) { if (!isset($this->geometries[$index])) { throw new ShapefileException(Shapefile::ERR_INPUT_GEOMETRY_INDEX_NOT_VALID, $index); } return $this->geometries[$index]; } /** * Gets all the geometries in the collection. * * @return \Shapefile\Geometry\Geometry[] */ protected function getGeometries() { return $this->geometries; } /** * Gets the number of geometries in the collection. * * @return int */ protected function getNumGeometries() { return count($this->geometries); } /** * Reverses the order of geometries in the collection. * * @return self Returns $this to provide a fluent interface. */ protected function reverseGeometries() { $this->geometries = array_reverse($this->geometries); return $this; } }