panel_contour: Add colored contour to the image panel

panel_contourR Documentation

Add colored contour to the image panel

Description

An instrument to overlay multiple rasters on the same image panel. Contour is derived from one band of raster image. The colors (and respective colorbar in legend) is an alternative to contour labeling.

Usage

panel_contour(obj, type = "", ...)




Arguments

obj

Object of class ursaRaster or NULL. Raster band for contouring. If NULL then contour is not displayed. Default is NULL.

type

Character. Keyword list to descibe characteristics of contour, which is interpreted using regular expressions.
"label" specifies displaying labels on contour lines.
"line" specifies displaying contour lines.
"colo(u)*r" specifies displaying colored contour lines.
"fill" specifies displaying filled contour lines.
Keywords can be combined in a single character, e.g., "fill label" specifies displaying filled contours with labels.

...

Set of arguments, which are recognized via their names (using regular expressions) and classes:

bg

Character. Color name or code for contour border. Used for contrast increasing. Semi-transparency and transparency ("transparent") are allowed. Default is "black".

lwd(\\.fg)*

Positive numeric. Width of contour line. Default is 1.

lwd\\.bg

Poistive numeric. Width of the back of contour line. For bordering shoould exceed foreground width (argument lwd). Default is lwd*1.5.

lty

Numeric of character. Line type for contour. Default is 1.

(lab)*cex

Numeric. Character expansion factor for labels. Default is 0.85.

method

Character. Argument, which is passed to contour. Default is "flattest".

expand

Numeric. Scale factor (>=1) to artificial increasing contour details by means of smoothing of increased image size. Not applicable for images with color tables. Default is NA; smoothing is determined intuitively.

before

Logical. Should image reclassification be done before smoothing? Default is FALSE for categorical images and TRUE for numerical images.

cover

Numeric. Argument, which is passed to regrid to control NA values during smoothing. Default is NA; connected to default value of argument cover in function regrid.

short

Positive integer. Minimal number of points in segments for displaying. Prevents displaying very short segments in the case of high-detailed image. Default is 0: all segments are displayed.

verb(ose)*

Logical. Value TRUE may provide some additional information on console. Default is FALSE.

Other arguments are used in the functuion colorize to produce color tables.

Details

Function contourLines is used for contouring.

The color table of input raster image is kept. The output panel have one element left, because contours are borders between areas of the same color. It is recommended to use only gradient palettes.

The color table is forced not to be ramp (argument ramp=FALSE in the function colorize) to prevent extra density of contour lines.

The color table is forced to be interval (argument interval=1L in the function colorize) to prevent lost of elements in the palette.

Value

Object of class ursaColorTable, which then should be used as an input argument for the colorbar legend (function legend_colorbar). If there is no argument of class ursaRaster then function returns NULL value.

Author(s)

Nikita Platonov platonov@sevin.ru

See Also

contourLines

contour

Examples

session_grid(NULL)
a <- pixelsize()
refval <- seq(450,650,by=25)
val <- refval[seq(refval) %% 2 == 1]
ref <- colorize(a,breakvalue=refval,pal.rich=45,pal.rotate=0)
p1 <- colorize(a,breakvalue=val,pal.rich=135,pal.rotate=0)
p2 <- colorize(a,value=val,pal.rich=-15,pal.rotate=0)
p3 <- colorize(a,value=refval)

if (exam1 <- TRUE) {
   compose_open(legend=list(list(1,"left"),list(1,"right")),scale=2)
   panel_new()
  # ct1 <- panel_raster(ref)
  # ct2 <- panel_contour(p2,"colored line",palname="Greens",lwd=15,lwd.bg=0)
   ct2 <- panel_contour(p2,"colored line",pal.rich=240,pal.rotate=0,lwd.fg=15,lwd.bg=0)
  # panel_contour(ref,lwd=0)
  # mysource("contour.R")
  # mycontour(.panel_contour(a),lwd=0)
   if (exists("ct1"))
      compose_legend(ct1,units="raster")
   if (exists("ct2"))
      compose_legend(ct2,units="contour")
   compose_close(bpp=8)
}

if (exam2 <- TRUE) {
   compose_open(layout=c(2,2),byrow=FALSE
               ,legend=list(list(1,"left"),list("bottom",1)
                           ,list(1,"right"),list("top",2)
                           ,list(2,"right"),list("bottom",2)))
   panel_new()
   panel_raster(ref)
   panel_contour(a)
   panel_new()
   ct0 <- panel_contour(a,"color",value=val,pal.rich=240,pal.rotate=0,lwd=11,lwd.bg=12)
   panel_contour(a)
   panel_annotation(text="no colortable")
   panel_new()
   panel_raster(p1)
   ct1 <- panel_contour(p1,"color",lwd=11,lwd.bg=2)
   panel_contour(a)
   panel_annotation(text="colortable:category")
   panel_new()
   panel_raster(p2)
   ct2 <- panel_contour(p2,"color",lwd=11,lwd.bg=2)
   panel_contour(a)#,cex=0.5)
   panel_annotation(text="colortable:interval")
   compose_legend(ref,units="reference")
   compose_legend(ct0,units="contour")
   compose_legend(p1,units="raster")
   compose_legend(ct1,units="contour")
   compose_legend(p2,units="raster")
   compose_legend(ct2,units="contour")
   compose_close()
}

if (exam3 <- TRUE) {
   s <- 29
   session_grid(NULL)
   a <- as.ursa(volcano)
   if (FALSE) {
      display(a)
      a2 <- regrid(a,mul=s,cascade=TRUE,verbose=TRUE)
      display(a2)
      session_grid(a)
   }
   compose_open() ## device="windows")
   panel_new()
   ct1 <- panel_raster(a,ramp=FALSE,interval=TRUE)
   ct2 <- panel_contour(a,"label")
   rm(ct2)
   panel_decor()
   if (exists("ct2"))
      legend_colorbar(ct2)
   else if (exists("ct1"))
      legend_colorbar(ct1)
   compose_close()
}


ursa documentation built on Dec. 28, 2022, 2:18 a.m.