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

Point with 3 coordinates or more does not pass validation while valid as per the GeoJSON specs #79

Closed
lafrech opened this issue Jul 15, 2016 · 8 comments
Labels

Comments

@lafrech
Copy link
Contributor

lafrech commented Jul 15, 2016

Please excuse me if I'm mistaken, but as I was reading the GeoJSON specs, I came accross a paragraph mentioning positions with more than two elements:

A position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.

In python-geojson's validator, this is explicitly forbidden:

code:

    if isinstance(obj, geojson.Point):
        if len(obj['coordinates']) != 2:
            return output('the "coordinates" member must be a single position')

tests:

    def test_invalid_point(self):
        point = geojson.Point((10, 20, 30))
        self.assertEqual(is_valid(point)['valid'], NO)

If my understanding is correct, the validator should allow any number of elements greater than of equal to two.

The same change was made in MongoDB:

@frewsxcv
Copy link
Collaborator

If my understanding is correct, the validator should allow any number of elements greater than of equal to two.

You are correct. The validation logic should allow for >= 2 elements for each position.

@lafrech
Copy link
Contributor Author

lafrech commented Jul 20, 2016

Maybe a _dimension attribute could be added to GeoJSON. It would be set in __init__(), defaulting to None.

The validation logic would check that a position is made of >=2 elements if _dimension is None, or that it is made of exactly _dimension otherwise.

This way, the user could validate that the object has the required dimension.

Adding this feature would allow compliance with the spec while allowing people actually relying on the validation to adapt with a few changes (basically, just passing _dimension=2 at object instantiation).

@frewsxcv
Copy link
Collaborator

I'd like to keep this library as close to the spec as possible, and since the spec doesn't mention 'dimension' anywhere relevant, I'm hesitant to include such a feature.

@lafrech
Copy link
Contributor Author

lafrech commented Jul 21, 2016

I understand.

This is something a user can add by subclassing GeoJSON, anyway. People relying on current validation will probably have to do something like this.

@frewsxcv frewsxcv added the bug label Aug 2, 2016
@gfhuertac
Copy link

Just to comment
It should not be >= 2 but 2 or 3 according to the latest RFC (7946).
https://tools.ietf.org/html/rfc7946#section-3.1.1

Implementations SHOULD NOT extend positions beyond three elements
because the semantics of extra elements are unspecified and
ambiguous.

@udos
Copy link
Contributor

udos commented Dec 28, 2016

@frewsxcv , was really glad to find this library some time ago but now I miss the 3rd element badly.
I'm using it to generate LineStrings for gps trails in which the 3rd element would be the elevation... without the 3rd element it is impossible to use the lib in this context.

please reconsider extending it because it would then be covering also this part of the GeoJSON specs.
p.s.: thumbs up for a really helpful lib!

@frewsxcv
Copy link
Collaborator

I don't have much time to look into this right now, but if someone wants to open a PR for this, I'll gladly review it.

On a similar note, if anyone wants commit access to this repository if they want to maintain, please let me know and I'll happily add you. Alternatively, I could also create a python-geojson GitHub organization, transfer the repository, and add people there if people prefer that.

udos added a commit to udos/python-geojson that referenced this issue Apr 24, 2017
frewsxcv added a commit that referenced this issue Apr 25, 2017
@frewsxcv
Copy link
Collaborator

Fixed in #92

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

4 participants