Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
5  
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. –  Jeffrey Evans Oct 4 '12 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 Oct 4 '12 at 4:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.