forked from developmentseed/geojson-pydantic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor geo_interface to use standard mixin. Fixes developmentseed#96.
- Loading branch information
Showing
3 changed files
with
30 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Mixin for __geo_interface__ on GeoJSON objects.""" | ||
|
||
from typing import Any, Dict, Protocol | ||
|
||
|
||
class DictProtocol(Protocol): | ||
"""Protocol for use as the type of self in the mixin.""" | ||
|
||
def dict(self, *, exclude_unset: bool, **args: Any) -> Dict[str, Any]: | ||
"""Define a dict function so the mixin knows it exists.""" | ||
... | ||
|
||
|
||
class GeoInterfaceMixin: | ||
"""Mixin for __geo_interface__ on GeoJSON objects.""" | ||
|
||
@property | ||
def __geo_interface__(self: DictProtocol) -> Dict[str, Any]: | ||
"""GeoJSON-like protocol for geo-spatial (GIS) vector data. | ||
ref: https://gist.github.com/sgillies/2217756#__geo_interface | ||
""" | ||
return self.dict(exclude_unset=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters