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

does not work on derived classes? #94

Closed
devleaks opened this issue May 31, 2021 · 1 comment · Fixed by #95
Closed

does not work on derived classes? #94

devleaks opened this issue May 31, 2021 · 1 comment · Fixed by #95

Comments

@devleaks
Copy link

Hello,
I'm no python specialist, just a regular user.
I derived a class from Feature but then, turfpy operations on those derived classes no longer work...

from geojson import Point, Feature
from turfpy.measurement import distance

class Vertex(Feature):
    def __init__(self, node: str, point: Point):
        Feature.__init__(self, geometry=point)
        self.nodeid = node

p1 = Point((25.25458, 51.623879))
f1 = Feature(geometry=p1)
v1 = Vertex("v1", point=p1)
p2 = Point((25.254626, 51.624053))
f2 = Feature(geometry=p2)
v2 = Vertex("v2", point=p2)

df = distance(f1, f2)
print("df: ",df)  # df:  0.019606799666682842

print("v1 is feature?", isinstance(v1, Feature))  # true

dv = distance(v1, v2)
print("dv: ", dv)
# Error:
# Traceback (most recent call last):
#   File "ft.py", line 19, in <module>
#     dv = distance(v1, v2)
#   File "/usr/local/miniconda3/lib/python3.9/site-packages/turfpy/measurement.py", line 112, in distance
#     coordinates1 = get_coord(point1)
#   File "/usr/local/miniconda3/lib/python3.9/site-packages/turfpy/helper.py", line 80, in get_coord
#     raise Exception("coord must be GeoJSON Point or an Array of numbers")
# Exception: coord must be GeoJSON Point or an Array of numbers

I'd rather derive my Vertex class from Feature rather than "compose" by adding a feature attribute to my Vertex class.
Thanks in advance for your help.
P.

@sackh
Copy link
Collaborator

sackh commented May 31, 2021

@devleaks Thanks for reporting this. We will have to fix this. as type checking is not done correctly.

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 a pull request may close this issue.

2 participants