miscLattice: Lines, points and polygons

latticeR Documentation

Lines, points and polygons

Description

Represent lines, points and polygons

Usage

## S3 method for class 'SpatVector'
llines(x, ...)
## S3 method for class 'SpatVector'
lpoints(x, ...)
## S3 method for class 'SpatVector'
lpolygon(x, rule = "evenodd", ...)

Arguments

x

a SpatVector object

rule

character string specifying how ‘NA’ values are interpreted for polygons. The default rule (‘"evenodd"’) interprets ‘NA’-separated segments as subpaths, possibly representing holes, of a single path, and are rendered using grid.path. Note that this default value is different from the default value defined in lpolygon.default.

...

Any argument that can be passed to llines, lpoints, or lpolygon

Author(s)

Alexandre Courtiol and Oscar Perpiñán

Examples

library(lattice)
library(latticeExtra)
library(terra)
library(rasterVis)

f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)

r <- rast(v)
values(r) <- 1:ncell(r)

pts <- terra::as.points(v)
levelplot(r, margin = FALSE) +
    layer(lpoints(pts, col = "white"))

lns <- terra::as.lines(v)
levelplot(r, margin = FALSE) +
    layer(llines(lns, col = "white", lty = 3))

pols <- terra::as.polygons(v)
levelplot(r, margin = FALSE) +
    layer(lpolygon(pols, border = "black", col = "white"))

## Example adapted from the help page of terra::vect

x <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
hole <- rbind(c(50,0), c(105,30), c(120,2), c(105,-30))
     
z <- rbind(cbind(object=1, part=1, x, hole=0), 
           cbind(object=1, part=1, hole, hole=1))
colnames(z)[3:4] <- c('x', 'y')

p <- vect(z, "polygons", atts=data.frame(id=1))
crs(p) <- "+proj=longlat"

r <- rast(p)
values(r) <- runif(ncell(r))
     
levelplot(r, margin = FALSE) + 
    layer(lpolygon(p, border = "black", col = "white"))

oscarperpinan/rastervis documentation built on March 28, 2024, 11:27 p.m.