laravel-geo
laravel-geo copied to clipboard
GeometryCollection operations (+ added fromArray fn)
I'm trying to implement the fromArray functionality for GeometryCollection, but with this function
public static function fromArray(array $items) {
$parsed = array_map(function($p){
if( !is_array($p) or sizeof($p) != 2)
throw new GeoSpatialException('Error: array of array containing lat, lon expected.');
if ($p['type'] == 'POLYGON') {
$points = array_map(function ($p) {
if( !is_array($p) or sizeof($p) != 2)
throw new GeoSpatialException('Error: array of array containing lat, lon expected.');
return new Point($p[0], $p[1]);
}, $p['value'][0]);
}
return new Polygon([new LineString($points)]);
}, $items);
return new static(new GeometryCollection([$parsed]));
}```
I'm getting this error:
`ElevenLab\PHPOGC\Exceptions\GeoSpatialException with message 'A GeometryCollection must be constructed with an array of OGCObject objects'`
It works fine with this `return new static($parsed));` however, I every whereX query fails, intersection, touches, etc.
I have a few contribs for this library in the pipeline, hoping to gain a deeper understanding here so I can push forward.
Cheers!