Librerias
library(readxl) #leer excel
library(tidyverse) #unir str
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.2 v dplyr 1.0.4
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(terra)
## terra version 1.0.10
##
## Attaching package: 'terra'
## The following objects are masked from 'package:dplyr':
##
## collapse, desc, near
## The following object is masked from 'package:purrr':
##
## transpose
## The following objects are masked from 'package:tidyr':
##
## expand, fill, pack, separate
Generar un entorno de trabajo para archivos en carpetas
ruta <- getwd()
ruta
## [1] "C:/Users/LENOVO/Desktop/11/RS/exdata"
doc <- 'pts.xlsx'
Arc <- str_c(ruta,'/',doc)
Arc
## [1] "C:/Users/LENOVO/Desktop/11/RS/exdata/pts.xlsx"
transformacion
tabla <- read_xlsx(Arc)
latitude <- tabla$latitude
longitude <- tabla$longitude
LonLat <- cbind(longitude,latitude)
pts <- vect(LonLat)
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. :
georeferenciar
crsref <- '+proj=longlat +datum=WGS84'
pts <- vect(LonLat, crs=crsref)
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
pol <- vect(LonLat, type="polygons", crs=crsref)
pol
## 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(pol, las=1)
plot(pol, border='black', col='green', lwd=3, add=TRUE)