[R-sig-Geo] Area-weighted average of ncdf files

Nagle, Nicholas nnagle at utk.edu
Tue Jan 17 13:08:30 CET 2012


Hi Trent -

I've had some success doing raster-to-vector conversions with GRASS and the spgrass6 package.  But without the fractional allocation of cells that you need here.  Quick and dirty, you might increase the resolution of the raster so that the area of cells exactly on the boundary is neglible.

If you don't get any help for native R solutions, write back, and I'll post an example for doing this in GRASS with spgrass6.

Come to think of it... if you increase the resolution of the grid, then turn your raster into centroids with coordinates(), and then do a point-in-polygon operation with overlay(), you can do this in R.  Count the number of pixels from each cell in the polygon, and you'll get the area you need for the areal weighting.

Nicholas



> 
> 
> Message: 5
> Date: Mon, 16 Jan 2012 19:39:23 -0800 (PST)
> From: trent biggs <trentbren at yahoo.com>
> To: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org>
> Subject: [R-sig-Geo] Area-weighted average of ncdf files
> Message-ID:
> 	<1326771563.21241.YahooMailNeo at web65903.mail.ac4.yahoo.com>
> Content-Type: text/plain
> 
> Hello,
> ? I want to calculate the area-weighted average of the grid values in a time-series of netcdf files, summarized over a shapefile with a single polygon.? The polygon overlaps several of the gridcells in the ncdf grid, but only partially overlaps some cells, requiring an area-weighted average.? 1) Do any of the spatial packages in R have an area-weighted mean option for a polygon overlaid on a grid?? 2) Do I need to convert the ncdf files into SpatialPointsDataFrames first?? I know how to open and read the ncdf files (ncdf library), how to read in the shapefile (readShapePoly), but am having trouble easily converting the ncdf files into a format that can be easily overlaid by the shapefile polygon.
> ? Thank you for your help!
> ? Trent Biggs
> ? San Diego State University
> 
> 	[[alternative HTML version deleted]]
> 



More information about the R-sig-Geo mailing list