This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
library(elevatr)
## elevatr v0.99.0 NOTE: Version 0.99.0 of 'elevatr' uses 'sf' and 'terra'. Use
## of the 'sp', 'raster', and underlying 'rgdal' packages by 'elevatr' is being
## deprecated; however, get_elev_raster continues to return a RasterLayer. This
## will be dropped in future versions, so please plan accordingly.
library(sf)
## Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
library(leaflet)
library(terra)
## terra 1.8.70
library(RColorBrewer)
library(tidyterra)
##
## Adjuntando el paquete: 'tidyterra'
## The following object is masked from 'package:stats':
##
## filter
library(ggplot2)
(r <- rast(nrows=40, ncols=20, xmin=0, xmax=10, ymin=0, ymax=10))
## class : SpatRaster
## size : 40, 20, 1 (nrow, ncol, nlyr)
## resolution : 0.5, 0.25 (x, y)
## extent : 0, 10, 0, 10 (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84)
values(r) <- runif(ncell(r))
plot(r)
q <- 100 * r^2
plot(q)
q
## class : SpatRaster
## size : 40, 20, 1 (nrow, ncol, nlyr)
## resolution : 0.5, 0.25 (x, y)
## extent : 0, 10, 0, 10 (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84)
## source(s) : memory
## name : lyr.1
## min value : 1.227151e-06
## max value : 9.963468e+01
m <- q < 10
plot(m)
z <- sin(r)
plot(z)
list.files()
## [1] "3753817.jpg" "4318891.jpg"
## [3] "B24.1202.1" "CF02_CFA"
## [5] "Datos" "desktop.ini"
## [7] "Discord.lnk" "elev_amazonas.tif"
## [9] "Este equipo.lnk" "G2"
## [11] "Gam" "Gam l"
## [13] "Grand Theft Auto V.url" "Herramientas"
## [15] "Rast" "Rastrera-de-la-Amazonas-F.html"
## [17] "Rastrera-de-la-Amazonas-F.Rmd" "Rastrera-de-la-Amazonas-F_files"
## [19] "Rastrera-de-la-Amazonas_files" "Rastrera de la Amazonas - copia.Rmd"
## [21] "Rastrera de la Amazonas F.Rmd" "Rastrera de la Amazonas.Rmd"
## [23] "Rockstar Games Launcher.lnk" "rsconnect"
elevacion <- rast ("Datos/COL_ref/COL_msk_alt.tif")
elevacion
## class : SpatRaster
## size : 2136, 1800, 1 (nrow, ncol, nlyr)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -81.8, -66.8, -4.3, 13.5 (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84
## source : COL_msk_alt.tif
## name : COL_msk_alt
## min value : -28
## max value : 5453
plot(elevacion)
#m <- crop (elevacion, vector, mask=TRUE)
meta <- st_read("Datos/amazonas.gpkg")
## Reading layer `AmanzonasDepto' from data source
## `C:\Users\Alejo\Desktop\Datos\amazonas.gpkg' using driver `GPKG'
## Simple feature collection with 1 feature and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -74.38985 ymin: -4.228429 xmax: -69.36835 ymax: 0.1603
## Geodetic CRS: WGS 84
library(terra)
amazonas1 <- vect("Datos/amazonas.gpkg")
amazonas1
## class : SpatVector
## geometry : polygons
## dimensions : 1, 9 (geometries, attributes)
## extent : -74.38985, -69.36835, -4.228429, 0.1603 (xmin, xmax, ymin, ymax)
## source : amazonas.gpkg (AmanzonasDepto)
## coord. ref. : lon/lat WGS 84 (EPSG:4326)
## names : ID_0 ISO NAME_0 ID_1 NAME_1 TYPE_1 ENGTYPE_1
## type : <num> <chr> <chr> <num> <chr> <chr> <chr>
## values : 53 COL Colombia 1 Amazonas ComisarÃa Commissiary
## NL_NAME_1 VARNAME_1
## <chr> <chr>
## NA NA
elev_amazonas <- crop(elevacion,amazonas1, mask=TRUE)
## Warning: [crop] CRS do not match
crs_amazonas1 <- crs(amazonas1)
crs(elevacion) <- crs_amazonas1
crs(elevacion) == crs(amazonas1)
## [1] TRUE
elev_amazonas <- crop (elevacion,amazonas1, mask=TRUE)
plot(elev_amazonas)
ggplot() +
geom_spatraster(data = elev_amazonas) +
scale_fill_whitebox_c(
palette = "muted",
labels = scales::label_number(suffix = "[m]"),
n.breaks = 12,
guide = guide_legend(reverse = TRUE)
) +
labs(
fill = "",
title = "elevación en Amazonas"
#subtitle = "Months of April, May and June"
)
writeRaster(elev_amazonas, "elev_amazonas.tif", overwrite=TRUE)
(elevacion_amazonas <- rast("elev_amazonas.tif"))
## class : SpatRaster
## size : 526, 603, 1 (nrow, ncol, nlyr)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -74.39167, -69.36667, -4.225, 0.1583333 (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (EPSG:4326)
## source : elev_amazonas.tif
## name : COL_msk_alt
## min value : 53
## max value : 333
plot(elevacion_amazonas)