static function geoPHP::geometryReduce in geoPHP 8
Same name and namespace in other branches
- 7 geoPHP/geoPHP.inc \geoPHP::geometryReduce()
6 calls to geoPHP::geometryReduce()
- Collection::boundary in geoPHP/lib/geometry/Collection.class.php
- GeoJSON::read in geoPHP/lib/adapters/GeoJSON.class.php
- Given an object or a string, return a Geometry
- geoPHP::load in geoPHP/geoPHP.inc
- GeoRSS::geomFromXML in geoPHP/lib/adapters/GeoRSS.class.php
- GPX::geomFromXML in geoPHP/lib/adapters/GPX.class.php
... See full list
File
- geoPHP/geoPHP.inc, line 147
Class
- geoPHP
Code
static function geometryReduce($geometry) {
if (is_array($geometry)) {
if (empty($geometry)) {
return FALSE;
}
if (count($geometry) == 1) {
return geoPHP::geometryReduce($geometry[0]);
}
}
if (gettype($geometry) == 'object') {
$passbacks = array(
'Point',
'LineString',
'Polygon',
);
if (in_array($geometry
->geometryType(), $passbacks)) {
return $geometry;
}
}
if (gettype($geometry) == 'object') {
$simple_collections = array(
'MultiPoint',
'MultiLineString',
'MultiPolygon',
);
if (in_array(get_class($geometry), $passbacks)) {
$components = $geometry
->getComponents();
if (count($components) == 1) {
return $components[0];
}
else {
return $geometry;
}
}
}
if (!is_array($geometry)) {
$geometry = array(
$geometry,
);
}
$geometries = array();
$geom_types = array();
$collections = array(
'MultiPoint',
'MultiLineString',
'MultiPolygon',
'GeometryCollection',
);
foreach ($geometry as $item) {
if ($item) {
if (in_array(get_class($item), $collections)) {
foreach ($item
->getComponents() as $component) {
$geometries[] = $component;
$geom_types[] = $component
->geometryType();
}
}
else {
$geometries[] = $item;
$geom_types[] = $item
->geometryType();
}
}
}
$geom_types = array_unique($geom_types);
if (empty($geom_types)) {
return FALSE;
}
if (count($geom_types) == 1) {
if (count($geometries) == 1) {
return $geometries[0];
}
else {
$class = 'Multi' . $geom_types[0];
return new $class($geometries);
}
}
else {
return new GeometryCollection($geometries);
}
}