I have a map of London's waterways, which I've grided into a raster dataset to enable me to measure proximity to water from randomly generated points.
What I'd like to do please is to constrain the randomly generated points to a polygon (which represents the sampling area) within the larger grid.
This is the code I've used:
randLocs <- spsample(waterGrid, n=200, type='random')
waterGrid is the overall grid enabling me to measure distances, and I have a polygon which I've loaded as a shapefile.