terra (version 0.3-7)

vect: Create SpatVector objects

Description

Create a new SpatVector

Usage

# S4 method for data.frame
vect(x, type="points", atts=NULL, crs=NA, ...)

Arguments

x

character (filename), data.frame, matrix, or missing. If x is a filename, all other arguments are ignored

type

character. Geometry type. Must be "points", "lines", or "polygons"

atts

data.frame with the attributes. The number of rows must match the number of geometrical elements

crs

the coordinate reference system (PROJ4 notation)

...

additional matrices and/or lists with matrices

Value

SpatVector object

Examples

Run this code
# NOT RUN {
f <- system.file("exdata/lux.shp", package="terra")
f
v <- vect(f)
v

x1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))
x2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
x3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45))
hole <- rbind(c(80,0), c(105,13), c(120,2), c(105,-13))

z <- rbind(cbind(object=1, part=1, x1, hole=0), cbind(object=2, part=1, x3, hole=0),
			cbind(object=3, part=1, x2, hole=0), cbind(object=3, part=1, hole, hole=1))
colnames(z)[3:4] <- c('x', 'y')
z <- data.frame(z)

p <- vect(z, "polygons")
p

z[z$hole==1, "object"] <- 4
lns <- vect(z[,1:4], "lines")
plot(p)
lines(lns, col='red')

# }

Run the code above in your browser using DataLab