Skip to content

GeometryCollection problem #134

Open
@francescods

Description

@francescods

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

Activity

francescods

francescods commented on Apr 11, 2020

@francescods
Author

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

added a commit that references this issue on Oct 2, 2020
c28fb98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @francescods

      Issue actions

        GeometryCollection problem · Issue #134 · grimzy/laravel-mysql-spatial