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

Inconsistent toArray() method #110

Open
augusthur opened this issue Nov 11, 2019 · 2 comments
Open

Inconsistent toArray() method #110

augusthur opened this issue Nov 11, 2019 · 2 comments

Comments

@augusthur
Copy link

GeometryCollection is an Arrayable, and toArray() is the way to get the items from it. But then Other classes extend from GeometryCollection. Like MultiLineString or Polygon. They already have getLineStrings() to get its items but because they extend from GeometryCollection also they have the toArray() to get the same result.

The problem is how Eloquent works with Arrayables. For example, when using mutators, it returns the result of toArray() for Arrayable Classes.

Another example of strange behavior:

$polygon = new Polygon([new LineString([
    new Point(40.74894149554006, -73.98615270853043),
    new Point(40.74848633046773, -73.98648262023926),
    new Point(40.747925497790725, -73.9851602911949),
    new Point(40.74837050671544, -73.98482501506805),
    new Point(40.74894149554006, -73.98615270853043)
])]);

If we make $polygon->toArray(), we get this:

[
  {
    "type": "LineString",
    "coordinates": [
      [-73.98615270853,40.74894149554],
      [-73.986482620239,40.748486330468],
      [-73.985160291195,40.747925497791],
      [-73.984825015068,40.748370506715],
      [-73.98615270853,40.74894149554]
    ]
  }
]

I think it's the expected result for $polygon->getLineStrings() not toArray, which should just return an array representation of the polygon, something like:

{
  "type": "Polygon",
  "coordinates": [
    [
      [-73.98615270853,40.74894149554],
      [-73.986482620239,40.748486330468],
      [-73.985160291195,40.747925497791],
      [-73.984825015068,40.748370506715],
      [-73.98615270853,40.74894149554]
    ]
  ]
}

Maybe it's posible to write a toArray() method for classes like MultiPoint, MultiLineString or Polygon in order to avoid side effects of the method inherited by GeometryCollection.

@grimzy
Copy link
Owner

grimzy commented Mar 9, 2020

Possibly good idea; I'll look into it sometime soon.

Feel free to submit a PR 😄 💪 🎉

@grimzy
Copy link
Owner

grimzy commented Mar 9, 2020

Is this related to #96 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants