栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Check if geo-point is inside or outside of polygon

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/611985.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号