9/20/2023 0 Comments Aggregate raster in rI would make the argument that, from a smoothing perspective, one could achieve good results by skipping Gaussian decomposition and just apply a smoothing spline or local polynomial regression. I would recommend using the focal raster function with a custom / user defined function for summing up population values as you wish. 1 I would do this at the source resolution via a focal function and then aggregate using the mean (it will already be normal). While in fact it should be something like:ġ0 + 15/2 + 12/2 + 18/4 = 28 (if we assume an equal population distribution over each pixel.) Then aggregating by sum to 1.5m we get for the first pixel: I.e.: Let's say we have four cells and these values with a resolution of 1 m: 10 15Īfter resampling to 0.5 using NN: 10 10 15 15 Note however that sum in this case won't return the sum of people who are living in a certain aggregated area. #then use an integer as a factor (in this case 3)ĪggRas <- aggregate(detailedRas, fact=3, fun=sum) 5)ĭetailedRas <- projectRaster(r, to = template, method = "ngb") Template <- raster(extent(r), crs = crs(r), resolution =. Here a workaround: #first resample to higher resolution My preferred method would be to create a SpatialPolygonsDataFrame and rasterize with fun = mean, but (in my experience) extracting raster values using polygons is very inefficient. However, if the points are created at the centroids of the raster cells, I'm not sure how they are handled when extracting with a resolution of 1.5x the original raster. Rasterize(pts2, template, field = "vals", fun = sum) Pts2 <- SpatialPointsDataFrame(pts, ame(vals)) So far, the only method I've been able to come up with is to coerce the template to a SpatialPoints object extract values from the original, higher-resolution raster and rasterize() the result: pts <- as(template, "SpatialPoints") ProjectRaster(r, to = template, method = "bilinear") ProjectRaster(r, to = template, method = "ngb") # Correct resolution, but incorrect / impossible values for population Template <- raster(extent(r), crs = crs(r), resolution = 1.5) R <- raster(resolution = 1, nrow = 100, crs = proj) Proj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" Is there a way to aggregate a raster by a non-integer factor AND specify the function to use when aggregating? library(raster) projectRaster() and resample() allow me to adjust the resolution precisely, but (as far as I know) I am restricted to the prepackaged bilinear-interpolation and nearest-neighbor computation methods. While aggregate() allows me to sum values when aggregating, its factor parameter accepts only integer values. I would like to aggregate a population raster by a factor of 1.5, summing the values of the cells.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |