PyNGL Home > Functions > Lat/Lon manipulators

Ngl.gc_inout

Determines if a specified point is inside or outside of a spherical polygon.

Available in version 1.4.0 or later.

Prototype

dist = Ngl.gc_inout(lat1, lon1, lat2, lon2)

Arguments

lat1, lon1

Latitude and longitude of first point on the globe.

lat2, lon2

Latitude and longitude of second point on the globe.

Description

This function determines if a specified point is inside or outside of a spherical polygon. A point is considered inside if it is strictly inside or on a boundary arc. Given the discrete nature of floating point arithmetic a point is considered to be on a boundary arc if it is within 1.e-10 degrees of it.

Missing values are not honored as such.

See Also

Ngl.gc_convert, Ngl.gc_dist, Ngl.gc_inout, Ngl.gc_interp, Ngl.gc_qarea, Ngl.gc_tarea

Examples

The following:

import Ngl

#---Point at center of diamond.
inout = Ngl.gc_inout(0.0, -2.0, \
                            [ 0.0,  1.0,  0.0, -1.0,  0.0], \
                            [-3.0, -2.0, -1.0, -2.0, -3.0] )
print(inout)
produces:
[1]

Example 2

The following:

import Ngl

#---Point on a boundary arc.
plat = 20.
plon =  0.
qlat = [0.0, 45.0, 45.0, 0.0]
qlon = [0.0, 45.0,  0.0, 0.0]
inout = Ngl.gc_inout(plat, plon, qlat, qlon)
print(inout)
produces:

[1]
Example 3

The following:

import Ngl

lat = [                                                       \
          [ [  0.0,   0.0,  2.0], [ 0.0,  0.0,  1.0] ],  \
          [ [  0.0,   0.0,  2.0], [ 0.0,  0.0,  1.0] ],  \
          [ [ 89.0,  89.0, 89.0], [ 0.0,  0.0, 80.0] ]   \
       ]
lon = [                                                          \
          [ [ 0.0,    2.0,   1.0], [ -1.0,   1.0, -1.0] ],  \
          [ [ 0.0,    2.0,   1.0], [ -1.0,   1.0, -1.0] ],  \
          [ [ 0.0,  120.0, 240.0], [  0.0,  90.0, 45.0] ]   \
       ]

p0_lat = [ [ 1.0,  0.0],  \
            [ 1.0, -0.1],  \
            [90.0, 45.0]   \
          ]
p0_lon = [ [ 1.0,  0.0],  \
            [ 0.0,  0.0],  \
            [ 0.0, 45.0]   \
          ]

inout = Ngl.gc_inout(p0_lat, p0_lon, lat, lon)
print(inout)
produces:

[[1 1]
 [0 0]
 [1 1]]
Also see example "shapefile3.py" in the PyNGL gallery.