#connect to database
getDefaultDB()
## Not run:
# #connect to postgreSQL database
# require("RObsDat")
# require("RPostgreSQL")
# m <- dbDriver("PostgreSQL")
# con <- dbConnect(m, user="a_user", password="secret", dbname="obsdat")
# sqhandler <- new("odm1_1Ver", con=con)
# options(odm.handler=sqhandler)
#
# #connect to MySQL database
# require("RObsDat")
# require("RMySQL")
# m <- dbDriver("MySQL")
# con <- dbConnect(m, user="a_user", password="secret", dbname="obsdat")
# sqhandler <- new("odm1_1Ver", con=con)
# options(odm.handler=sqhandler)
#
# #connect to SQLite database
# require("RObsDat")
# require("RSQLite")
# m <- dbDriver("SQLite")
# dbname = "database.db"
# con <- dbConnect(m, dbname = dbname)
# sqhandler <- new("odm1_1Ver", con=con)
# options(odm.handler=sqhandler)
#
# ## End(Not run)
#Store metadata in database
addSite(Code="test", Name="Virtual test site", x=-5, y=46,
LatLongDatum="WGS84", Elevation=1500, State="Germany")
addVariable(Name="Distance", Unit="cm", ValueType="Field Observation",
GeneralCategory="Instrumentation", Code="test_dist")
addQualityControlLevel(ID=6,Code="test_ok", Definition="The default")
addISOMetadata(TopicCategory="Unknown", Title="Testdata",
Abstract="This data is created to test the functions of RObsDat")
addSource(Organization="Your Org", SourceDescription="Madeup data",
SourceLink="RObsDat Documentation", ContactName="Yourself",
Metadata="Testdata")
library(xts)
library(spacetime)
example.data <- xts(1:40, seq(as.POSIXct("2014-01-01", tz="UTC"),
as.POSIXct("2014-02-09", tz="UTC"), length.out=40))
example.data[40] <- 30
example.data[35] <- 22
addDataValues(example.data[1:20], Site="Virtual test site", Variable="test_dist",
Source="Madeup", QualityControlLevel="test_ok")
#Avoid duplicates automatically
example.data[15] <- 30
addDataValues(example.data, Site="Virtual test site", Variable="test_dist",
Source="Madeup", QualityControlLevel="test_ok")
inDB <- getDataValues(Site="test")
stplot(inDB, mode="ts")
#Version management
inDB <- getDataValues(Site="test")
to.correct <- which(inDB@data > 30)
inDB@data[to.correct,] <- 20
if(NROW(inDB@data)>=30){
inDB@data[30,] <- 32
updateDataValues(inDB, "Correction of wrong value")
}
ver2 <- inDB
if(NROW(ver2@data)>=13){
ver2@data[10:13,] <- 60
updateDataValues(ver2, "Changing more data")
}
inDB <- getDataValues(Site="test")
ver3 <- inDB
if(NROW(ver3@data)>=32){
ver3@data[30:32,] <- 33
updateDataValues(ver3, "Ups, I used 60 instead of 33 by mistake")
}
#If only one time point or one location is selected you have to use '@ValueIDs' in addition.
if(dim(inDB@ValueIDs)[2]>=29) deleteDataValues(inDB@ValueIDs[,29], "Remove a value")
if(dim(inDB@ValueIDs)[2]>=14) deleteDataValues(inDB@ValueIDs[,10:14], "Remove several values")
# When more than one spatial point and times are given,
# then use the usually selection without 'ValueIDs'.
# deleteDataValues(testSiteData[2,20:24], "Remove several values.")
getDataVersions()
versionQuery1 <- getDataValues(Site=1, VersionID=1)
stplot(versionQuery1, mode="ts")
versionQuery2 <- getDataValues(Site=1, VersionID=2)
stplot(versionQuery2, mode="ts")
Run the code above in your browser using DataLab