Rhys,

This returns the approximate area of each cell, which varies with latitude
as you use longitude/latitude data.

a <- area(ra, na.rm=TRUE)

to sum the area by zone (RasterLayer 'world' in your case), you can do

zonalarea <- zonal(a, world)



For a Raster object with a _planar_ (not Longitude/Latitude) coordinate
reference system, the area function is not relevant as each cell has the
same size, and you could do

f <- freq(world)

and, to go from cellcounts to areas:

f[,2] <- f[,2] * prod(res(world))

This is what Tony suggested for a RasterLayer with presences/absence data.
The memory-safe version of his approach is:

icearea <- cellStats( raster.Ice , 'sum', na.rm=TRUE)  * prod(res(
raster.Ice ))



Robert


On Wed, May 16, 2012 at 3:56 PM, Anthony Fischbach <afischbach@usgs.gov>wrote:

> Rhys,
> using the NASA special sensor microwave imagery sea ice data set with its
> constant area pixel
> (PixelArea = 25x25 ## in km) geometry I was able to solve this problem by
> creating a raster with pixel values = 1 for pixels with ice and NA for
> pixels without ice then I summed the values and multiplied by the
> PixelArea.
> sum(values(raster.Ice), na.rm=T)* PixelArea
> hth-
>
> -----
> Tony Fischbach, Wildlife Biologist
> Walrus Research Program
> Alaska Science Center
> U.S. Geological Survey
> 4210 University Drive
> Anchorage, AK 99508-4650
>
> AFischbach@usgs.gov
> http://alaska.usgs.gov/science/biology/walrus
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Calculating-area-of-region-with-a-raster-tp7561970p7562866.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


Hi all,

I've been sat infront of my computer for almost a day, and still can't see
why this wont work. I've made a raster that has split the world into 49
different regions. I'm then going to input the suitability of certain
species to be cultivated within each region.

However, I can't seem to be able to calculate the area of each region, of
just get given back to me the area of the entire world, rather than the
specific region.

#This layer highlights Australia
ra<-(world==2)

#When plotting this it highlights Australia perfectly
plot(ra)


#Trying to calculate area for this region
area(ra,, na.rm=TRUE)

#I receive this response back, no matter which region I put in 'ra'
class       : RasterLayer
dimensions  : 75, 180, 13500  (nrow, ncol, ncell)
resolution  : 2, 2  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0
values      : in memory
min value   : 865.039
max value   : 49560.57
layer name  : layer


I know for someone on here this may seem like a completely ridiculous
question, and may seem so simple, I think my problem is that I've been sat
too long staring at the screen, trying to work it out- unsuccessfully.

Thanks in advance,

Rhys

	[[alternative HTML version deleted]]

