1

I want to do weighted area mean of raster cells included in buffered points,spatialpointsdataframe but from what I have noticed the extract function only includes raster cells having their cell centers inside the 7 meter buffer. Raster cell size is 12.5 meter. It would be great if the function could calculate a weighted area mean of all raster cells not just cells having their centers inside the buffer zone. Anyone have an idea how to solve this? Code looking like this:

means <- extract(Raster, SpatialPointsDataframe, method='simple', buffer=7,weights=TRUE, normalizeWeights=T, small=T, fun=mean, df=T) 

As an example this spatial point gets the value of one pixel with weighted mean 21

enter image description here

1 Answer 1

1

I have solved this problem thanks to https://gis.stackexchange.com/users/8520/jeffrey-evans

Using his example

results <- vector() for(j in 1:nrow(x)) { lsub <- x[j, ] cr <- raster::crop(y, raster::extent(lsub), snap = "out") r <- as(cr, "SpatialPolygonsDataFrame") names(r@data) <- "raster.value" r <- intersect(lsub, r) na.idx <- which(is.na(r$raster.value)) if(length(na.idx) > 0) { r <- r[-na.idx,] } if (nrow(r) < 1) { results <- append(results, NA) } else { results <- append(results, weighted.mean(r@data[,"raster.value"], gArea(r, byid=TRUE))) } } results 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.