I'm trying to convert a RasterBrick to polygon, across four different resolutions. It works for the coarsest three resolutions, but for the finest resolution, I get an error that I can't find much information on.

Here's the RasterBrick Info:

    > rass_agg
class       : RasterBrick 
dimensions  : 1883, 2926, 5509658, 14  (nrow, ncol, ncell, nlayers)
resolution  : 13710, 12210  (x, y)
extent      : -20051271, 20064189, -2722745, 20268685  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs 
names       : Wood_Thru//is_Bare_06, Wood_Thru//rubland_06, Wood_Thru//ropland_06, Wood_Thru//oadleaf_06, Wood_Thru//dleleaf_06, Wood_Thru//oadleaf_06, Wood_Thru//dleleaf_06, Wood_Thru//assland_06, Wood_Thru//_Forest_06, Wood_Thru//rubland_06, Wood_Thru//n_Built_06, Wood_Thru//s_Water_06, Wood_Thru//assland_06, Wood_Thru//oodland_06 
min values  :           -0.06590122,           -0.03429975,           -0.13205945,           -0.03906334,           -0.03001432,           -0.28689602,           -0.03063185,           -0.28541537,           -0.11917765,           -0.01400324,           -0.06292345,           -0.15828412,           -0.02550580,           -0.09214195 
max values  :          5.590892e-03,          9.034161e-02,          5.403338e-02,          9.276621e-01,          2.288492e-03,         -1.000000e-04,          4.427548e-03,          1.393522e-03,          1.852588e-01,          2.967395e-03,          5.623372e-02,          9.160649e-03,         -1.000000e-04,         -9.698019e-05 

Then when I call rasterToPolygons(), I get an error.

rass_poly <- rasterToPolygons(rass_agg, n=4, na.rm=T)

The error:

Error in rbind(xyv, xyvr) : number of columns of matrices must match (see arg 2)

Is this a bug?

  • A brick or stack object represents multiple rasters. You need to specify a single raster to convert to a polygon feature class. In your call to the brick object you can use a double bracket to call a given raster ie., rass_agg[[1]] – Jeffrey Evans Jan 30 '17 at 19:52
  • Most of the time, it works for the entire brick. I am exploring a route using rass_agg[[1]], but it's not required. – the_skua Jan 31 '17 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.