[R-sig-Geo] Determining the area of grid cells from a raster in R

Robert J. Hijmans r.hijmans at gmail.com
Wed Jun 8 23:00:10 CEST 2016


> library(raster)
> library(spatstat)
( ...)
The following objects are masked from ‘package:raster’:
    area, rotate, shift


So either do not load spatstat or call the raster function explicitly

raster::area(x)

Best, Robert

On Wed, Jun 8, 2016 at 12:49 PM, Alex Fitz <afitz at email.wm.edu> wrote:
> Hi,
>
> I have a raster and I am trying to get the area of each grid cell.  The raster object is a country and I am trying to get the area of my grid cells so I can calculate density.
>
> When I type in the name of my raster this is the output I get:
>
> class       : RasterLayer
> dimensions  : 1155, 1441, 1664355  (nrow, ncol, ncell)
> resolution  : 0.008333333, 0.008333333  (x, y)
> extent      : 2.666667, 14.675, 4.266667, 13.89167  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
> data source : /private/var/folders/jw/ynhy9rqn0b3bhrsdfs3qt_bw0000gn/T/RtmpJd12I7/raster/r_tmp_2016-06-08_142202_13015_34709.grd
> names       : gpw.v4.population.count.adjusted.to.2015.unwpp.country.totals_2015
> values      : 0, 65434.81  (min, max)
>
>
> I have tried using the area() function but get the following Error message:
> Error in as.owin.default(w) : Can't interpret W as a window
>
>
> Any help would be greatly appreciated.
>
> Best,
> Alex Fitz
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list