Funcion 1. 'SpatVector'

#primero se debe descargar la libraria
library(terra)
## terra version 1.0.10
#1. puntos
longitude <- c(-78.9750, -77.4611, -77.3539, -71.6773, -71.3386, -73.3750, -72.0794, -67.4654, -66.8695, -67.4080, -69.8495, -69.9429, -70.7126, -71.0524, -73.0848 )
latitude <- c(1.6271, 5.5567, 8.6488, 12.4457, 11.8639, 9.1760, 7.0755, 6.1585, 1.2356, 2.2327, 1.7139, -4.2175, -3.7956, -2.7418, -2.2894)
lonlat <- cbind(longitude, latitude) #concatenar
LonBG <- c(-78.975, -78.975, -66.8695, -66.8695)
LatBG <- c(12.4457, -4.2175,  -4.2175, 12.4457)
LonLatBG <- cbind(LonBG, LatBG)

#2. crear un objeto de formato SpatVector
pts <- vect(lonlat)
ptsBG <- vect(LonLatBG)
class(pts) #verificar la clase
## [1] "SpatVector"
## attr(,"package")
## [1] "terra"
geom(pts) #obsevar la informacion obtenida
##       geom part        x       y hole
##  [1,]    1    1 -78.9750  1.6271    0
##  [2,]    2    1 -77.4611  5.5567    0
##  [3,]    3    1 -77.3539  8.6488    0
##  [4,]    4    1 -71.6773 12.4457    0
##  [5,]    5    1 -71.3386 11.8639    0
##  [6,]    6    1 -73.3750  9.1760    0
##  [7,]    7    1 -72.0794  7.0755    0
##  [8,]    8    1 -67.4654  6.1585    0
##  [9,]    9    1 -66.8695  1.2356    0
## [10,]   10    1 -67.4080  2.2327    0
## [11,]   11    1 -69.8495  1.7139    0
## [12,]   12    1 -69.9429 -4.2175    0
## [13,]   13    1 -70.7126 -3.7956    0
## [14,]   14    1 -71.0524 -2.7418    0
## [15,]   15    1 -73.0848 -2.2894    0
pts
##  class       : SpatVector 
##  geometry    : points 
##  dimensions  : 15, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. :
#aun le falta estar georeferenciado en un datum geografico por lo cual se usa la funcion 'crd'
crdref <- '+proj=longlat +datum=WGS84'
crdrefBG <- '+proj=longlat +datum=WGS84'
pts <- vect(lonlat, crs=crdref)
ptsBG <- vect(LonLatBG, crs=crdrefBG)
pts
##  class       : SpatVector 
##  geometry    : points 
##  dimensions  : 15, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. : +proj=longlat +datum=WGS84 +no_defs
crs(pts)
## [1] "GEOGCRS[\"unknown\",\n    DATUM[\"World Geodetic System 1984\",\n        ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n            LENGTHUNIT[\"metre\",1]],\n        ID[\"EPSG\",6326]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433],\n        ID[\"EPSG\",8901]],\n    CS[ellipsoidal,2],\n        AXIS[\"longitude\",east,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]],\n        AXIS[\"latitude\",north,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]]]"

PARA AGREGAR VARIABLES AL SPATVECTOR PRIMERO SE DEBE CREAR UN 'DATAFRAME'

# SE generan valores aleatorios de precipitaci昼㸳n con la funcion 'runif'
precipvalue <- runif(nrow(lonlat), min=0, max=100)
df <- data.frame(ID=1:nrow(lonlat), precip=precipvalue)
df

luego se combina el dataframe con el spatvector

ptsdf <- vect(lonlat, data=df)
crs(ptsdf) <- crdref
ptsdf
##  class       : SpatVector 
##  geometry    : points 
##  dimensions  : 15, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. : +proj=longlat +datum=WGS84 +no_defs

LINEAS Y POLIGONOS

a = 'LINEAS'
a
## [1] "LINEAS"
lns <- vect(lonlat, type="lines", crs=crdref)
lns
##  class       : SpatVector 
##  geometry    : lines 
##  dimensions  : 1, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. : +proj=longlat +datum=WGS84 +no_defs
b = 'POLIGONOS'
b
## [1] "POLIGONOS"
pols <- vect(lonlat, type="polygons", crs=crdref)
pols
##  class       : SpatVector 
##  geometry    : polygons 
##  dimensions  : 1, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. : +proj=longlat +datum=WGS84 +no_defs
PolBG <- vect(LonLatBG, type="polygons", crs=crdref)
PolBG
##  class       : SpatVector 
##  geometry    : polygons 
##  dimensions  : 1, 0  (geometries, attributes)
##  extent      : -78.975, -66.8695, -4.2175, 12.4457  (xmin, xmax, ymin, ymax)
##  coord. ref. : +proj=longlat +datum=WGS84 +no_defs
plot(PolBG, las=1, col = 'blue')
plot(pols, las=1, add = T)
plot(pols, border='black', col='green', lwd=3, add=TRUE)