PT_IN_POLY(A,XVERT,YVERT) Returns flag: -1 where points of A lie outside, 0 if on an edge, 1 if inside the polygon defined by XVERT, YVERT
Arguments: |
A |
Variable on the XY grid and region to be tested |
XVERT |
X-coordinates of vertices of polygon | |
YVERT |
Y-coordinates of vertices of polygon |
|
Result Axes: |
X |
Inherited from A |
Y |
Inherited from A |
|
Z |
Inherited from A |
|
T |
Inherited from A |
Note: The algorithm will return a value of 1 for points that lie "inside" the polygon even if it is not a closed curve. Carefully check the shape that you define with XVERT,YVERT and the results of the function.
Note: Prior to Ferret v6.94, if the longitudes given in the second argument XVERT lie on a different modulo longitude branch than the longitudes in the grid of the variable A, the function did NOT translate the longitudes in XVERT. So, in the example below, if we had specified "let xp = {-60, -40, -25, -45, -60}", then the function would return no points within the polygon. Check the grid of the variable and use longitudes in its native range. In Ferret v6.94 and later, if the XY grid of argument 1 is a modulo axis, then modulo operations are applied and the function returns correct results.
This function is based on the code by W. Randolph Franklin, found in his web pages at
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
Example:
Define the vertices of a simple polygon shape. Using pt_in_poly, create a mask which for every point of the grid of the 1-degree etopo60 dataset, is 1 inside the polygon and 0 outside it.
! Make a basemap plot of the region go basemap x=280:360 y=0:60 20 ! Define the polygon and plot it on the map let xp = {300,320,335,315,300} let yp = {20,35,40,20,20} plot/vs/thick/line/color=blue/over/nolab xp,yp ! Compute the mask use etopo60 let mask = if pt_in_poly(rose,xp, yp) gt 0 then 1 ! Plot masked data shade/over/key rose*mask