You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found the following categorical raster to fail when calling as.polygons() on it.
It works for a minimal example so something must be wrong/different with the custom raster in the following reprex?
remotes::install_github("mlr-org"/mlr3spatial")
library(mlr3spatial)
#> Loading required package: mlr3
library(terra)
#> terra version 1.4.11#> #> Attaching package: 'terra'#> The following object is masked from 'package:mlr3':#> #> resample# worksstack_classif<- demo_stack_spatraster(0.1)
as.polygons(stack_classif)
#> class : SpatVector #> geometry : polygons #> dimensions : 9, 1 (geometries, attributes)#> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)#> coord. ref. : lon/lat WGS 84 #> names : x_1#> type : <num>#> values : -3#> -2#> -1# also worksr1<- rast(matrix(rep(c("FALSE", "TRUE"), 3), nrow=2))
value<-data.frame(ID= c(0, 1), y= c("negative", "positive"))
setCats(r1, layer="y", value=value)
as.polygons(r1)
#> class : SpatVector #> geometry : polygons #> dimensions : 2, 1 (geometries, attributes)#> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax)#> coord. ref. : lon/lat WGS 84 (EPSG:4326) #> names : lyr.1#> type : <chr>#> values : negative#> positive# failsvalue<-data.frame(ID= c(0, 1), y= c("negative", "positive"))
setCats(stack_classif, layer="y", value=value)
as.polygons(stack_classif)
#> Error in .local(x, i, j = j, ..., value): i > 0 && i <= ncol(x) is not TRUE
Thanks, I believe this has now been fixed. The error was related to having multiple layers in the SpatRaster, and a categorical layer that is not the first layer. Note that as.polygons will only process the first layer of dissolve=TRUE
I've found the following categorical raster to fail when calling
as.polygons()
on it.It works for a minimal example so something must be wrong/different with the custom raster in the following reprex?
remotes::install_github("mlr-org"/mlr3spatial")
Created on 2021-10-21 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: