Description
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.