4

I have a raster file (10*10). It has 3 columns and 4 rows. I have a column Count that gives me number of cells in each row class (0,1,2,3). I want to get area of this raster in R. I ma thinking of adding the cell counts and then multiply by 100 to get area in square meters. I tried using area(rastername) but got an error saying Warning message: In .local(x, ...) : This function is only useful for Raster* objects with a longitude/latitude coordinates.

Can anyone help me with this ?

1
  • 2
    area() works fine for non-longlat grids - it's just a warning - but you need to now worry whether your constant pixel width/height area matches the reality of your projection. It probably is fine given how tiny it is . . . What is the projection() and extent() of the grid? If the projection is equal area, or covers relatively small region all is well, but you will find a discrepancy for large areas if the projection is conformal or equi-distant rather than equal-area.
    – mdsumner
    Oct 15, 2016 at 6:37

1 Answer 1

4

area function of raster will work if your raster is in latitude and longitude coordinate system. You can try this library(raster) r = raster("path to file") area = nrow(r) * ncol(r) * xres(r) * yres(r)

2
  • My raster is in UTM. Can't we specify R to add counts in one of the columns and so the math?
    – user65127
    Oct 17, 2016 at 15:48
  • I am not getting your question. What count you want to keep in column ? Also area() function will work in UTM projections also, area function will return raster of same size as input raster with each pixel stores the area of that pixel in square km.
    – S. Thiyaku
    Oct 19, 2016 at 14:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.