public function Collection::centroid in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/lib/geometry/Collection.class.php \Collection::centroid()
Overrides Geometry::centroid
1 method overrides Collection::centroid()
- Polygon::centroid in geoPHP/
lib/ geometry/ Polygon.class.php
File
- geoPHP/
lib/ geometry/ Collection.class.php, line 43
Class
- Collection
- Collection: Abstract class for compound geometries
Code
public function centroid() {
if ($this
->isEmpty()) {
return NULL;
}
if ($this
->geos()) {
$geos_centroid = $this
->geos()
->centroid();
if ($geos_centroid
->typeName() == 'Point') {
return geoPHP::geosToGeometry($this
->geos()
->centroid());
}
}
// As a rough estimate, we say that the centroid of a colletion is the centroid of it's envelope
// @@TODO: Make this the centroid of the convexHull
// Note: Outside of polygons, geometryCollections and the trivial case of points, there is no standard on what a "centroid" is
$centroid = $this
->envelope()
->centroid();
return $centroid;
}