Determine if Shapely point is within a LineString/MultiLineString

前端 未结 1 1103
野趣味
野趣味 2020-12-10 17:03

I am trying to use Shapely\'s within function to do a \'spatial join\' of a LineString and a Point file (FYI, the point file was generated using the inter

相关标签:
1条回答
  • 2020-12-10 17:18

    There are floating point precision errors when finding a point on a line. Use the distance with an appropriate threshold instead.

    from shapely.geometry import Point, LineString
    
    line = LineString([(-9765787.9981184918, 5488940.9749489054), (-9748582.8016368076, 5488402.1275707092)])
    point = Point(-9763788.9782693591, 5488878.3678984242)
    
    line.within(point)  # False
    line.distance(point)  # 7.765244949417793e-11
    line.distance(point) < 1e-8  # True
    
    0 讨论(0)
提交回复
热议问题