-
Notifications
You must be signed in to change notification settings - Fork 19
/
SpatialCoveragePlusSample.R
61 lines (46 loc) · 1.62 KB
/
SpatialCoveragePlusSample.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
library(spcosa)
library(sp)
#Read data with coordinates and other attributes of fine grid (discretization of study area)
load(file="Data/HunterValley4Practicals.RData")
grd <- grdHunterValley
head(grd)
N <- nrow(grd)
# Choose number of locations of spatial coverage sample
n<-90
#Compute clusters (geostrata) and select centres
coordinates(grd)<- ~Easting+Northing
gridded(grd)<-TRUE
set.seed(314)
myStrata <- stratify(grd, nStrata = n, equalArea=FALSE, nTry=10)
mySCsample <- spsample(myStrata)
# Compute average distance between neighbouring points of spatial coverage sample
gridTopology <- as(getGridTopology(grd), "data.frame")
A <- N * gridTopology$cellsize[1]^2
d <- sqrt(A/n)
# Specify separation distances and subsample sizes
h <- c(20)
m <- c(10)
# Select random subsample from the spatial coverage sample
mySCsample.df <- as(mySCsample, "data.frame")
set.seed(314)
ids <-sample(nrow(mySCsample.df),sum(m))
mySubsample <- mySCsample.df[ids,]
# Select locations in random direction at distances h from subsample
first<-1
final<-cumsum(m)
plus <- NULL
for (i in 1:length(h)) {
dxy <- matrix(nrow=m[i],ncol=2)
angle<-runif(n=m[i],min=0,max=2*pi)
dxy[,1]=h[i]*sin(angle)
dxy[,2]=h[i]*cos(angle)
plus.h<-mySubsample[c(first:final[i]),]+dxy
plus <- rbind(plus,plus.h)
first <- final[i]+1
}
# Plot strata, spatial coverage sample and supplemental sample
library(ggplot2)
pdf(file = "SpatialCoveragePlusSample.pdf", width = 7, height = 7)
plot(myStrata,mySCsample) +
geom_point(data = plus, mapping = aes(x= Easting, y =Northing), shape =2,size=1.5 )
dev.off()