source: branches/branch-1.8/zoo-project/zoo-services/hello-r/cgi-env/hello.R @ 981

Last change on this file since 981 was 873, checked in by djay, 7 years ago

Add support for R language and its documentation.

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1source("minimal.r")
2
3hellor <- 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
21failR <- function(conf,inputs,outputs){
22    zoo[["conf"]][["lenv"]][["message"]] <<- ZOOTranslate("Failed running from R world!")
23    return(zoo[["SERVICE_FAILED"]])
24}
25
26voronoipolygons <- 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
49RVoronoi <- 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
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png