Check if a coordinate point are lies in certain box area python [duplicate]

微笑、不失礼 提交于 2019-12-12 05:28:37

问题


I have a coordinate point of a place, for example:

point_coord = [-7.7938593,110.3634829]

I also have a viewport of an area contain two point of corrdinates, for example:

northeast = [5.9052479,141.0194444]
southwest = [-11.005261,95.01106190000002]

If I illustrate these point, it will be look like this:

The question is, how do I check if the point_coord is fall or lies in somewhere in that box area using Python?

Thanks


回答1:


Sorry, not too much experience with maps and viewports, but shouldn't it simply be:

def isInside(point_coord, northeast, southwest):
    return southwest[0]<point_coord[0]<northeast[0] and\
           southwest[1]<point_coord[1]<northeast[1]

The only possible edge cases I can think of would be north and south poles. You could probably just code special cases to handle them.

Edit: some typos and not chaining comparisons.



来源:https://stackoverflow.com/questions/45180019/check-if-a-coordinate-point-are-lies-in-certain-box-area-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!