Closed jamesgrecian closed 3 months ago
This line expect the custom region to be a sf
object, not just an sfc
, and for that object to use the name geometry
for its geometry column, which is a convention but often a weak point of checking for sf objects
This should fix it I think
CP <- sf::st_bbox(c(xmin = -180, xmax = 180, ymin = -30, ymax = -60), crs = 4326) |>
sf::st_as_sfc() |>
sf::st_as_sf() |>
dplyr::rename(geometry = x)
Although I am running in an API call error, but that is a different story, as I am not authentified with GFW. Adding it just for the record.
Error in `httr2::req_perform()`:
! HTTP 401 Unauthorized.
Run `rlang::last_trace()` to see where the error occurred.
This works with no errors on my machine, sessionInfo (abridged) below
> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sf_1.0-16 gfwr_2.0.0 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[11] ggplot2_3.5.1 tidyverse_2.0.0
Great. The only comment I'd have for the devs is to not expect the region to have a geometry
named column, or to error and let the user know explicitly when this column isn't present. Otherwise this can be closed.
Hi @jamesgrecian, Thank you so much for reaching out. And thanks @VLucet for responding. @VLucet you are right, we will remove the check using the geometry sfc
name and check using only st_geometry()
. Other than that your code chunk works.
We will push the small change to the code so that you don't need to rename the geometry column to "geometry" and let you know.
Good point to use st_geometry()
I did the update, @jamesgrecian so this should work without the renaming line.
CP <- sf::st_bbox(c(xmin = -180, xmax = 180, ymin = -30, ymax = -60), crs = 4326) |>
sf::st_as_sfc() |>
sf::st_as_sf()
Please note that I also renamed the option USER_JSON to USER_SHAPEFILE to be more precise, so in your case this should work:
gfw_dat <- get_raster(spatial_resolution = 'LOW',
temporal_resolution = 'YEARLY',
group_by = 'GEARTYPE',
start_date = '2021-01-01',
end_date = '2022-01-01',
region = CP,
region_source = 'USER_SHAPEFILE',
key = gfw_auth())
I'm closing this issue but feel free to reopen if anything is missing.
Hi
gfwr
team,I'm new to using the
gfwr
package after previously using Juan Mayorga's excellent guide to using google big query.I'm trying to pass a
sf
polygon to theget_raster
function but the object is not being recognised. I can't find guidance on how best to generate this object.Here's a reprex of what I'm trying:
Created on 2024-07-19 with reprex v2.1.1