Skip to content

Commit 7b7e850

Browse files
author
tmcd
committed
Commit of beta version 1.5.1
1 parent 2249dce commit 7b7e850

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

R/draw.strat.grts.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ draw.strat.grts <- function(n, over.n, strat.var, alloc.type, fn, dir){
33
# draw a GRTS sample using spsurvey. Spsurvey should already be loaded.
44
#
55

6-
# cat("Drawing GRTS sample...This can take a while ...\n")
6+
cat("Drawing GRTS sample...This can take a while ...\n")
77

88
# Check whether the frame has been read already, and the sp object is laying around.
99
shp <- getSpFrame( fn, dir )
1010

11+
print(head(data.frame(shp)))
12+
1113
if(!(strat.var %in% names(shp))){
1214
stop(paste("Variable", strat.var, "not found in frame"))
1315
}
@@ -49,6 +51,5 @@ draw.strat.grts <- function(n, over.n, strat.var, alloc.type, fn, dir){
4951

5052
# Call the user visible routine that takes a SpatialX object
5153
ans <- grts.strat(n, over.n, strat.var, shp )
52-
5354
ans
5455
}

R/getSpFrame.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ getSpFrame <- function( filename, dir ){
77
# The shapefile is not laying around. Read it.
88

99
# Write the command to console and histry file
10-
timestamp( paste( filename, "<- readOGR(", dir, ",", filename, ")"), prefix="", suffix=" ## SDraw")
10+
# NOTE: THIS USED TO WORK. HOWEVER, WHEN WE UPGRADED TO R 3.1.3 TIMESTAMP STOPPED WORKING AND INFACT
11+
# CRASHED R WHEN RUNNING IN RSTUDIO. SO, WE HAVE TAKEN ALL THESE OUT. IF REQUIRED, WE WILL OPEN OUR OWN
12+
# LOG FILE AND WRITE THERE.
13+
#print("writing to log")
14+
# timestamp( paste( filename, "<- readOGR(", dir, ",", filename, ")"), prefix="", suffix=" ## SDraw")
1115

1216
shp <- readShape(dir, filename) # a wrapper for readOGR
1317

R/grts.strat.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ strata.levels<-names(table(data.frame(shp)[,strat.var]))
7171
attr(Stratsites, "over.n") <- over.n
7272
attr(Stratsites, "sp.object") <- deparse(substitute(shp))
7373
attr(Stratsites, "frame.type") <- sframe.type
74+
attr(Stratsites, "strata.var") <- "stratum"
7475

7576
Stratsites
7677
}

R/plotSample.R

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,35 @@ plotSample <- function(button, dat){
3535
# If the sample object exists, plot points on the map
3636
if( exists( outobj )){
3737
samp <- get( outobj, pos=.GlobalEnv )
38-
n <- attr(samp, "n")
3938
stype <- attr(samp, "sample.type")
4039

41-
if( nrow(samp) == n ){
42-
# No oversample
43-
points( samp, pch=16 )
44-
legend("bottomleft", legend=paste(stype, "sample points"), pch=c(16))
40+
# Is this a stratified sample -> different legend
41+
strat.var <- attr(samp, "strata.var")
42+
43+
# Determine if this sample has an oversample
44+
has.oversamp <- "pointType" %in% names(data.frame(samp))
45+
if( has.oversamp ) has.oversamp <- length(unique(data.frame(samp)[,"pointType"])) > 1
46+
47+
if( !is.null( strat.var )){
48+
# We have stratified sample
49+
strat.ind <- data.frame(samp)[,strat.var]
50+
strat.vals <- levels(factor(strat.ind))
51+
strat.cols <- terrain.colors(length(strat.vals))
52+
for(h in strat.vals){
53+
points( samp[strat.ind == h,], pch=which(h==strat.vals)+14, col=strat.cols[which(h==strat.vals)] )
54+
}
55+
legend("bottomleft", legend=strat.vals, pch=1:length(strat.vals)+14, col=strat.cols, title="Strata:")
56+
# Note. oversample points in stratified samples, if they exist, are not plotted.
57+
} else if( has.oversamp ){
58+
# There is some oversample
59+
samp.ind <- data.frame(samp)[,"pointType"]
60+
points( samp[samp.ind=="Sample",], pch=16 )
61+
points( samp[samp.ind=="OverSample",], pch=1 )
62+
legend("bottomleft", legend=paste(stype, c("sample", "over sample")), pch=c(16,1))
4563
} else {
46-
# There is some oversample
47-
points( samp[1:n,], pch=16 )
48-
points( samp[ (n+1):nrow(samp),], pch=1 )
49-
legend("bottomleft", legend=paste(stype, c("sample", "over sample")), pch=c(16,1))
64+
# No oversample
65+
points( samp, pch=16 )
66+
legend("bottomleft", legend=paste(stype, "sample points"), pch=c(16))
5067
}
5168

5269
}

R/run.sample.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ run.sample <- function(button, dat){
6363
# Write out the command to console and history file. Must do this
6464
# here, rather than in draw.XXX routines, because I want to write out
6565
# the assignment to the output object.
66-
cat(">")
67-
switch( stype,
68-
"BAS " = timestamp(paste(outobj, "<- bas(", n + over.n, ",", fn, ")"), prefix="", suffix=" ## SDraw"),
69-
"GRTS" = timestamp(paste(outobj, "<- grts.equi(", n, ",", over.n, ",", fn, ")"), prefix="", suffix=" ## SDraw"),
70-
"SSS " = timestamp(paste(outobj, "<- sss(", n , ",", fn, ")"), prefix="", suffix=" ## SDraw")
71-
)
66+
# NOTE: TIMESTAMP STOPPED WORKING. AT SOME POINT, RETURN AND WRITE THESE
67+
# COMMANDS TO A SDRAW.LOG FILE.
68+
# cat(">")
69+
# switch( stype,
70+
# "BAS " = timestamp(paste(outobj, "<- bas(", n + over.n, ",", fn, ")"), prefix="", suffix=" ## SDraw"),
71+
# "GRTS" = timestamp(paste(outobj, "<- grts.equi(", n, ",", over.n, ",", fn, ")"), prefix="", suffix=" ## SDraw"),
72+
# "SSS " = timestamp(paste(outobj, "<- sss(", n , ",", fn, ")"), prefix="", suffix=" ## SDraw")
73+
# )
7274

7375

7476
# Actually draw the sample
@@ -78,7 +80,6 @@ run.sample <- function(button, dat){
7880
"GRTS" = draw.grts(n,over.n,fn,in.dir),
7981
"SSS " = draw.sss(n,over.n,fn,in.dir),
8082
stop(paste("Unknown sample type:",stype)))
81-
print("hello2")
8283

8384
# Save the sample in global environment. Type of sample is an attribute.
8485
# SDrawPackageSpace <- as.environment( "package:SDraw" )

R/run.strat.sample.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ run.strat.sample <- function(button, dat){
22
#tester for running stratified sample
33

44
# Query the entry fields
5+
56
n <- dat$n.entry$getText()
67
fn <- dat$shape.in.entry$getText()
78
dir <- dat$shape.in.dir$getText()
@@ -70,13 +71,15 @@ run.strat.sample <- function(button, dat){
7071

7172
# Actually draw the sample
7273
# Remember that fn is the text string name of the shapefile, without .shp, and without path.
74+
7375
samp <- switch( stype,
7476
#"BAS " = draw.bas(n,over.n,fn),
7577
"GRTS" = draw.strat.grts(n,over.n,strat.var,alloc.type,fn,dir),
7678
#"SSS " = draw.sss(n,over.n,fn),
7779
stop(paste("Unknown sample type:",stype)))
7880

7981
# Save the sample in global environment. Type of sample is an attribute.
82+
print("back from draw.strat.grts in run.strat.sample")
8083
assign( outobj, samp, pos=.GlobalEnv )
8184

8285
# Tell user we are finished.

man/stratified.GUI.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Following is a description of the functioning of all buttons at the bottom of th
8585
.GlobalEnv workspace.
8686
8787
}
88+
}
8889
8990
After the sample draw, one can check allocation sample sizes in each strata using the \code{table} function. For example, if the output R name is 'samp', one can check sample sizes with \code{table(samp$strata)}. One can plot the study area and sample points with \code{plot(frame); points(samp)}, assuming \code{frame} is the 'sp' object containing the frame
9091

0 commit comments

Comments
 (0)