From f50a2c28fa3202c40438210659d1c2e1e37e11c1 Mon Sep 17 00:00:00 2001 From: JoryGriffith Date: Wed, 17 Jul 2024 11:16:50 -0400 Subject: [PATCH] Changed functions from raster to terra package --- scripts/studyarea_to_WKT/studyarea_to_WKT.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/studyarea_to_WKT/studyarea_to_WKT.R b/scripts/studyarea_to_WKT/studyarea_to_WKT.R index e83fcc8ef..29e316301 100644 --- a/scripts/studyarea_to_WKT/studyarea_to_WKT.R +++ b/scripts/studyarea_to_WKT/studyarea_to_WKT.R @@ -2,7 +2,7 @@ # Install necessary libraries - packages packagesPrev<- installed.packages()[,"Package"] # Check and get a list of installed packages in this machine and R version -packagesNeed<- list("magrittr", "terra", "raster", "sf", "fasterize", "pbapply", "this.path", "rjson") # Define the list of required packages to run the script +packagesNeed<- list("magrittr", "terra", "sf", "fasterize", "pbapply", "this.path", "rjson") # Define the list of required packages to run the script lapply(packagesNeed, function(x) { if ( ! x %in% packagesPrev ) { install.packages(x, force=T)} }) # Check and install required packages that are not previously installed # Load libraries @@ -31,7 +31,7 @@ input <- rjson::fromJSON(file=file.path(outputFolder, "input.json")) # Load inpu output<- tryCatch({ # Load and convert the study area to aggregate polygon limits and project it to the defined EPSG coordinate system -vector_polygon<- terra::vect(input$studyarea_path) %>% terra::aggregate() %>% terra::project( raster::crs( paste0("+init=epsg:", input$studyarea_epsg) ) ) +vector_polygon<- terra::vect(input$studyarea_path) %>% terra::aggregate() %>% terra::project( terra::crs( paste0("epsg:", input$study_area_espg ) ) ) # Generate WKT representation of the strudy area polygon wkt_polygon <- terra::geom(vector_polygon, wkt=TRUE) %>% { paste0( "MULTIPOLYGON (",paste(gsub("POLYGON |MULTIPOLYGON ", "", .), collapse= ", "),")") %>% {gsub("\\({4}", "\\(\\(\\(", .)} }