[R-sig-Geo] Calculate area of raster cells

Robert J. Hijmans r.hijmans at gmail.com
Wed Apr 28 19:02:42 CEST 2010


Tim,

if your SpatialGridDataFrame is called 'spgdf', you can do

library(raster)
r = raster(spgdf)
a = area(r)
plot(a)
spgdf2 = as(a, 'SpatialGridDataFrame')

That gives a reasonable estimate in most cases (it uses the
longitudinal span of the center of each cell).

For more precise computations,  you can coerce the grid (or perhaps
the first cell of each row if the grid is large) to polygons and then
use "areaPolygons" in the development version (on R-Forge) of
"geosphere".
install.packages("geosphere", repos="http://R-Forge.R-project.org")

This function computes the area of spherical polygons.  How you would
implement this could very well depend on the size of your raster

rr = raster(r)
p = rasterToPolygons(rr)   # or an sp coerce method from the spgdf
rr[] = areaPolygon(p)

Here is a short illustration:
r = raster(nrow=30, ncol=4, ymn=-89)  # excluding South Pole; bugs there
p = rasterToPolygons(r)
library(geosphere)
r[] = areaPolygon(p)
plot(r)


Robert

On Wed, Apr 28, 2010 at 3:54 AM, Tim Erbrecht <timerbrecht at web.de> wrote:
> Dear all,
>
>
>
> having data in a SpatialGridDataFrame with geographic coordinates, is there
> a simple method to calculate the spatial area for each cell? I wasn't able
> to find anything in the list archives ...
>
>
>
> Thanks and best regards
>
> Tim
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>



More information about the R-sig-Geo mailing list