[R-sig-Geo] Aggregation to

Loïc Dutrieux loic.dutrieux at conabio.gob.mx
Thu Aug 31 21:57:42 CEST 2017



On 31/08/17 14:22, Miluji Sb wrote:
> I have a set of coordinates:
> 
> temp <- dput(head(gcp,10))
> structure(list(lon = c(-180, -180, -179, -179, -178, -178, -177,
> -176, -176, -175), lat = c(67, 68, 67, 68, 67, 68, 67, 66, 67,
> 66)), datalabel = "", time.stamp = "11 Aug 2017 16:10", .Names = c("lon",
> "lat"), formats = c("%9.0g", "%9.0g"), types = c(255L, 255L), val.labels =
> c("",
> ""), var.labels = c("lon", "lat"), version = 12L, row.names = c("1",
> "2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
> 
> These are at 1 degree, I would like to aggregate them to 2.5 degree to use
> them to extract data from a netcdf file (which is at 2.5 degree). This is
> what I have done:
> 
> rasterDF <- rasterFromXYZ(gcp)
> gcp2_5 <- aggregate(rasterDF,fact=2.5, fun=sum)

The aggregation factor in raster::aggregate has to be an integer (2, 3, 
etc). Perhaps raster::resample is what you're looking for then. When 
using 'bilinear', resample actually aggregates to the nearest multiple 
of the original raster's resolution (2 degrees in your case), and 
finishes with some interpolation.

Cheers,
Loïc

> 
> However, this seems to return aggregated coordinates at 2 degree.
> 
> class       : RasterLayer
> dimensions  : 67, 180, 12060  (nrow, ncol, ncell)
> resolution  : 2, 2  (x, y)
> extent      : -180.5, 179.5, -54.5, 79.5  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> 
> What am I doing wrong? Is there another way? Thank you.
> 
> Sincerely,
> 
> Milu
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> Email secured by Check Point
>



More information about the R-sig-Geo mailing list