I plotted domestic livestock abundance (each spatial point corresponds to different values, it appears as 1,2.3......but each of these 1, 2,3 has corresponding number of livestock counts in it) in a 4 by 4km grid (raster layer).

Then i plot the facal sample collection locations and around each sample made a buffer of 10km radius of spatialpolygonsdataframe. then got the list of or number of domestic livestock abundance in each buffer. But now stuck with how to extract the values associated with each of extracted lists.

res(r) <- 4000.0 #sets the resolution 

r <- setValues(r, 1:ncell(r))
grid <- as(r,'SpatialPolygonsDataFrame') # grid for making SPDF

wp.per.grid <- over(wp.count.sp, grid) # gives count per grid

buff <-  gBuffer(scats.sp, width=10000, byid = TRUE) # made buffer

d1<-data.frame(pointID = 1:nrow(wildp.count.sp))
for(i in 1:length(buff@polygons)){
  column<-as.logical(point.in.polygon(point.x = wp.count.sp@coords[,1], 
                                      point.y = wp.count.sp@coords[,2], 
                                      pol.x = buff@polygons[[i]]@Polygons[[1]]@coords[,1], 
                                      pol.y = buff@polygons[[i]]@Polygons[[1]]@coords[,2]))
# gives no of counts in each buffer created
d2<-data.frame(Buffer = 1:length(buff@polygons), numberOfpoints = NA)
for(i in 1:nrow(d2)){

how to find out which are these buffers esp for those that are more than 1 and how to get the no.of counts associated with each of the identified points inside buffer???

  • thank you @Spacedman for editing forgot how to post properly – Johnny Feb 9 '18 at 15:45
  • Why are you coercing to a SpatialPolygonsDataFrame and buffering your points? Just use raster::extract with the buffer argument. You can pass a function to extract to tally the grid cells however you want (eg., sum). If you want a point count, within a specified distance, you can just use a knn or neighbor distance approach in spdep. Your code seems overly verbose. – Jeffrey Evans Feb 9 '18 at 16:18
  • @Jeffrey i actually have the domestic livestock counts in a group and the entire group has only one reference location& i need to get counts or abundance of livestock in a buffer of a point location (this is wild scat location). therefore plotted the scat locations on the grid so that i can plot the domesticlivestock reference points.I managed to do it but like i said each reference domesticlocation has several counts (that is why need the grids, so i can find out all references in each).I do not know how to calculate the livestock counts attached to each reference point – Johnny Feb 12 '18 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.