Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeometryCollection problem #134

Open
francescods opened this issue Mar 17, 2020 · 1 comment · May be fixed by #150
Open

GeometryCollection problem #134

francescods opened this issue Mar 17, 2020 · 1 comment · May be fixed by #150

Comments

@francescods
Copy link

francescods commented Mar 17, 2020

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

@francescods
Copy link
Author

Hi everyone, has anyone had a chance to read this issue request?
Thank you, have a nice day.

limenet added a commit to limenet/laravel-mysql-spatial that referenced this issue Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant