Make farm_map_combine_geoms() more resilient to empty geometries.

This commit is contained in:
Michael Stenta 2020-07-15 13:45:19 -04:00
parent 4b9df8fe63
commit 7e930dd210
1 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,11 @@ function farm_map_combine_geoms($geoms = array()) {
$wkt_strings = array();
foreach ($geoms as &$geom) {
// If the geometry is empty, skip it.
if (empty($geom)) {
continue;
}
// Convert to a GeoPHP geometry object.
$geometry = geoPHP::load($geom, 'wkt');
@ -130,6 +135,11 @@ function farm_map_combine_geoms($geoms = array()) {
// Combine all the WKT strings together into one.
$wkt = implode(',', $wkt_strings);
// If the WKT is empty, bail.
if (empty($wkt)) {
return FALSE;
}
// If there is more than one geometry, wrap them all in a geometry collection.
if ($geometrycollection) {
$wkt = 'GEOMETRYCOLLECTION (' . $wkt . ')';