[R-sig-eco] Reading attribute from high resolution raster using low resolution raster as boundary

Jeremy Chacon chaco001 at umn.edu
Tue Apr 4 22:39:13 CEST 2017


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:

> Dear friends,
>
> I have 2 raster files, one with very high resolution (each degree-cell is
> 30x30m) and the other with coarser resolution (0.25 degree-cells).
>
> The high resolution raster has info on forest cover area.  The low
> resolution raster has info on species abundance.  My end goal is to
> determine abundance per area.  That entails determining the forest cover
> area (high res raster) within each one of low res raster degree-cells.
>
> Is it possible to overlay both rasters and retrieve the area atribute from
> high res raster for each one the degree-cells in the low res raster?  I
> guess another way to do it it would be to determine the number of
> degree-cells from the high resolution raster that lie within each one of
> the degree-ceils from the coarser resolution raster?
>
> Any help is much appreciated.  I have been stuck with this for a couple of
> weeks..!!
>
> Thanks!
>
> Andre
>
>
>
>
> *Andre Rovai, Ph.D.*
> Research Associate V
> Department of Oceanography and Coastal Sciences
> Energy, Coast, and Environment Bldg., Room 3201
> Louisiana State University
> Baton Rouge, LA 70803
> Phone: 225 578 6422 <(225)%20578-6422>
> Cell: 225 439 5559 <(225)%20439-5559>
> Email: arovai1 at lsu.edu
>            asrovai at gmail.com
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



-- 

*___________________________________________________________________________Jeremy
M. Chacon, Ph.D.*

*Post-Doctoral Associate, Harcombe Lab*
*University of Minnesota*
*Ecology, Evolution and Behavior*

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list