For a project in geoprocessing, I need to extract information from a raster but for different buffer sizes. I have a raster of the population (100 m size pixel) and a SpatialPolygonDataFrame with the localisation of volcanoes. According to the volcanic explosivity index (VEI) of those volcanoes, I created a new column in the spdf with different buffer sizes (VEI = 1 --> buffer_size = 5000; VEI = 2 --> buffer_size = 10000, ...). Now, I want to extract the sum of pixel included inside the buffer. I want to do it the more efficient ! Then, I wanted to make a loop, but it doesn't work... Can somebody tell me why?
When I want to extract for a single buffer value, there is no problem (see the following code) :
people_number <- extract(x = population_proj, y = locations_spdf_proj, buffer = 10000, fun = sum)
But When I want to do that in a loop, I have a warning message (Error in .cellValues(x, y, ...)
) :
for (i in 1:length(locations_spdf_proj)){
people[[i]] <- extract(x = population_proj, # raster layer
y = locations_spdf_proj[[i]], # SPDF with locations for buffer
buffer = locations_spdf_proj$buffer_size[[i]], # buffer size
fun = sum) # value to extract (sum of all pixels)
}