Check if geo-point is inside or outside of polygon

Check if geo-point is inside or outside of polygon,第1张

Check if geo-point is inside or outside of polygon

Here is a possible solution to my problem.

  1. Geographical coordinates must be stored properly. Example
    np.array([[Lon_A, Lat_A], [Lon_B, Lat_B], [Lon_C, Lat_C]])
  2. Create the polygon
  3. Create the point to be tested
  4. Use
    polygon.contains(point)
    to test if point is inside (
    True
    ) or outside (
    False
    ) the polygon.

Here is the missing part of the pre:

from shapely.geometry import Pointfrom shapely.geometry.polygon import Polygonlons_lats_vect = np.column_stack((lons_vect, lats_vect)) # Reshape coordinatespolygon = Polygon(lons_lats_vect) # create polygonpoint = Point(y,x) # create pointprint(polygon.contains(point)) # check if polygon contains pointprint(point.within(polygon)) # check if a point is in the polygon

Note : the polygon does not take into account great circles, therefore it
is necessary to split the edges into many segments thus increasing the number
of vertices.


Special case: If point lies on borders of Polygon

E.g.

print(Polygon([(0, 0), (1, 0), (1, 1)]).contains(Point(0, 0)))
will
fail

So one can use

print(polygon.touches(point)) # check if point lies on border of polygon


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5618106.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存