1

I have two raster layer, the first one r is my zonal mask as a raster grid, and I created as:

ext <-extent(Yraster)    
r <- raster(nrows=32,ncols=32,ext)
r[] <-(1:ncell(r))

and project it as the 'Yraster' one

projection(r)<-"+proj=utm +zone=19 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"

  > r
class       : RasterLayer 
dimensions  : 32, 32, 1024  (nrow, ncol, ncell)
resolution  : 428.465, 430.3401  (x, y)
extent      : 346090.2, 359801.1, 8783943, 8797714  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=19 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : 1, 1024  (min, max)

> Yraster
class       : RasterLayer 
dimensions  : 459, 457, 209763  (nrow, ncol, ncell)
resolution  : 30.00192, 30.00192  (x, y)
extent      : 346090.2, 359801.1, 8783943, 8797714  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=19 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : acre_2010_non1 
values      : 1, 1  (min, max)
Raster Attribute Table
     fields : ID Rowid    COUNT
        min :  1     0 13821927
        max :  1     0 13821927

but when I do the zonal statistics, an error pop out:

> list <- zonal(Yraster,r, na.rm=TRUE)
Error in compare(c(x, z)) : ncols different

How can I make the zonal statistics work?

2
  • 6
    I believe that this error is fairly self-explanatory and is just the first error that R came across. The next one will be a mismatch in resolution. For this function to work you will need value and zonal rasters with the same extent, row/col dimensions and resolution. It looks like you are trying to summarize your value raster to 428.465 by 430.3401 meter blocks. You will need to rethink your methodology to create zones that are the desired sized block size with uniform zone values at the same resolution as your value raster. You are also missing the "stat" argument in the zonal function. Commented Oct 4, 2012 at 3:25
  • @JeffreyEvans Thank you. I have added another question on how to create zonal grid here gis.stackexchange.com/questions/34895/create-zonal-grid-in-r
    – Seen
    Commented Oct 4, 2012 at 4:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.