grdclip(cmd0::String="", arg1=nothing; kwargs...)

Clip the range of grid values


Sets values < low to below and/or values > high to above. You can also specify one or more intervals where all values should be set to between, or replace individual values. Such operations are useful when you want all of a continent or an ocean to fall into one color or gray shade in image processing, when clipping of the range of data values is required, or for reclassification of data values. above, below, between, old and new can be any number or even NaN (Not a Number). You must choose at least one of the |-S| options. Use region to only extract a subset of the ingrid file.

Optional Arguments

  • G or save or outgrid or outfile : – outgrid=[=ID][+ddivisor][+ninvalid][+ooffset|a][+sscale|a][:driver[dataType][+coptions]]
    Give the name of the output grid file. Optionally, append =ID for writing a specific file format (See full description). The following modifiers are supported:

    • +d - Divide data values by given divisor [Default is 1].

    • +n - Replace data values matching invalid with a NaN.

    • +o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

    • +s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

    Note1: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

    Note2: This is optional and to be used only when saving the result directly on disk. Otherwise, just use the G = modulename(...) form.

  • R or region or limits : – limits=(xmin, xmax, ymin, ymax) | limits=(BB=(xmin, xmax, ymin, ymax),) | limits=(LLUR=(xmin, xmax, ymin, ymax),units="unit") | ...more
    Specify the region of interest. More at limits. For perspective view view, optionally add zmin,zmax. This option may be used to indicate the range used for the 3-D axes. You may ask for a larger w/e/s/n region to have more room between the image and the axes.

  • Sa or above or high : – above="high/above", | above=(high,above)
    Set all data[i] > high to above.

  • Sb or below or low : – below="low/below", | below=(low,below)
    Set all data[i] < low to below.

  • Si or between : – between="low/high/between" | between=(low,high,between)
    Set all data[i] >= low and <= high to between. Repeat the option for as many intervals as are needed.

  • Sr or old or new : – old="old/new" | old=(old,new)
    Set all data[i] == old to new. This is mostly useful when your data are known to be integer values. Repeat the option for as many replacements as are needed.

  • S : – S="..."
    Any of the above must use the short form S?. The current use of this is when one wants to repeat an S? option, which we cannot do because we can't repeat the *kwargs
    key names. Example usage: G2 = grdclip(G, S="a5/6 -Sb2/2 -Si3/4/3.5")

  • V or verbose : – verbose=true | verbose=level
    Select verbosity level. More at verbose


To set all values > 0 to NaN and all values < 0 to 0 in the remote file

Gnew_AFR = grdclip("", above=(0,NaN), below=(0,0))

To reclassify all values in the 25-30 range to 99, those in 35-39 to 55, exchange 17 for 11 and all values < 10 to 0 in file, try

Gnew_classes = grdclip("", S="i25/30/99, -Si35/39/55", old=(17,11), between=(10,0))

See Also

grdfill, grdlandmask, grdmask, grdmath, grd2xyz, xyz2grd