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 construct Point. x and y should be numeric: trim coordinates #181

Open
jbogdani opened this issue Mar 15, 2021 · 2 comments
Open

Comments

@jbogdani
Copy link

Hello and thank you for this library.

I'm having an issue on loading WKT with extra spaces, for instance:

$geo = \geoPHP::load('POINT ( 1 1 )', 'wkt');

As I can see at Point.class.php the basic validation is failing due to the trailing space on the first coordinate. I know I can clean my data by removing these spaces, but the point is that POINT ( 1 1 ) is valid WKT, and I guess geoPHP should parse it correctly.

I guess that trimming the input could solve this issue:
Point.class.php:

if (!is_numeric(trim($x)) || !is_numeric(trim($y))) {
    throw new Exception("Cannot construct Point. x and y should be numeric");
}
// Check to see if this is a 3D point
if ($z !== NULL) {
    if (!is_numeric(trim($z))) {
        throw new Exception("Cannot construct Point. z should be numeric");
    }
    $this->dimension = 3;
}

The floatval below also trims the values, so there is no need to repeat the trim after the validation.

@BathoryPeter
Copy link

This has already been solved in several fork, for example look at mine.

@jbogdani
Copy link
Author

Thank you @BathoryPeter! I guess the main repository is not actively maintained. I'm going to point at yours, thank you.

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

No branches or pull requests

2 participants