I am using Python 3.6 with the latest version of shapely from Anaconda.
from shapely.geometry import Point,LineString
g = LineString(coordinates=[(0, 0), (6.656423206909781, 4.437570291332059)])
p =wkt.loads('POINT (4.160264504318614 2.773481432082537)')
g.contains(p)
>>> False
The point p
is clearly within geometry g
, Since:
g.interpolate(5).xy
>>> (array('d', [4.160264504318614]), array('d', [2.773481432082537]))
Why is the above statement evaluating to false when I think it should be true?
Answer
Simply look at the answer of Mike T in Determine if shapely point is within a linestring/multilinestring
There are floating point precision errors when finding a point on a line. Use the distance with an appropriate threshold instead.
g.distance(p) < 1e-8 # True
True
No comments:
Post a Comment