jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
915 stars 121 forks source link

add validation for geojson objects #56

Closed saromanov closed 9 years ago

saromanov commented 9 years ago

Hi! I notice what allows to construct object even if is not valid by specification and i created module for checking validation for objects. Now is something like a "concept"(or very restricted version), because i don't know about needs this for you. No tests and no documentation, but contains two objects LineString and MultiLineString. How it works:

>>> from geojson import LineString, MultiLineString, IsValid
>>> IsValid(LineString([(8.919, 44.4074), (8.923, 44.4075)]))
{'valid': 'yes', 'message': ''}
>>> IsValid(LineString([(8.919, 44.4074)]))
{'valid': 'no', 'message': 'the "coordinates" member must be an array of two or more positions'}
>>> IsValid(MultiLineString([[(10,5), (4,3)]]))
{'message': '', 'valid': 'yes'}
>>> IsValid(MultiLineString([[(10,5)]]))
{'message': 'the "coordinates" member must be an array of LineString coordinate arrays', 'valid': 'no'}

The messages is just a copy-paste from specification What do you think about this?

frewsxcv commented 9 years ago

Awesome! There are a few flake8 issues that travis reported that need to be addressed.

On a side note, what do you think about making this a method on the GeoJSON objects? e.g. my_linestring.is_valid()? It's not necessary, just a thought. I'll merge this in either way

saromanov commented 9 years ago

Ok, great!

from the one side, it would be better. In that case, not need imports, just call geojsonobject.is_valid(). From the other side, it is pretty optional and it make no sense to set it on every object. And if you write, that it looks nice already now so, i think, i will be not change it :) In this case, i'll finish with remaining objects, will provide documentation and fix trobles from flake8 output. Hope, to do it in the next 2 or 3 days.

frewsxcv commented 9 years ago

Great, thank you!

Don't forget to add yourself to the credits :)

saromanov commented 9 years ago

Well, i think, i'm done. What i've made in the result:

saromanov commented 9 years ago

Replaced is not True to is False and renamed IsValid to is_valid. I agree, that this name is better.

frewsxcv commented 9 years ago

Looks great @saromanov , thank you for your contribution! :D

frewsxcv commented 9 years ago

Just released version 1.2.0 that includes this code. Thanks again!

saromanov commented 9 years ago

Ok, great!