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

Ensure associative arrays are properly normalised #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rtrvrtg
Copy link

@rtrvrtg rtrvrtg commented Sep 2, 2016

I'm currently working with geoPHP within Drupal to generate polygons for geographical regions, but for some reason some of the arrays that are coming into WKB.class.php are associative, with their index starting from 1. In these cases, when $components[] = new Point($line_coords[$i],$line_coords[$i+1]); is called, an exception is thrown because $line_coords has no key $i + 1.

I intend to investigate why this function is getting malformed keys, and try and correct it, but decided to put together some sort of interim remedy in case anyone else had the same problem. This PR normalises the input array so that it's no longer associative, ensuring that the keys start from 0 and are properly consecutive. It also ensures that any malformed points are dropped. (Is your policy to drop malformed points, or to try and display them by any means necessary?)

Am also wondering if maybe we could use array_chunk to chunk the array into 2-tuples, and then clean up any malformed ones at the end. Actually, I've gone ahead and done that. Requires PHP 5.3+, but the functionality in question is much more apparent now.

@BathoryPeter
Copy link

geoPHP' current WKB implementation is buggy and fails for many input. I have a (huge) pull request #125 that hopefully fix them. Can you please try it?

OGC specification doesn't mention malformed geometries, simply considers all features is valid geometry. (http://www.opengeospatial.org/standards/sfa)

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

Successfully merging this pull request may close these issues.

2 participants