Skip to content

Instantly share code, notes, and snippets.

@allixender
Created July 13, 2015 03:25
Show Gist options
  • Save allixender/ecc15b05a5c1178d3a92 to your computer and use it in GitHub Desktop.
Save allixender/ecc15b05a5c1178d3a92 to your computer and use it in GitHub Desktop.
# wps.des: sos4R_wps_gwl_horo, title = interp mean gw levels per Foi per year via SOS,
# abstract = A Simple and useless demo WPS Process just summing the meaausrements for a given Foi;
# wps.in: year, string;
# calculate something... variable "input" don't has to be initialized
library(sos4R)
library(akima)
library(fields)
c("soe_352007",
"soe_352051",
"soe_352111",
"soe_352131",
"soe_352271",
"soe_352311",
"soe_353291",
"soe_361003",
"soe_361041",
"soe_362003",
"soe_362005",
"soe_362017",
"soe_362033",
"soe_362331",
"soe_362541",
"soe_362551",
"soe_362661",
"soe_362711",
"soe_362951",
"soe_362511",
"soe_362521",
"soe_363251",
"soe_372061")
myopts <- curlOptions(ssl.verifyhost=FALSE, ssl.verifypeer=FALSE, followlocation=TRUE)
handle <- getCurlHandle( .opts= myopts)
gwl.converters <- SosDataFieldConvertingFunctions(
"http://resources.smart-project.info/gemet/groundwaterlevel" = sosConvertDouble,
"http://www.opengis.net/def/property/OGC/0/SamplingTime" = sosConvertTime,
"http://www.opengis.net/def/property/OGC/0/FeatureOfInterest" = sosConvertString)
gwl <- SOS(url = "http://portal.smart-project.info/52nSOSv3.5.0/sos",
dataFieldConverters = gwl.converters, curlHandle=handle)
yearString = paste(c(year, '/01/01::', year, '/12/31'), collapse='')
yearTP = sosCreateTime(sos = gwl, time = yearString)
gwl_offerings <- sosOfferings(gwl)
gwl_off_no2 <- gwl_offerings[[2]]
observ<-getObservation(sos = gwl, offering=gwl_off_no2, saveOriginal = FALSE, eventTime = yearTP)
result<-sosResult(observ, coordinates = TRUE)
measLevel <- colnames(result)[[2]]
obs.crs<-sosGetCRS(observ)
gwl_spdf<-SpatialPointsDataFrame(coords = result[,c("lon", "lat")],data = result[,c("SamplingTime", "feature", measLevel)],proj4string = obs.crs)
gwl_spdf_sc <- as(observ, "SpatialPointsDataFrame")
x <- result[["lat"]]
y <- result[["lon"]]
z <- result[[measLevel]]
matr <- interp(x,y,z, duplicate = "mean", linear = TRUE)
zr<-range(result[[measLevel]])
# zr<-range(c(0, 50))
image.plot(matr, zlim = zr )
points(gwl_spdf_sc, pch = 19)
randnum <- sample(10000:99999, 1)
image = paste(c('tmp-sos-interp-',randnum ,'.png'), collapse='')
png(file = image)
titletext = paste(c('interpolated groundwater levels in the Horowhenua area'), collapse='')
subtitletext = paste(c('gwl/masl ', year, '/01/01 - ', year, '/12/31'), collapse='')
image.plot(matr, zlim = zr)
title(main = titletext, sub = subtitletext )
# dev.off()
graphics.off()
# wps.out: image, png;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment