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

Cannot use "Polygon" type correctly #7

Closed
andresrex opened this issue Aug 22, 2017 · 2 comments
Closed

Cannot use "Polygon" type correctly #7

andresrex opened this issue Aug 22, 2017 · 2 comments
Labels

Comments

@andresrex
Copy link

I have an array of coordinates, which I am passing to the controller and then parse it into an "array of Points" as follows:

            Log::info($request->polygon);
            $arrayOfPoints = [];
            foreach( $request->polygon as $point ){
                $arrayOfPoints[] = new Point($point[0], $point[1]);
            }
            Log::info(new Polygon($arrayOfPoints)); // Line 28

And immediately I get the following error:

[2017-08-22 20:44:51] local.INFO: array (
0 =>
array (
0 => '-99.16897058486938',
1 => '19.424870411471588',
),
1 =>
array (
0 => '-99.16744709014893',
1 => '19.424769230105948',
),
2 =>
array (
0 => '-99.16781187057495',
1 => '19.423433630174305',
),
3 =>
array (
0 => '-99.16882038116455',
1 => '19.4236764673421',
),
)
[2017-08-22 20:44:51] local.ERROR: exception 'InvalidArgumentException' with message '$linestrings must be an array of Points' in /Library/WebServer/Documents/private/private/vendor/grimzy/laravel-mysql-spatial/src/Types/MultiLineString.php:29
Stack trace:
#0 /Library/WebServer/Documents/private/private/app/Http/Controllers/LocationController.php(28): Grimzy\LaravelMysqlSpatial\Types\MultiLineString->__construct(Array)
#1 [internal function]: App\Http\Controllers\LocationController->create(Object(Illuminate\Http\Request))

@grimzy
Copy link
Owner

grimzy commented Aug 23, 2017

Polygon extends MultiLineString, so you need to pass an array of LineString to instantiate it.

$arrayOfPoints = [];
foreach($request->polygon as $point) {
    $arrayOfPoints[] = new Point($point[0], $point[1]);
}
$lineString = new LineString($arrayOfPoints);
$polygon = new Polygon([$lineString]);

MySQL POLYGON supports both the exterior and interior boundaries.

@andresrex
Copy link
Author

Thank you

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

No branches or pull requests

2 participants