简体   繁体   中英

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 ie 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 ?)

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)

从西向东增加强度

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM