You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the same problem as #94 with other function calls: An Edge is a subclass of a Feature and point_to_line_distance fails to recognize an edge as a Feature...
I think that there is a more general issue with type/subtype checking.
Also, the documentation does not always reflect the code: For exemple, distance is documented as distance(Feature, Feature). But distance(Point, Point) also works and is not documented.
I have the feeling that more generally, type should be enforced at function parameter level: point_to_line_distance(Feature, Feature) is too loose. The coder must check that the Feature geometry has the appropriate type. point_to_line_distance(Point, Line) is more precise and type checking is done by Python at runtime. There is no need to add more checks inside the code of the function.
BTW, point_to_line_distance should return the closest point somehow as well. May be a function nearest_point_on_line(Point, Line) returns the nearest point, and its distance to the line can be determined with distance.
Here is a piece of code that exhibit the issue:
`
from geojson import Point, LineString, Feature
from turfpy.measurement import point_to_line_distance
I also have the issue of classes with the following hierarchy:
A Line is a subclass of a LineString (a Line is a LineString with just 2 points, start and end). I create a Feature from the Line.
nearest_point_on_line(Feature, Feature) fails, telling the Line is not a regognized LineString, although isinstance(aLine, LineString) is True.
@devleaks Thanks again, I think we need to check at the project level and see where ever possible to make types/subtypes specific. It will take some time to fix all the possible functions. Please feel free to open PR. We can do it iteratively each function level.
Hello,
I have the same problem as #94 with other function calls: An Edge is a subclass of a Feature and point_to_line_distance fails to recognize an edge as a Feature...
I think that there is a more general issue with type/subtype checking.
Also, the documentation does not always reflect the code: For exemple, distance is documented as distance(Feature, Feature). But distance(Point, Point) also works and is not documented.
I have the feeling that more generally, type should be enforced at function parameter level:
point_to_line_distance(Feature, Feature)
is too loose. The coder must check that the Feature geometry has the appropriate type.point_to_line_distance(Point, Line)
is more precise and type checking is done by Python at runtime. There is no need to add more checks inside the code of the function.BTW,
point_to_line_distance
should return the closest point somehow as well. May be a functionnearest_point_on_line(Point, Line)
returns the nearest point, and its distance to the line can be determined withdistance
.Here is a piece of code that exhibit the issue:
`
from geojson import Point, LineString, Feature
from turfpy.measurement import point_to_line_distance
class Edge(Feature):
def init(self, node: str, start: Feature, end: Feature):
Feature.init(self, geometry=LineString((start["geometry"]["coordinates"], end["geometry"]["coordinates"])))
self.name = node
p1 = Point((25.25458, 51.623879))
f1 = Feature(geometry=p1)
p2 = Point((25.254626, 51.624053))
f2 = Feature(geometry=p2)
e1 = Edge("e1", start=f1, end=f2)
p0 = Point((25.0, 51.0))
f0 = Feature(geometry=p0)
fline = Feature(geometry=LineString((f1["geometry"]["coordinates"], f2["geometry"]["coordinates"])))
print(point_to_line_distance(f0, fline))
#71.59329853730718
fedge = Edge(node="e1", start=f1, end=f2)
print(isinstance(fedge, Feature))
#True
print(point_to_line_distance(f0, fedge))
Traceback (most recent call last):
File "/Users/pierre/Developer/Internet/js/gip/emitpy/tests/ft3.py", line 28, in
print(point_to_line_distance(f0, fedge))
File "/usr/local/miniconda3/lib/python3.9/site-packages/turfpy/measurement.py", line 1004, in point_to_line_distance
feature_of(line, "LineString", "line")
File "/usr/local/miniconda3/lib/python3.9/site-packages/turfpy/helper.py", line 120, in feature_of
raise Exception(
Exception: Invalid input to line, Feature with geometry required
`
P.
The text was updated successfully, but these errors were encountered: