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

Refactor geo_interface to use a standardized mixin. #105

Merged

Conversation

eseglem
Copy link
Collaborator

@eseglem eseglem commented Feb 10, 2023

What I am changing

  • Refactored the code to use a single function for all __geo_interface__ methods. Because the models represent geojson already returning themselves as a dict is all that is necessary. This implementation aligns with what other libraries are doing as well as the discussion in __geo_interface__ specification and implementation #96. The original gist pre-dates the current geojson spec and has some slight inconsistencies, but the intent is to match geojson.

How I did it

  • Added a standard mixin for __geo_interface__ to use on the models.
  • Use self.dict() for the response.

How you can test it

  • No tests were changed and they all still pass.
  • The primary test for this is probably a bit implicit inside the WKT tests. Since shapely reads the __geo_interface__ and then produces the same WKT as our WKT functions we know it is producing usable data in __geo_interface__

Related Issues

I prefer consolidating code where I can, so I did it as a mixin. If it is preferable, we could just have the function on each of the models directly rather than a mixin. Since mixins do add to complexity of understanding. I was using this as a way to learn the right way to do a mixin like this in pydantic and keep everything happy. So it has at least served that purpose.


ref: https://gist.github.com/sgillies/2217756#__geo_interface
"""
return self.dict(exclude_unset=True)
Copy link
Member

Choose a reason for hiding this comment

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

👍

@vincentsarago
Copy link
Member

🤯 thanks for a great PR 🙏

@vincentsarago vincentsarago merged commit 45e758f into developmentseed:main Feb 10, 2023
@eseglem eseglem deleted the feature/geo-interface-mixin branch February 10, 2023 14:16
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