Description
Hi, I'm working with Laravel 7, php 7.4 and MySQL 5.7
I have a problem with Geometry::fromJson and a GeometryCollection Feature (single).
I have a column geo_data
of type geometry
and I have manually stored in it a GeometryCollection
composed of a Point
and a Linestring
.
When I read it from the db it works as expected.
$map = Map::with('elements')->find(7);
print_r($map->elements->first()->geo_data);
gives me the correct Grimzy\LaravelMysqlSpatial\Types\GeometryCollection Object
and
$map->elements->first()->geo_data->toJson()
is correctly
{ type: "GeometryCollection", geometries: [ { type: "Point", coordinates: [ 30, 30 ] }, { type: "LineString", coordinates: [ [ 0, 0 ], [ 10, 10 ], [ 20, 20 ] ] } ] }
But if I convert the json back (to store to the db)
Geometry::fromJson('{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[30,30]},{"type":"LineString","coordinates":[[0,0],[10,10],[20,20]]}]}');
I get the following error
Expected GeoJson\Feature\FeatureCollection, got GeoJson\Geometry\GeometryCollection .../vendor/grimzy/laravel-mysql-spatial/src/Types/GeometryCollection.php:130
If I use this json:
Geometry::fromJson('{"type":"Feature","id":46,"geometry":{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[30,30]},{"type":"LineString","coordinates":[[0,0],[10,10],[20,20]]}]}}');
I get the same error.
Can you help me how to solve this problem?
Thank you for your support