# \donttest{
library(sf)
library(dplyr)
# These are SYNTHETIC agricultural FSS data
data(ifs_dk) # Census data
# Create spatial data
ifg = fssgeo(ifs_dk, locAdj = "LL")
ress = c(1,5,10,20,40, 80, 160)*1000
# Create regular grid of the variables, for three regions
ifl = gridData(ifg[ifg$REGIONS %in% c("DK03", "DK04", "DK05"),], vars = c("UAA"), res = ress)
ifl3 = gridData(ifg[ifg$REGIONS == "DK03",], vars = c("UAA"), res = ress)
ifl4 = gridData(ifg[ifg$REGIONS == "DK04",], vars = c("UAA"), res = ress)
ifl5 = gridData(ifg[ifg$REGIONS == "DK05",], vars = c("UAA"), res = ress)
# Create the different multi-resolution grids for different nuts regions
himg3 = multiResGrid(ifl3, vars = "UAA", ifg = ifg[ifg$REGIONS == "DK03",], suppresslim = 0.02)
himg4 = multiResGrid(ifl4, vars = "UAA", ifg = ifg[ifg$REGIONS == "DK04",], suppresslim = 0.02)
himg5 = multiResGrid(ifl5, vars = "UAA", ifg = ifg[ifg$REGIONS == "DK05",], suppresslim = 0.02)
# Bind them together and create new consecutive IDs for the grid cells
himg = rbind(himg3, himg4, himg5)
himg$ID = 1:dim(himg)[1]
# Find the overlapping grid cells, and show some examples.
himgd = MRGoverlap(himg, action = "none")
dim(himgd)
himgd[himgd$ID.y %in% 932:940,]
# Remove overlapping grid cells
himgnew = MRGoverlap(himg, action = "sum")
# Check that there are no more overlaping grid cells
himgd2 = MRGoverlap(himgnew, action = "none")
himgd2
# Create a new multi-resolution grid which has the correct grid cells
# at the border. In this example, the region of interest is so small that
# it is difficult to reprocess just the border grid cells, so
# we make a new complete grid
himg1 = multiResGrid(ifl, vars = "UAA", ifg = ifg[ifg$REGIONS %in% c("DK03", "DK04", "DK05"),],
suppresslim = 0.02)
himgnew2 = MRGoverlap(himg, himg2 = himg1, action = "replace")
himgd12 = MRGoverlap(himgnew2, action = "none")
himgd12
# }
Run the code above in your browser using DataLab