Skip to main content
  • Home
  • Documentation
  • FAQ
  • Downloads
  • Support
  • Current Release Notes
  • Ferret Users Guide
    • Users Guide Index
    • Commands Reference
    • 1. Introduction
    • 2. Data Set Basics
    • 3. Variables & Expressions
    • 4. Grids & Regions
    • 5. Animations & Gif Images
    • 6. Customizing Plots
    • 7. Handling String Data Symbols
    • 8. Working with Special Data Sets
    • 9. Computing Environment
    • 10. Converting to NetCDF
    • 11. Writing External Functions
    • Glossary
    • Appendix A: Functions
    • Appendix B: PPLUS Guide
    • Appendix C: Ferret-Specific PPLUS Enhancements
  • Previous Release Notes
  • Tutorials and Demos
    • Ferret Tour
    • DSG files: Discrete Sampling Geometries Demo
    • Ferret sorting demo
    • Fast Fourier Transforms demo
    • Empirical Orthogonal Functions demo
    • Ferret objective analysis demo
    • Ferret Palette Demo
    • Map projections
    • Ferret polygon vector demo
    • Ferret Graticules demo
    • Ferret Polytube Demo
    • Ferret Polymark Demo
    • Ferret Constant-Array demo
    • Ferret land_detail demo
    • COADS Tour
    • Levitus Tour
    • Use OPeNDAP
    • Ferret binary read demo
  • PyFerret
    • PyFerret Downloads and Install ../../faq/ferret-faqs.html
    • What is PyFerret?
    • Why use PyFerret?
    • PyFerret for the Ferret user
    • PyFerret command syntax: quick-start notes
    • PyFerret for the Python user
    • Graphics in PyFerret ?
    • New Ferret functionality
    • PyFerret Python functions and constants
    • PyFerret Python objects and methods
    • Ferret external functions in Python
    • Ferret Fortran external functions
    • PyFerret metadata-and-data dictionaries
  • OPeNDAP
    • OPeNDAP usage in Ferret
    • Use OPeNDAP Demo
    • Test OPeNDAP

PT_IN_POLY

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 of Rensselaer Polytechnic Institute, and found in his web pages at
https://wrfranklin.org/nikola/pages/software/#pnpoly

 

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