pythonmapscoordinate

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


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: enter image description here

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

Thanks


Solution

  • 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.