Skip to content

Commit

Permalink
Changed functions from raster to terra package
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryGriffith committed Jul 17, 2024
1 parent 3b7b0a3 commit f50a2c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/studyarea_to_WKT/studyarea_to_WKT.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}", "\\(\\(\\(", .)} }

Expand Down

0 comments on commit f50a2c2

Please sign in to comment.