Skip to content

Commit

Permalink
Merge pull request #204 from GEO-BON/BII_fix
Browse files Browse the repository at this point in the history
cropped raster by country for viewer, added link to valid country nam…
  • Loading branch information
JoryGriffith authored Dec 16, 2024
2 parents 79528bf + 4d8deff commit 332f4aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions scripts/BII/BIIZonalStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ for(i in 1:length(collections_items)){
srs.cube = "EPSG:4326", layers=NULL, variable=NULL, spatial.res=0.08,
t0 = NULL, t1 = NULL, temporal.res = "P1D", aggregation = "mean", resampling = "near") # load cube from loacFromStacFun

summary(dat_cube)
dat_cube <- filter_geom(cube=dat_cube, geom=study_area$geometry, srs="EPSG:4326")

raster_layers[[i]] <- dat_cube # add to a list of raster layers
names(raster_layers)[i] <- ci[2]

print(names(raster_layers))
if(input$summary_statistic == "Mean"){
stats_each <- gdalcubes::extract_geom(cube=dat_cube, sf=study_area, FUN=mean, reduce_time=TRUE)
} else if(input$summary_statistic == "Median"){
stats_each <- gdalcubes::extract_geom(cube=dat_cube, sf=study_area, FUN=median, reduce_time=TRUE)
} else {
stats_each <- gdalcubes::extract_geom(cube=dat_cube, sf=study_area, FUN=mode, reduce_time=TRUE)}
print(stats_each)
#stats_each$name <- ci[2]
#stats_each <- as.data.frame(stats_each)

stats_layer <- data.frame(name=ci[2], statistic=stats_each[1,2])
stats_list[[i]] <- stats_layer
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/data/getBoundingBox.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ library("rjson")
library("sf")

input <- fromJSON(file=file.path(outputFolder, "input.json"))


output<- tryCatch({
# define study area
if (is.null(input$studyarea_file)){ # if there is no study area file input
if (is.null(input$state)){ # if there is only a country input (no state)
Expand All @@ -19,7 +20,7 @@ if (is.null(input$studyarea_file)){ # if there is no study area file input
study_area_polygon<- sf::st_read(study_area) # load study area as sf object
print(st_crs(study_area_polygon))
if(nrow(study_area_polygon)==0){
stop("Study area polygon does not exist. Check spelling of country and state names. Check if region contains protected areas")
stop("Study area polygon does not exist. Check spelling of country and state names.")
} # stop if object is empty

# Save study area and protected area data
Expand All @@ -34,8 +35,7 @@ bbox <- st_transform(study_area_polygon, st_crs(4326))
bbox<-unname(st_bbox(study_area_polygon))

output <- list("bbox" = bbox, "study_area_polygon" = study_area_polygon_path)
print(output)

}, error = function(e) { list(error = conditionMessage(e)) })
### return outpu
jsonData <- toJSON(output, indent=2)
write(jsonData, file.path(outputFolder,"output.json"))
6 changes: 3 additions & 3 deletions scripts/data/getBoundingBox.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
script: getBoundingBox.R
name: Get bounding box
description: "Extract items and calculate zonal statistics from various collections on the GEO BON Stac Catalog."
description: "Exrtact the bounding box of a country or region of interest."
author:
- name: Jory Griffith
identifier: https://orcid.org/0000-0001-6020-6690
inputs:
country:
label: Country
description: Country of interest
description: Country of interest. For list of countries look here https://geoio.biodiversite-quebec.ca/docs#/default/validate_country_name_validate_country_name_get.
type: text
example: Colombia
state:
label: State/Province
description: State or province of interest (leave blank if you want the full country)
description: State or province of interest (leave blank if you want the full country). For list of accepted region names look here https://geoio.biodiversite-quebec.ca/docs#/default/validate_state_name_validate_state_name_get.
type: text
example: Putumayo
study_area_file:
Expand Down

0 comments on commit 332f4aa

Please sign in to comment.