0

I have some data that exist in a waterway system river network, and I'm trying to draw a buffer around some points, to see which areas of the water lie within a 10km boat ride.

library(raster)
library(ggplot2)

canada <- raster::getData("GADM",country="CAN",level=1)
canada_prov = canada[canada$NAME_1 == "British Columbia"] # subset to just BC

location <- data.frame(
  name = c("one", "two"),
  lat = c(52.79883, 52.53555),
  long = c(-128.3144, -128.3593)
)

ggplot2::ggplot() +
  geom_polygon(data = canada_prov,
               aes(x = long, y = lat, group = group),
               colour = "black",
               linewidth = 0.01,
               fill = "grey65") +
  geom_point(data = location, 
             aes(x = long, y = lat), shape = 21, fill = "red", size = 3) + 
  coord_cartesian(xlim = c(-128.6, -128.2), ylim = c(52.4, 52.95)) + 
  theme_bw() + 
    labs(x = "Longitude (°)", y = "Latitude (°)") 

enter image description here

Here the dark gray colour is land and the white is water. What I want to do is create a buffer around these points that shows everywhere I could get in these waterways if I drove a boat for 10km.

The reason I'm having trouble is I know I can create a single circular buffer around these points, but I need the edge of the buffer polygon to respect the restrictions of the land/water divide. I also don't want the buffer to just do a straight-line distance of 10km to everywhere in the waterways.

Is there a way I can go about this? I haven't found anything in sf or raster packages yet that seems to be what I'm looking for?

Ideally what I would end up with is something that looks like this crappy hand-drawn version here:

enter image description here

As always any help appreciated!!

colebrookson
  • 831
  • 7
  • 18
  • 1
    There are a couple of solutions here: https://stackoverflow.com/q/68596244/7547327 that should point you in the right direction. Not exactly the same question, but the underlying methods should give you a starting point. – mrhellmann Apr 19 '23 at 22:23
  • Oh great I hadn't seen this one, thanks! – colebrookson Apr 20 '23 at 23:26

0 Answers0