Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate spatial points with a pattern

I am doing some work where I need to generate both a) random spatial points b) non-random spatial points, over a polygon i.e. for b) the points probability depends on for example an East-West gradient, or distance from some point source or something else

For a) I can generate random points over a polygon using the spsample() command in the sp package as follows:

# Load a spatial polygon from maptools package
library(maptools)
nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],        proj4string=CRS("+proj=longlat +datum=NAD27"))
plot(nc)

library(sp)
pts <- spsample(nc, 100, type="random")
plot(nc)
points(pts, pch=19, col="red")

This gives exactly what I want for a). But, can this be modified for b) so points are more likely in the East than the West for example ? (and whilst still being able to specify I want 100 points ?)

like image 798
user2498193 Avatar asked Nov 23 '15 15:11

user2498193


1 Answers

I only know how to do this using the spatstat package. With the function rpoint You can use any function of the coordinates x,y to define your uneven density of points. Here I define the function to have the value 0 at the West end of the region and grow linearly with slope 100 towards the East:

library(maptools)
library(spatstat)
nc <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
                    proj4string=CRS("+proj=longlat +datum=NAD27"))
nc <- as.owin(nc)
west0 <- nc$xrange[1]
f <- function(x, y, ...){ 100 * (x - west0) }
pts <- rpoint(1000, f, win = nc)
plot(pts)

Increasing intensity from West to East

like image 170
Ege Rubak Avatar answered Oct 05 '22 23:10

Ege Rubak