Open Nowosad opened 3 days ago
Indeed, NAs were not being handled properly for raster inputs. This is because fuzzyOverlay
was converting all inputs with as.data.frame
(to accommodate also matrices, tibbles, sf
objects, etc.), but for SpatRaster as.data.frame
(by default) removes the NAs. So, the result had fewer values than input pixels (hence that warning message), and the output pixel values were all messed up.
This is fixed now in the development version on R-Forge. You can run install.packages("fuzzySim", repos="http://R-Forge.R-project.org")
and try again.
Many thanks for reporting!
# pak::pak("ambarbosa/fuzzySim")
library(fuzzySim)
library(terra)
#> terra 1.7.83
clc2000_tartu = rast("https://github.com/Nowosad/comparing-spatial-patterns-2024/raw/refs/heads/main/data/clc2000_tartu.tif")
clc2018_tartu = rast("https://github.com/Nowosad/comparing-spatial-patterns-2024/raw/refs/heads/main/data/clc2018_tartu.tif")
clc2000_tartub = ifel(clc2000_tartu == 3, 1, 0)
clc2018_tartub = ifel(clc2018_tartu == 3, 1, 0)
plot(clc2000_tartub, main = "Tartu (2000)")
plot(clc2018_tartub, main = "Tartu (2018)")
fo = fuzzyOverlay(c(clc2000_tartub, clc2018_tartub))
plot(fo)
plot(rast(matrix(fo, ncol = 400)))
Hi @AMBarbosa -- thanks for working on this. I rerun the code with the new package version and now:
Hi @AMBarbosa -- thanks for adding the raster support for the package. I've tried it today, and all is looking good, except
fuzzyOverlay()
which gives a warning and returns a strange-looking raster: