1 | source("minimal.r") |
---|
2 | |
---|
3 | hellor <- function(a,b,c) { |
---|
4 | # Create a useless graph |
---|
5 | cars <- c(1,2,3,4,5) |
---|
6 | filePath <- paste(a[["main"]][["tmpPath"]],paste("cars",zoo[["conf"]][["lenv"]][["usid"]],".png",sep=""),sep="/") |
---|
7 | png(filePath) |
---|
8 | plot(cars) |
---|
9 | quartzFonts(avenir = c("Avenir Book", "Avenir Black", "Avenir Book Oblique", "Avenir Black Oblique")) |
---|
10 | par(family = 'avenir') |
---|
11 | title("Hello from R World!") |
---|
12 | dev.off() |
---|
13 | # Set the result |
---|
14 | zoo[["outputs"]][["Result"]][["value"]] <<- paste("Hello",b[["S"]][["value"]],"from the R World! (plot ref:",filePath,")",sep=" ") |
---|
15 | # Update the main conf settings |
---|
16 | zoo[["conf"]][["lenv"]][["message"]] <<- "Running from R world!" |
---|
17 | # Return SERVICE_SUCCEEDEED |
---|
18 | return(zoo[["SERVICE_SUCCEEDEED"]]) |
---|
19 | } |
---|
20 | |
---|
21 | failR <- function(conf,inputs,outputs){ |
---|
22 | zoo[["conf"]][["lenv"]][["message"]] <<- ZOOTranslate("Failed running from R world!") |
---|
23 | return(zoo[["SERVICE_FAILED"]]) |
---|
24 | } |
---|
25 | |
---|
26 | voronoipolygons <- function(x,poly) { |
---|
27 | require(deldir) |
---|
28 | if (.hasSlot(x, 'coords')) { |
---|
29 | crds <- x@coords |
---|
30 | } else crds <- x |
---|
31 | bb = bbox(poly) |
---|
32 | rw = as.numeric(t(bb)) |
---|
33 | z <- deldir(crds[,1], crds[,2],rw=rw) |
---|
34 | w <- tile.list(z) |
---|
35 | polys <- vector(mode='list', length=length(w)) |
---|
36 | require(sp) |
---|
37 | finalCoordinates <- c() |
---|
38 | for (i in seq(along=polys)) { |
---|
39 | pcrds <- cbind(w[[i]]$x, w[[i]]$y) |
---|
40 | pcrds <- rbind(pcrds, pcrds[1,]) |
---|
41 | finalCoordinates[[i]] <- i |
---|
42 | polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i)) |
---|
43 | } |
---|
44 | SP <- SpatialPolygons(polys) |
---|
45 | voronoi <- SpatialPolygonsDataFrame(SP, data=data.frame(identifier=finalCoordinates)) |
---|
46 | return(voronoi) |
---|
47 | } |
---|
48 | |
---|
49 | RVoronoi <- function(conf,inputs,outputs){ |
---|
50 | require(rgdal) |
---|
51 | require(rgeos) |
---|
52 | message(names(inputs[["InputPoints"]])) |
---|
53 | message(inputs[["InputPoints"]]) |
---|
54 | myGeoData <- readOGR(inputs[["InputPoints"]][["cache_file"]],layer=ogrListLayers(inputs[["InputPoints"]][["cache_file"]])[1], verbose = FALSE); |
---|
55 | voronoiData <- voronoipolygons(myGeoData,myGeoData) |
---|
56 | filePath <- paste(conf[["main"]][["tmpPath"]],paste("RBuffer_",zoo[["conf"]][["lenv"]][["usid"]],".shp",sep=""),sep="/") |
---|
57 | writeOGR(voronoiData, dsn=filePath, layer="Voronoi", driver="ESRI Shapefile", verbose = FALSE) |
---|
58 | zoo[["outputs"]][["Result"]][["storage"]] <<- filePath |
---|
59 | return(zoo[["SERVICE_SUCCEEDEED"]]) |
---|
60 | } |
---|
61 | |
---|