An HTML attachment was scrubbed... URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100428/bd26a984/attachment.html>
Calculate area of raster cells
5 messages · Tim Erbrecht, Paul Hiemstra, Roger Bivand +1 more
Tim Erbrecht 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
with the meuse dataset: library(sp) data(meuse.grid) gridded(meuse.grid) = ~x+y fullgrid(meuse.grid) = TRUE bla = gridparameters(meuse.grid) area = bla$cellsize[1] * bla$cellsize[2] area cheers, Paul
Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
On Wed, 28 Apr 2010, Paul Hiemstra wrote:
Tim Erbrecht 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
with the meuse dataset: library(sp) data(meuse.grid) gridded(meuse.grid) = ~x+y fullgrid(meuse.grid) = TRUE bla = gridparameters(meuse.grid) area = bla$cellsize[1] * bla$cellsize[2] area
These are projected, not geographical coordinates, unfortunately. The case for calculating areas on an ellipsoid is much harder, I'm afraid. Roger
cheers, Paul
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
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
P.S. The solution I just posted assumes the earth is a sphere, not an ellipsoid (which would be more accurate).
These are projected, not geographical coordinates, unfortunately. The case for calculating areas on an ellipsoid is much harder, I'm afraid. Roger
On Wed, Apr 28, 2010 at 4:16 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
On Wed, 28 Apr 2010, Paul Hiemstra wrote:
Tim Erbrecht 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
with the meuse dataset: library(sp) data(meuse.grid) gridded(meuse.grid) = ~x+y fullgrid(meuse.grid) = TRUE bla = gridparameters(meuse.grid) area = bla$cellsize[1] * bla$cellsize[2] area
These are projected, not geographical coordinates, unfortunately. The case for calculating areas on an ellipsoid is much harder, I'm afraid. Roger
cheers, Paul
-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo