## ---- echo=FALSE, include=FALSE----------------------------------------------- library(knitr) opts_chunk$set(fig.width = 5, fig.height = 5, fig.cap = '', collapse = TRUE) ## ----------------------------------------------------------------------------- longitude <- c(-116.7, -120.4, -116.7, -113.5, -115.5, -120.8, -119.5, -113.7, -113.7, -110.7) latitude <- c(45.3, 42.6, 38.9, 42.1, 35.7, 38.9, 36.2, 39, 41.6, 36.9) lonlat <- cbind(longitude, latitude) ## ----------------------------------------------------------------------------- library(terra) pts <- vect(lonlat) ## ----------------------------------------------------------------------------- class (pts) ## ----------------------------------------------------------------------------- pts geom(pts) ## ----------------------------------------------------------------------------- crdref <- "+proj=longlat +datum=WGS84" pts <- vect(lonlat, crs=crdref) pts crs(pts) ## ----------------------------------------------------------------------------- # Generate random precipitation values, same quantity as points precipvalue <- runif(nrow(lonlat), min=0, max=100) df <- data.frame(ID=1:nrow(lonlat), precip=precipvalue) ## ----------------------------------------------------------------------------- ptv <- vect(lonlat, atts=df, crs=crdref) ## ----------------------------------------------------------------------------- ptv ## ----------------------------------------------------------------------------- lon <- c(-116.8, -114.2, -112.9, -111.9, -114.2, -115.4, -117.7) lat <- c(41.3, 42.9, 42.4, 39.8, 37.6, 38.3, 37.6) lonlat <- cbind(id=1, part=1, lon, lat) lonlat lns <- vect(lonlat, type="lines", crs=crdref) lns ## ----------------------------------------------------------------------------- pols <- vect(lonlat, type="polygons", crs=crdref) pols ## ---- vectordata-1------------------------------------------------------------ plot(pols, las=1) plot(pols, border='blue', col='yellow', lwd=3, add=TRUE) points(pts, col='red', pch=20, cex=3)