Closed carostolle closed 2 years ago
Could you provide a reprex that doesn't use whitebox
? Installing that from CRAN leads to an error,
sh: 1: /home/edzer/R/x86_64-pc-linux-gnu-library/4.0/whitebox/WBT/whitebox_tools: not found
on my side, suggesting that the CRAN package is not enough.
Hi thanks for the quick reply.
Usually whitebox should work after running whitebox::install_whitebox()
, but I will try to figure out a reprex without whitebox.
Thanks, that works!
Great report - should work now!
Yes, that seems to have done the trick! Thank you!
Hi @carostolle
I have installed elevatr
, sf
and stars
from GitHub, and also whitebox::install_whitebox()
. I get next error when running get_elev_layer
to create variable dem
Accessing raster elevation [=========================] 100%
Mosaicing & Projecting
Clipping DEM to locations
Error: OGRCreateCoordinateTransformation(): transformation not available
In addition: Warning message:
In CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy, :
GDAL Error 6: Cannot find coordinate operations from `EPSG:3035' to `ENGCRS["ETRS89-extended / LAEA Europe",EDATUM["Unknown engineering datum"],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]'
Any suggestions to test your code?
Thanks!
It works in crs epsg 4326!
@alexyshr can you provide a reprex of the thing that does not work?
library(sf)
#> Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library(stars)
#> Loading required package: abind
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(whitebox)
temp_files <- c("elevation", "slope") |>
vapply(
\(f) tempfile(pattern = f, fileext = ".tif"),
FUN.VALUE = character(1L)
)
on.exit(unlink(temp_files), add = TRUE, after = FALSE)
# AOI small
df <- data.frame(
lon = c(11.15525, 11.15622),
lat = c(49.76438, 49.76510)
)
## AOI big
# df = data.frame(
# lon = c(11.1127, 11.20474)
# , lat = c(49.74578, 49.7775)
# )
aoi <- st_as_sf(
df,
coords = c("lon", "lat"),
crs = 4326
) |>
st_bbox() |>
st_as_sfc() |>
st_as_sf()
#without trasformin to 3035 it works
aoi <- st_transform(aoi, crs = 3035)
#the issue is in elevatr::get_elev_raster
dem <- get_elev_raster(
aoi,
z = 14,
clip = "locations"
)
#> Mosaicing & Projecting
#> Clipping DEM to locations
#> Warning in CPL_transform(x, crs, aoi, pipeline, reverse, desired_accuracy, :
#> GDAL Error 6: Cannot find coordinate operations from `EPSG:3035' to
#> `ENGCRS["ETRS89-extended / LAEA Europe",EDATUM["Unknown engineering
#> datum"],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]'
#> Error in eval(expr, envir, enclos): OGRCreateCoordinateTransformation(): transformation not available
# #Mosaicing & Projecting
# #Clipping DEM to locations
# #Note: Elevation units are in meters.
# # it returns a raster layer
# dem <- stars::st_as_stars(dem)
# dem <- setNames(dem, nm = "elevation")
# ## slope
# stars::write_stars(dem, dsn = temp_files[["elevation"]])
# # calculate slope stars
# whitebox::wbt_slope(
# temp_files[["elevation"]],
# output = temp_files[["slope"]]
# )
# slope <- stars::read_stars(temp_files[["slope"]])
# dem <- stars::read_stars(temp_files[["elevation"]])
# # dimensions
# all.equal(
# st_dimensions(slope),
# current = st_dimensions(dem)
# )
# stars <- stars::read_stars(temp_files)
# # stack using terra
# library(terra)
# slope_t <- terra::rast(temp_files[["slope"]])
# dem_t <- terra::rast(temp_files[["elevation"]])
# # dimensions
# all.equal(
# dim(slope_t),
# current = dim(dem_t)
# )
# stack <- terra::rast(temp_files)
Created on 2024-04-07 with reprex v2.0.2
That works for me:
Thank you!
I will install all those packages from the source again. Any other advice will be appreciated.
Best!
Hi,
we are trying to load a stars object that has a DEM - retrieved through the elevatr package - as well as some terrain metrics calculated via whitebox as attributes. However, for small areas the combining of the two separate stars objects fails with the error: Error in c.stars(structure(list(elevation2edc4a34fdfd.tif = structure(c(328.039428710938, : don't know how to merge arrays: please specify parameter along The same code for a bigger area runs without problem, see in the example below. When using terra to stack the rasters it works for both AOIs. After downgrading to stars v.0.5-5 the code also works for the smaller AOI.
Thanks for any hints on what the issue could be!
Created on 2022-09-09 with reprex v2.0.2