Search code examples
rloopsgisworkflowdata-manipulation

for-loop question for spatial buffer in R


I am doing a sensitivity analysis for a spatial buffer.

buffer_house <- gBuffer(house_prj, width = 1, byid = TRUE)

How would I do a for-loop to increase the buffer size for each iteration.

For example a width = 5 in one iteration up to width = 100by running a loop for 5m intervals.

Can anyone help please


Solution

  • You would do this:

    for(width in seq(5, 100, 5)){
      buffer_house <- gBuffer(house_prj, width = width, byid = TRUE)
    }
    

    You would still have to save all of those outcomes though. The code I showed you will overwrite buffer_house each time.