jazzband / geojson

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

geojson.Poylgon is not producing 100% correct output #29

Closed tleeuwenburg closed 10 years ago

tleeuwenburg commented 10 years ago

I have a list of (lon, lat) values, which I'm loading in via

foo = geojson.Polygon(points)

When I use geojson.dumps, I get something like:

{"type": "Polygon", "coordinates": [[152.59136962890625, -28.313671112060547], [152.63580322265625, -28.355209350585938], [152.82142639160156, -28.509435653686523], [153.00906372070312, -28.665510177612305], [153.18821716308594, -28.82417106628418], [152.59136962890625, -28.313671112060547]]}

I have removed a bunch of intermediate points from this snippet.

I then used http://geojsonlint.com/ to validate the output. I got

"Failed to validate field 'coordinates' list schema: Length of value [152.59136962890625, -28.313671112060547] for list item must be greater than or equal to 4"

The issue appears to be some missing square brackets. If I put the coordinate list inside another list, i.e. open with [[[ and close with ]]], then it seems to work fine.

It seems like this might be an error with geojson rather than something I'm doing wrong. I then tried calling geojson with the same trick, wrapping my list of points inside another list. This seemed to work pretty well. So I've got a workaround, but it seems like maybe geojson should or could notice the issue and report the exception.

frewsxcv commented 10 years ago

Is this a duplicate of #22 ?

tleeuwenburg commented 10 years ago

It looks very much like the same issue, yes. It's not hard to work around once you've figured it out, but it would be nicer to give the user an exception so that they have that little bit less work to do when understanding problems.

On Thu, Mar 27, 2014 at 10:00 AM, Corey Farwell notifications@github.comwrote:

Is this a duplicate of #22https://github.com/frewsxcv/python-geojson/issues/22?

Reply to this email directly or view it on GitHubhttps://github.com/frewsxcv/python-geojson/issues/29#issuecomment-38751291 .


Tennessee Leeuwenburg http://myownhat.blogspot.com/ "Don't believe everything you think"

frewsxcv commented 10 years ago

Agreed, I just haven't gotten around to doing it yet. Feel free to submit a PR if you already have a solution. Closing this