Last active
December 17, 2015 14:19
-
-
Save mattmakesmaps/5623239 to your computer and use it in GitHub Desktop.
dicking around with sudobangbang. looking at different implementations of sean gillies proposed `__geo_interface__` https://gist.github.com/sgillies/2217756
This file contains hidden or 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
>>> from shapely.geometry import mapping, shape | |
>>> from shapely.geometry import Point | |
# Create a class that has a __geo_interface__ | |
>>> class MattPoint(object): | |
... __geo_interface__ = {'type': 'Point', 'coordinates': (0.0, 0.0)} | |
... | |
>>> myPoint = MattPoint() | |
>>> myPoint.__geo_interface__ | |
{'type': 'Point', 'coordinates': (0.0, 0.0)} | |
>>> shape(myPoint).buffer(5.0).area | |
78.41371226364848 | |
# Create a class w/ the same value assigned to a different variable name | |
>>> class ModPoint(object): | |
... __mod_geo_interface__ = {'type': 'Point', 'coordinates': (0.0, 0.0)} | |
... | |
>>> myModPoint = ModPoint() | |
>>> myModPoint.__mod_geo_interface__ | |
{'type': 'Point', 'coordinates': (0.0, 0.0)} | |
>>> shape(myModPoint).buffer(5.0).area | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/home/rdi/virtualenvs/gpstracker/local/lib/python2.7/site-packages/shapely/geometry/geo.py", line 28, in shape | |
geom_type = ob.get("type").lower() | |
AttributeError: 'ModPoint' object has no attribute 'get' | |
# Multiple Inheritance, get both methods | |
>>> class MergedPoint(MattPoint, ModPoint): | |
... pass | |
>>> myMergedPoint = MergedPoint() | |
>>> shape(myMergedPoint).buffer(5.0).area | |
78.41371226364848 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment