The POLYFILLV function returns a vector containing the subscripts of the array elements contained inside a polygon defined by vectors.

The X and Y parameters are vectors that contain the subscripts of the vertices that define the polygon in the coordinate system of the two-dimensional Sx by Sy array. The Sx and Sy parameters define the number of columns and rows in the array enclosing the polygon. At least three points must be specified, and all points should lie within the limits: 0 ≤ Xi < Sx and 0 ≤ Yi < Sy for all i.

As with the POLYFILL procedure, the polygon is defined by connecting each point with its successor and the last point with the first. This function is useful for defining, analyzing, and displaying regions of interest within a two-dimensional array.


The scan-line coordinate system is used, as defined by Rogers in Procedural Elements for Computer Graphics, McGraw-Hill, 1985, page 71. In this system, the scan lines are considered to pass through the center of each row of pixels. Pixels are activated if the center of the pixel is to the right of the intersection of the scan line and the polygon edge within the interval. This implies that for a given set of vertices, some of the vertices themselves may not be included in the returned result.

For example, imagine a square polygon, extending from pixels 2 to 4 in a 6x6 array:

  subscripts = POLYFILLV( [2,4,4,2,2], [4,4,2,2,4], 6, 6 )
  filled = BYTARR(6, 6)
  filled[subscripts] = 1
  print, filled

IDL prints:

  0   0   0   0   0   0
  0   0   0   0   0   0
  0   0   1   1   0   0
  0   0   1   1   0   0
  0   0   0   0   0   0
  0   0   0   0   0   0

Note that only points 2:3 in each dimension are included in the polygon, where you might have expected pixels 2:4. The result can be verified by checking the area of the polygon. Here, the original area is 4 pixels, and 4 indices are returned in the subscripts from POLYFILLV.


To determine the mean and standard deviation of the elements within a triangular region defined by the vertices at pixel coordinates (100, 100), (200, 300), and (300, 100), inside a 512 x 512 array called DATA, enter the commands:

; Get the subscripts of the elements inside the triangle:
P = DATA[POLYFILLV([100,200,300], [100,300,100], 512, 512)]
; Use the STDEV function to obtain the mean and standard deviation 
; of the selected elements:


Result = POLYFILLV( X, Y, Sx, Sy[, Run_Length] )

Return Value

Returns a vector containing the one-dimensional subscripts of the array elements contained inside a polygon defined by vectors X and Y. These subscripts will be LONG64 values if the dimensions of the input array (Sx * Sy) warrant that size for proper addressing. If no points are contained within the polygon, a -1 is returned, and an informational message is printed.



A vector containing the X subscripts of the vertices that define the polygon.


A vector containing the Y subscripts of the vertices that define the polygon.


The number of columns in the array surrounding the polygon.


The number of rows in the array surrounding the polygon.


Set this optional parameter to a nonzero value to make POLYFILLV return a vector of run lengths, rather than subscripts. For large polygons, a considerable savings in space results. When run-length encoded, each element with an even subscript result contains the length of the run, and the following element contains the starting index of the run.

Version History



See Also


This information is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). However, it may be restricted from transfer to various embargoed countries under U.S. laws and regulations.
© 2016 Harris Geospatial Solutions