trace tracker logo

Random Geographic Coordinates Sampling

Generate the specified number of random geographic coordinates from a rectangular space defined by minimum and maximum X (Longitude) and Y (Latitude) coordinates. Input and output coordinates are in decimal degrees, with a specified precision of output values.

No results

No example available
No references available
				######################################
# Program to do random geographic coordinates sampling
######################################
rm(list = ls())

# cat("
Test:",length(commandArgs())) test<- ifelse(length(commandArgs()) == 2, TRUE, FALSE) fpath<- ifelse(test, "webRootUrl", "rtoolsPath") # load header scripts source(paste(fpath, "R/epi_head.R", sep = "")) source(paste(fpath, "R/HTMLStream.R", sep = "")) source(paste(fpath, "R/epitools_functions.r", sep = "")) # extract command arguments # 1 = number of points, 2 = minX, 3 = maxX, 4 = minY, 5 = maxY, 6 = precision # cat("
", a0[8:13]) a1<- type.convert(a0[8:13]) # cat("
", a1) n<- a1[1] # sample size minX<- min(a1[2], a1[3]) # minimum X maxX<- max(a1[2], a1[3]) # maximum X minY<- min(a1[4], a1[5]) # minimum Y maxY<- max(a1[4], a1[5]) # maximum Y digits<- a1[6] # precision heading<- "RGCS Random sampling results" heading2<- "List of randomly selected points" filename<- digest(Sys.time()) tmp.path<- paste(fpath, "tmp/", sep = "") tmp.file<- paste(fpath, "tmp/", filename, sep = "") sinkfile<- paste(fpath, "tmp/", filename, ".txt", sep="") # fpath, # cat("
", data.file) inputs<- array(a1, dim = c(length(a1), 1)) rownames(inputs)<- c("Sample size", "Minimum X", "Maximum X", "Minimum Y", "Maximum Y", "Precision") # do random sampling x<- runif(n, minX, maxX) y<- runif(n, minY, maxY) ran.list<- round(cbind(x, y), digits) ran.list<- ran.list[order(ran.list[,1]),] # ran.list file.name<- file(paste(tmp.file, "_result.xls", sep = ""), open = "wt") writeLines(c(heading, date(), ""), con = file.name) writeLines("Inputs", con = file.name) write.table(inputs, file = file.name, sep = "\t", append = T, col.names = F) writeLines(c("", heading2), con = file.name) write.table(ran.list, file = file.name, sep = "\t", append = T, row.names = F) close(file.name) # output results d1<- paste(substr(date(), 1, 10), substr(date(), 20,24), " @", substr(date(), 11, 16)) # reformat headers output<- paste("

", heading, "

\n") output<- paste(output, "

", "Analysed: ", d1, "

\n", sep="") output<- paste(output, "

Inputs

\n") output<- paste(output, HTMLStream(inputs, cellborder = 0, classfirstline = "mbg", classfirstcolumn = "mbg", classcellinside = "left_mar", cellalign = "center", align = "left")) output<- paste(output, "

Results

\n") output<- paste(output, "

", heading2, "

\n") output<- paste(output, HTMLStream(ran.list, cellborder = 0, classfirstline = "mbg", classfirstcolumn = "mbg", classcellinside = "left_mar", cellalign = "center", align = "left")) output<- paste(output, "

Download excel file of results

\n") output<- paste(output, "Detailed results
\n", sep = "") # nrow(ran.list) # sink() # write output to file file.name<- file(paste(tmp.file, "_result.html", sep = ""), open = "wt") cat(output, file=file.name) close(file.name) #) cat(output)