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

Fix MultiPolygon validation #63

Merged
merged 3 commits into from
Oct 12, 2015

Conversation

noirbizarre
Copy link
Contributor

This pull-request fix the multipolygon validation (and the associated test).
Tha data used for testing were false.

@@ -58,14 +58,19 @@ def is_valid(obj):
'must be equivalent')

if isinstance(obj, geojson.MultiPolygon):
if checkListOfObjects(obj['coordinates'],
lambda x: len(x) >= 4 and x[0] == x[-1]):
if checkListOfObjects(obj['coordinates'], lambda x: is_polygon(x)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you wrap this line? It's one character too long for flake8 :P

https://travis-ci.org/frewsxcv/python-geojson/jobs/84943678

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't this line, but I fixed it in the last commit:
https://travis-ci.org/frewsxcv/python-geojson/jobs/84946771

@frewsxcv frewsxcv closed this Oct 12, 2015
@frewsxcv frewsxcv reopened this Oct 12, 2015
@frewsxcv
Copy link
Collaborator

Reopened to restart travis

return output('the "coordinates" member must be an array'
'of Polygon coordinate arrays')

return output('')


def is_polygon(coords):
lengths = all([len(elem) >= 4 for elem in coords])
isring = all([elem[0] == elem[-1] for elem in coords])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the inner brackets in these so they become generators

    lengths = all(len(elem) >= 4 for elem in coords)
    isring = all(elem[0] == elem[-1] for elem in coords)

@noirbizarre
Copy link
Contributor Author

Done.

BTW, I'm really interested in improving validation with more detailled feedback.
I can submit a pull-request but I just wan't to know what constraint do you have.
I explain myself: in the case of a multipolygon, it's possible to have multiple validation error but the current mecanism only allow one feedback message.
To do so, I need to transform validation['message'] into an array if it's OK.
If not, I will try to agregate messages into a single one

@frewsxcv
Copy link
Collaborator

but I just wan't to know what constraint do you have.

I have no constraints with the validation format. Do whatever you think makes the most sense to you

To do so, I need to transform validation['message'] into an array if it's OK.

Sounds goods to me! I would just rename the key to 'messages' and then just make sure it is always an array. I'll make sure to publish a new major version following that change.

In the meantime, thanks for your contribution!

frewsxcv added a commit that referenced this pull request Oct 12, 2015
@frewsxcv frewsxcv merged commit ecfe78e into jazzband:master Oct 12, 2015
@frewsxcv
Copy link
Collaborator

Also, feel free to add yourself to the credits in the README for your daily dose of egotism

@noirbizarre
Copy link
Contributor Author

Thanks !
I will in the next coming pull-request ;)

@frewsxcv
Copy link
Collaborator

Version 1.3.1 has been released which includes this fix. Thanks again!

https://pypi.python.org/pypi/geojson/1.3.1

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 27, 2015
1.3.1 (2015-10-12)
------------------

- Fix validation bug for MultiPolygons

  - jazzband/geojson#63
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Nov 6, 2015
1.3.1 (2015-10-12)
------------------

- Fix validation bug for MultiPolygons

  - jazzband/geojson#63
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