Skip to content
Prev 5596 / 7420 Next

Reading attribute from high resolution raster using low resolution raster as boundary

Hi Andre,

Are the dimensions of the low- and high-res images the same? If so, an easy
approach would be to up-scale the low-res image to be the same size as the
high-resolution image.

You can use EBImage from bioconductor to scale the low-res image with
nearest-neighbor interpolation, and then just grab the data from each
image. See code below.

Note that nearest-neighbor scaling is quite simple, so if the dimensions
were different, or the x- resolution was different than the y-resolution,
you could probably hack together an implementation.

# fake data
low_res = matrix(runif(100), 10, 10)
high_res = matrix(rnorm(10000), 100, 100)

source("http://bioconductor.org/biocLite.R")
biocLite("EBImage")
library(EBImage)

# nearest-neighbor scaling
upscaled_low_res = resize(low_res, w = nrow(high_res), h = ncol(high_res),
filter = "none")

# look same
par(mfrow = c(1,2))
image(low_res)
image(upscaled_low_res)

# naively put it together with loops
# (faster methods avail., but loops are easy to read)
all_dat = data.frame()
for (i in 1:nrow(high_res)){
  for (j in 1:nrow(high_res)){
    all_dat = rbind(all_dat,
                    data.frame(x = i,y = j, forest_cover = high_res[i,j],
abundance = upscaled_low_res[i,j]))
  }
}
On Tue, Apr 4, 2017 at 2:54 PM, Andre Rovai <asrovai at gmail.com> wrote: