Guy Benett
Guy Benett

Reputation: 23

Calculate area in hectares for different land cover classes in a raster in R

How can I get the the total area in hectares of my land cover classes 1,2,3,4,5,6 given the following example:

class      : RasterLayer 
dimensions : 9257, 8348, 77277436  (nrow, ncol, ncell)
resolution : 25, 25  (x, y)
extent     : 146600, 355300, 164575, 396000  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs 
source     : memory
names      : Layer_5 
values     : 0, 6  (min, max)

I have tried:

nrow(change2) * ncol(change2) * xres(change2) * yres(change2)

But this gives me a different area result to when I use:

rgeos::gArea(area2)

on a polygon as the same area as the raster:

class       : SpatialPolygonsDataFrame 
features    : 114 
extent      : 146598, 396590, 164568, 401725.8  (xmin, xmax, ymin, ymax)
crs         : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs 
variables   : 7

Many thanks for any assistance!

Upvotes: 0

Views: 280

Answers (1)

drJones
drJones

Reputation: 1233

You can get the area of each target class using:

##area by class
targ_class = 1:6
area_class = table(change2[which(change2[]%in%targ_class)])*xres(change2)*yres(change2)/10000
area_class

And the total area of the target classes using:

##total area
sum(area_class)

The calculated area may still differ slightly from that calculated using a polygon.

Upvotes: 1

Related Questions