Skip to content

Add support for GeometryCollection fields #138

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

Merged
merged 1 commit into from
Jul 17, 2017

Conversation

gregseb
Copy link
Contributor

@gregseb gregseb commented Jul 14, 2017

Fixes #126
We have a project that has a need to support GeometryCollection fields. After poking around I decided to try altering the GeometryField and GeometrySerializerMethodField to use GeoDjango's built-in geojson output instead of creating a GeoJSON object on the fly. It seems to be a small change and fixes the issue in our project without breaking elsewhere.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Hi @GJdan, thank you for contributing!

Could you add a test that will help us ensure future mantainers won't accidentally break the GeometryCollection compatibility?

You can add a (short and concise) test here:
https://github.com/djangonauts/django-rest-framework-gis/blob/master/tests/django_restframework_gis_tests/tests.py

Instructions to run tests are here:
https://github.com/djangonauts/django-rest-framework-gis#using-tox

args = (geojson,)
except ValueError:
pass

Copy link
Member

Choose a reason for hiding this comment

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

could you remove this blank line please?

@@ -67,6 +62,18 @@ class GeoJsonDict(OrderedDict):
Used for serializing GIS values to GeoJSON values
TODO: remove this when support for python 2.6/2.7 will be dropped
"""
def __init__(self, *args, **kwargs):
"""
If a string is passed attempt to pass it through json.loads, because it should be a geojson formatted string.
Copy link
Member

Choose a reason for hiding this comment

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

Could you please break the comment like this?

If a string is passed attempt to pass it through json.loads,
because it should be a geojson formatted string.

@gregseb
Copy link
Contributor Author

gregseb commented Jul 14, 2017

Sure. I have to go to bed now, but I'll push the formatting fixes, and work on a test tomorrow.

@gregseb
Copy link
Contributor Author

gregseb commented Jul 14, 2017

@nemesisdesign I've added a test. First, I apologize, I'm not yet as familiar with the testing system as I would like to be. I ripped off the other geojson format tests above to keep some consistency, and also added assertJSONEqual because that's what made sense to me in this kind of test.

@gregseb gregseb changed the title Fixes #126 Add support for GeometryCollection fields Add support for GeometryCollection fields Jul 15, 2017
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Thank you very much, could you address my last inline comment?

else:
self.assertItemsEqual(json.dumps(response.data), json.dumps(expected))
self.assertContains(response, "Kool geometry collection geojson test")
self.assertJSONEqual(json.dumps(response.data), expected)
Copy link
Member

Choose a reason for hiding this comment

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

isn't this line redundant with lines 635-639? If yes I think you can keep this line and safely remove lines 635-639

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this was a misunderstanding on my part thinking that assertCountEqual and assertItemsEqual wouldn't do a thorough job because of their names, but on more research I see that they work very well. Line 640 is there because it came with the tests I copied and pasted from test_geojson_format. I have no problem removing it as well.

Removed line 641.

@gregseb
Copy link
Contributor Author

gregseb commented Jul 17, 2017

Done. I think. Unless you want me to remove the self.assertContains line?

@nemesifier
Copy link
Member

nemesifier commented Jul 17, 2017

@GJdan no it's fine, I would just like to ask you one last thing: to squash the commits into one and use as commit message the following: Added support for GeometryCollection #126, I could do this myself (squash and merge) but if you do it the history will look cleaner on github.

@gregseb gregseb force-pushed the fix-geometrycollection-geojson branch from d01f755 to 5236d78 Compare July 17, 2017 20:56
@gregseb
Copy link
Contributor Author

gregseb commented Jul 17, 2017

@nemesisdesign Done

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Great, thanks! 👍

@nemesifier nemesifier merged commit 50764ca into openwisp:master Jul 17, 2017
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.

Serialize models.GeometryCollectionField and m2m spatial relations as GeometryCollection
2 participants