Difference between revisions of "Wikisym 2012 Demo"

From Testiwiki
Jump to: navigation, search
(Large quantity of points on a static Google Maps)
m
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Polygons on dynamic Google Maps ==
+
[[Category:Code under inspection]]
This example plots municipalities of Finland on Google Maps using data from National Land Survey of Finland.
 
<rcode name="polygons_on_google_maps">
 
 
 
library(OpasnetUtilsExt)
 
library(sorvi)
 
library(rgdal)
 
 
 
# Get the shape data of Finnish municipalities using soRvi library
 
data(MML)
 
shp <- MML[["1_milj_Shape_etrs_shape"]][["kunta1_p"]]
 
 
 
# Set the projection
 
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 
proj4string(shp)<-("+init=epsg:3047")
 
shp2<-spTransform(shp,epsg4326String)
 
 
 
# Create the KML data using the shape
 
out<-sapply(slot(shp2,"polygons"),function(x){kmlPolygon(x,name="name",col='#df0000aa',lwd=1,border='black',description="desc") })
 
data<-paste(
 
paste(kmlPolygon(kmlname="This will be layer name", kmldescription="<i>More info about layer here</i>")$header, collapse="\n"),
 
paste(unlist(out["style",]), collapse="\n"),
 
paste(unlist(out["content",]), collapse="\n"),
 
paste(kmlPolygon()$footer, collapse="\n"),
 
sep=''
 
)
 
 
 
# Show the KML data on Google Maps
 
google.show_kml_data_on_maps(data)
 
 
 
</rcode>
 
 
 
== Points on dynamic Google Maps ==
 
This examples plots buildings of Kuopio on Google Maps. User can give the minimum age of buildings to plot as an input parameter.
 
 
 
 
 
<rcode name='plots_on_dynamic_maps' variables="name:age|description:Building minimum age|default:120">
 
 
 
library(rgdal)
 
library(RColorBrewer)
 
library(classInt)
 
library(OpasnetUtilsExt)
 
library(RODBC)
 
 
 
if (age > 190)
 
{
 
age <- 190
 
}
 
 
 
shp <- spatial_db_query(paste('SELECT * FROM kuopio_house WHERE ika >= ',age,';',sep=''))
 
 
 
coordinates(shp)=c("y_koord","x_koord")
 
 
 
plotvar<-shp@data$ika
 
nclr<-8
 
plotclr<-brewer.pal(nclr,"BuPu")
 
class<-classIntervals(plotvar,nclr,style="quantile")
 
colcode<-findColours(class,plotclr)
 
 
 
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 
proj4string(shp)<-("+init=epsg:3067")
 
shp2<-spTransform(shp,epsg4326String)
 
 
 
 
 
kmlname<-"Kuopio house data"
 
kmldescription<-"Random stuff about here"
 
icon<-"http://maps.google.com/mapfiles/kml/pal2/icon18.png"
 
name<-paste("Value: ",shp2$ika)
 
description <- paste("<b>Age:</b>",shp2$ika,"<br><b>Building ID:</b>",shp2$rakennustunnus)
 
  
data <- google.point_kml(shp2,kmlname,kmldescription,name,description,icon,colcode)
+
==Health effects of Drinking Water Model==
google.show_kml_data_on_maps(data)
 
  
</rcode>
+
This example is model which is built for calculating health effects of drinking water and how water treatment processess affect to the outcome.
  
== Large quantity of points on a static Google Maps ==
+
* [[Ground water pathogen concentrations]]
This example plots large number of point data on static Google Maps. The map produced in this example shows the age (in years) distribution of buildings within Kuopio. User can select the number of age classes (4,6 or 8) and the type of classification.
 
 
 
<rcode name='static_gmaps_test'
 
graphics='1'
 
Variables="name:myclasses|description:Number of classes|type:selection|options:4;4;6;6;8;8|default:8|
 
name:classtype|description:Type of classification|type:selection|options:'equal';Equal Int;'quantile';Quantile;'sd';Standard deviation;'jenks';Jenks|default:'quantile'
 
"
 
>
 
#code goes here
 
library(RgoogleMaps)
 
library(rgdal)
 
library(maptools)
 
library(RColorBrewer)
 
library(classInt)
 
library(OpasnetUtilsExt)
 
 
 
shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house')
 
plotvar<-shp@data$ika
 
nclr<-myclasses
 
plotclr<-brewer.pal(nclr,"Reds")
 
class<-classIntervals(plotvar,nclr,style=classtype)
 
colcode<-findColours(class,plotclr)
 
 
 
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 
proj4string(shp)<-("+init=epsg:3067")
 
shp2<-spTransform(shp,epsg4326String)
 
#get marker information for all points
 
mymarkers<-cbind.data.frame(lat=c(shp2@coords[,2]),lon=c(shp2@coords[,1]),color=colcode);
 
 
 
#get the bounding box:
 
bb <- qbbox(lat = mymarkers[,"lat"], lon = mymarkers[,"lon"])
 
 
 
#MyMap function without the "file destination" parameter
 
MyRmap<-function (lonR, latR, center, size = c(640, 640), 
 
    MINIMUMSIZE = FALSE, RETURNIMAGE = TRUE, GRAYSCALE = FALSE,
 
    NEWMAP = TRUE, zoom, verbose = 1, ...)
 
{
 
    if (missing(zoom))
 
        zoom <- min(MaxZoom(latR, lonR, size))
 
    if (missing(center)) {
 
        lat.center <- mean(latR)
 
        lon.center <- mean(lonR)
 
    }
 
    else {
 
        lat.center <- center[1]
 
        lon.center <- center[2]
 
    }
 
    if (MINIMUMSIZE) {
 
        ll <- LatLon2XY(latR[1], lonR[1], zoom)
 
        ur <- LatLon2XY(latR[2], lonR[2], zoom)
 
        cr <- LatLon2XY(lat.center, lon.center, zoom)
 
        ll.Rcoords <- Tile2R(ll, cr)
 
        ur.Rcoords <- Tile2R(ur, cr)
 
        if (verbose > 1) {
 
            cat("ll:")
 
            print(ll)
 
            print(ll.Rcoords)
 
            cat("ur:")
 
            print(ur)
 
            print(ur.Rcoords)
 
            cat("cr:")
 
            print(cr)
 
        }
 
        size[1] <- 2 * max(c(ceiling(abs(ll.Rcoords$X)), ceiling(abs(ur.Rcoords$X)))) +
 
            1
 
        size[2] <- 2 * max(c(ceiling(abs(ll.Rcoords$Y)), ceiling(abs(ur.Rcoords$Y)))) +
 
            1
 
        if (verbose)
 
            cat("new size: ", size, "\n")
 
    }
 
    return(google.get_map(center = c(lat.center, lon.center), zoom = zoom,
 
        size = size, RETURNIMAGE = RETURNIMAGE,
 
        GRAYSCALE = GRAYSCALE, verbose = verbose, ...))
 
}
 
 
 
MyMap<-MyRmap(bb$lonR,bb$latR,maptype="mobile",scale="2")
 
 
 
PlotOnStaticMap(MyMap,size=c(640,640))
 
 
 
PlotOnStaticMap(MyMap,size=c(640,640),lat=mymarkers[,"lat"],lon=mymarkers[,"lon"],pch=19,cex=0.3,col=colcode,add=T)
 
 
 
legend("topleft", legend=names(attr(colcode, "table")),title="Building Age (Yr)", fill=attr(colcode, "palette"),  cex=1.0, bty="y",bg="white")
 
</rcode>
 
 
 
==Water model==
 
  
 
<rcode  
 
<rcode  
Line 168: Line 14:
 
                 'Ground water - Clean';Ground water - Clean;
 
                 'Ground water - Clean';Ground water - Clean;
 
                 'Ground water - Surface water stress';Ground water - Surface water stress;
 
                 'Ground water - Surface water stress';Ground water - Surface water stress;
                 'Surface water - Vähäinen kuormitus';Surface water - Vähäinen kuormitus;
+
                 'Surface water - Low stress';Surface water - Low stress;
                 'Surface water - Keskisuuri kuormitus';Surface water - Keskisuuri kuormitus;
+
                 'Surface water - Medium stress';Surface water - Medium stress;
                 'Surface water - Suuri kuormitus';Surface water - Suuri kuormitus|
+
                 'Surface water - High stress';Surface water - High stress|
             category:Raakavesi: Patogeenien pitoisuudet|
+
             category:Ground water: Pathogenic concentrations|
                 name:Kampylo|description:Kampylobakteeri-pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Kampylo|description:Cambylobacter-concentration estimation (microbe/l)|default:'Use water source specific classification'|
                 name:Ecoli|description:E.coli O157:H7 -pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Ecoli|description:E.coli O157:H7 -concentration estimation (microbe/l)|default:'Use water source specific classification'|
                 name:Rota|description:Rotavirus-pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Rota|description:Rotavirus-concentration estimation (microbe/l)|default:'Use water source specific classification'|
                 name:Noro|description:Norovirus-pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Noro|description:Norovirus-concentration estimation (microbe/l)|default:'Use water source specific classification'|
                 name:Crypto|description:Cryptosporidium-pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Crypto|description:Cryptosporidium-concentration estimation (microbe/l)|default:'Use water source specific classification'|
                 name:Giardia|description:Giardia-pitoisuus arvio (mikrobia/l)|default:'Luokituksen mukainen'|
+
                 name:Giardia|description:Giardia-concentration estimation (microbe/l)|default:'Use water source specific classification'|
 
                  
 
                  
 
                  
 
                  
             name:Kaupunni|description:Kaupungin oletusarvot|default:'Custom'|type:selection|
+
             name:Kaupunni|description:City default values|default:'Custom'|type:selection|
 
             options:
 
             options:
                 'Custom';Käytä yllä määriteltyjä arvoja;
+
                 'Custom';Use values defined above;
 +
                'Op_en5799';Gotham City;
 
                 'Op_fi2603';Kuopio|
 
                 'Op_fi2603';Kuopio|
             name:Puhdistus|description:Käytössä olevat puhdistusmenetelmät|type:checkbox|
+
             name:Puhdistus|description:Available purification methods|type:checkbox|
 
             options:
 
             options:
                 1;Perinteinen puhdistus;
+
                 1;Traditional purification;
                 2;Hyvin toimva puhdistus;
+
                 2;Highly effective purification;
                 3;Tehostettu puhdistus;
+
                 3;Enhanced purification;
                 4;Hidas hiekkasuodatus;
+
                 4;Slow sand filtration;
                 5;Kalkkikivisuodatus;
+
                 5;Limestone filtration;
                 6;Aktiivihiilisuodatus;
+
                 6;Activated carbon filtration;
                 7;UV suodatus;
+
                 7;UV filtration;
                 8;Otsonointi;|
+
                 8;Ozonisation|
             default:1;4;5;6|category:Vedenpuhdistus: Puhdistusprosessi ja klooraus|
+
             default:1;4;5;6|category:Water purification: Purification processess and chlorinesation|
         name:KlooriAnnos|default:1.5|description:Klooriannos (mg/l)|
+
         name:KlooriAnnos|default:1.5|description:Chlorine dose (mg/l)|
 
      
 
      
         name:VedeKulu|default:1153|description:veden kulutus (ml)|category:Verkosto ja kuluttajat|
+
         name:VedeKulu|default:1153|description:Water consumption (ml)|category:Water network and consumers|
         name:Vaestonkoko|default:100000|description:Altistuvan väestön koko
+
         name:Vaestonkoko|default:100000|description:Population
 
     "
 
     "
 
>
 
>
Line 214: Line 61:
 
     #Patogeenien pitoisuudet
 
     #Patogeenien pitoisuudet
 
      
 
      
     Fetch2(data.frame(Name = "RaaPatPitLuo", Key = "AEmnj6ZNfhIHAt2X"), evaluate = TRUE)
+
     #Fetch2(data.frame(Name = "RaaPatPitLuo", Key = "AEmnj6ZNfhIHAt2X"), evaluate = TRUE)
 +
    # fetching data from english Opasnet
 +
    #Fetch2(data.frame(Name = "RaaPatPitLuo", Key = "kjRoRPqqAzhaG8qR"), evaluate = TRUE)
 +
    temp <- tidy(op_baseGetData("opasnet_base", "Op_en5800"), objname = "RaaPatPitLuo")
 +
    print(xtable(temp), type = "html")
 +
 
 +
    RaaPatPitLuo <- new("ovariable",
 +
name        = "RaaPatPitLuo",
 +
data        = temp
 +
    )
 
      
 
      
    RaaPatPitLuo@output <- RaaPatPitLuo@output[RaaPatPitLuo@output$Raakavesilähde == i.raw.class, ]
+
  # RaaPatPitLuo@output <- RaaPatPitLuo@output[RaaPatPitLuo@output$Raakavesilähde == i.raw.class, ]
 +
  RaaPatPitLuo@output <- RaaPatPitLuo@output[RaaPatPitLuo@output$Water_source == i.raw.class, ]
 
     RaaPatPitLuo@output <- merge(
 
     RaaPatPitLuo@output <- merge(
 
         RaaPatPitLuo@output,  
 
         RaaPatPitLuo@output,  
Line 590: Line 447:
 
print(xtable(dose.response[,c("Pathogen", "Exp.pat", "P.inf", "VedDesTehSource")]), type="html") # Patogeeneille altistuminen ja infektion todennäköisyys
 
print(xtable(dose.response[,c("Pathogen", "Exp.pat", "P.inf", "VedDesTehSource")]), type="html") # Patogeeneille altistuminen ja infektion todennäköisyys
  
cat("<span style='font-size: 1.2em;font-weight:bold;'>Arvioitu terveysvaikutus</span>\n")
+
cat("<span style='font-size: 1.2em;font-weight:bold;'>Estimated health effects</span>\n")
 +
 
 +
cat(sum((1 - (1 - temp$P.ill.g.inf * temp$P.inf)^365) * Vaestonkoko, na.rm = TRUE), " stomach flus per year \n")
 +
 
 +
cat(sum(Health.effects$DALYs, na.rm = TRUE), " DALY's from stomach flus \n")   
 +
</rcode>
 +
 
 +
== Polygons on dynamic Google Maps ==
 +
This example plots municipalities of Finland on Google Maps using data from National Land Survey of Finland.
 +
<rcode name="polygons_on_google_maps">
 +
 
 +
library(OpasnetUtilsExt)
 +
library(sorvi)
 +
library(rgdal)
 +
 
 +
# Get the shape data of Finnish municipalities using soRvi library
 +
data(MML)
 +
shp <- MML[["1_milj_Shape_etrs_shape"]][["kunta1_p"]]
 +
 
 +
# Set the projection
 +
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 +
proj4string(shp)<-("+init=epsg:3047")
 +
shp2<-spTransform(shp,epsg4326String)
 +
 
 +
# Create the KML data using the shape
 +
out<-sapply(slot(shp2,"polygons"),function(x){kmlPolygon(x,name="name",col='#df0000aa',lwd=1,border='black',description="desc") })
 +
data<-paste(
 +
paste(kmlPolygon(kmlname="This will be layer name", kmldescription="<i>More info about layer here</i>")$header, collapse="\n"),
 +
paste(unlist(out["style",]), collapse="\n"),
 +
paste(unlist(out["content",]), collapse="\n"),
 +
paste(kmlPolygon()$footer, collapse="\n"),
 +
sep=''
 +
)
 +
 
 +
# Show the KML data on Google Maps
 +
google.show_kml_data_on_maps(data)
 +
 
 +
</rcode>
 +
 
 +
== Points on dynamic Google Maps ==
 +
This examples plots buildings of Kuopio on Google Maps. User can give the minimum age of buildings to plot as an input parameter.
 +
 
 +
 
 +
<rcode name='plots_on_dynamic_maps' variables="name:age|description:Building minimum age|default:120">
 +
 
 +
library(rgdal)
 +
library(RColorBrewer)
 +
library(classInt)
 +
library(OpasnetUtilsExt)
 +
library(RODBC)
 +
 
 +
if (age > 190)
 +
{
 +
age <- 190
 +
}
 +
 
 +
shp <- spatial_db_query(paste('SELECT * FROM kuopio_house WHERE ika >= ',age,';',sep=''))
 +
 
 +
coordinates(shp)=c("y_koord","x_koord")
 +
 
 +
plotvar<-shp@data$ika
 +
nclr<-8
 +
plotclr<-brewer.pal(nclr,"BuPu")
 +
class<-classIntervals(plotvar,nclr,style="quantile")
 +
colcode<-findColours(class,plotclr)
 +
 
 +
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 +
proj4string(shp)<-("+init=epsg:3067")
 +
shp2<-spTransform(shp,epsg4326String)
 +
 
 +
 
 +
kmlname<-"Kuopio house data"
 +
kmldescription<-"Random stuff about here"
 +
icon<-"http://maps.google.com/mapfiles/kml/pal2/icon18.png"
 +
name<-paste("Value: ",shp2$ika)
 +
description <- paste("<b>Age:</b>",shp2$ika,"<br><b>Building ID:</b>",shp2$rakennustunnus)
 +
 
 +
data <- google.point_kml(shp2,kmlname,kmldescription,name,description,icon,colcode)
 +
google.show_kml_data_on_maps(data)
 +
 
 +
</rcode>
  
cat(sum((1 - (1 - temp$P.ill.g.inf * temp$P.inf)^365) * Vaestonkoko, na.rm = TRUE), " vatsatautia vuodessa \n")
+
== Large quantity of points on a static Google Maps ==
 +
This example plots large number of point data on static Google Maps. The map produced in this example shows the age (in years) distribution of buildings within Kuopio. User can select the number of age classes (4,6 or 8) and the type of classification.
  
cat(sum(Health.effects$DALYs, na.rm = TRUE), " DALY:ä vatsataudeista \n")  
+
<rcode name='static_gmaps_test'
 +
graphics='1'
 +
Variables="name:myclasses|description:Number of classes|type:selection|options:4;4;6;6;8;8|default:8|
 +
name:classtype|description:Type of classification|type:selection|options:'equal';Equal Int;'quantile';Quantile;'sd';Standard deviation;'jenks';Jenks|default:'quantile'
 +
"
 +
>
 +
#code goes here
 +
library(RgoogleMaps)
 +
library(rgdal)
 +
library(maptools)
 +
library(RColorBrewer)
 +
library(classInt)
 +
library(OpasnetUtilsExt)
 +
 
 +
shp<-readOGR('PG:host=localhost user=postgres dbname=spatial_db','kuopio_house')
 +
plotvar<-shp@data$ika
 +
nclr<-myclasses
 +
plotclr<-brewer.pal(nclr,"Reds")
 +
class<-classIntervals(plotvar,nclr,style=classtype)
 +
colcode<-findColours(class,plotclr)
 +
 
 +
epsg4326String <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
 +
proj4string(shp)<-("+init=epsg:3067")
 +
shp2<-spTransform(shp,epsg4326String)
 +
#get marker information for all points
 +
mymarkers<-cbind.data.frame(lat=c(shp2@coords[,2]),lon=c(shp2@coords[,1]),color=colcode);
 +
 
 +
#get the bounding box:
 +
bb <- qbbox(lat = mymarkers[,"lat"], lon = mymarkers[,"lon"])
 +
 
 +
#MyMap function without the "file destination" parameter
 +
MyRmap<-function (lonR, latR, center, size = c(640, 640), 
 +
    MINIMUMSIZE = FALSE, RETURNIMAGE = TRUE, GRAYSCALE = FALSE,
 +
    NEWMAP = TRUE, zoom, verbose = 1, ...)
 +
{
 +
    if (missing(zoom))
 +
        zoom <- min(MaxZoom(latR, lonR, size))
 +
    if (missing(center)) {
 +
        lat.center <- mean(latR)
 +
        lon.center <- mean(lonR)
 +
    }
 +
    else {
 +
        lat.center <- center[1]
 +
        lon.center <- center[2]
 +
    }
 +
    if (MINIMUMSIZE) {
 +
        ll <- LatLon2XY(latR[1], lonR[1], zoom)
 +
        ur <- LatLon2XY(latR[2], lonR[2], zoom)
 +
        cr <- LatLon2XY(lat.center, lon.center, zoom)
 +
        ll.Rcoords <- Tile2R(ll, cr)
 +
        ur.Rcoords <- Tile2R(ur, cr)
 +
        if (verbose > 1) {
 +
            cat("ll:")
 +
            print(ll)
 +
            print(ll.Rcoords)
 +
            cat("ur:")
 +
            print(ur)
 +
            print(ur.Rcoords)
 +
            cat("cr:")
 +
            print(cr)
 +
        }
 +
        size[1] <- 2 * max(c(ceiling(abs(ll.Rcoords$X)), ceiling(abs(ur.Rcoords$X)))) +
 +
            1
 +
        size[2] <- 2 * max(c(ceiling(abs(ll.Rcoords$Y)), ceiling(abs(ur.Rcoords$Y)))) +
 +
            1
 +
        if (verbose)
 +
            cat("new size: ", size, "\n")
 +
    }
 +
    return(google.get_map(center = c(lat.center, lon.center), zoom = zoom,
 +
        size = size, RETURNIMAGE = RETURNIMAGE,
 +
        GRAYSCALE = GRAYSCALE, verbose = verbose, ...))
 +
}
 +
 
 +
MyMap<-MyRmap(bb$lonR,bb$latR,maptype="mobile",scale="2")
 +
 
 +
PlotOnStaticMap(MyMap,size=c(640,640))
 +
 
 +
PlotOnStaticMap(MyMap,size=c(640,640),lat=mymarkers[,"lat"],lon=mymarkers[,"lon"],pch=19,cex=0.3,col=colcode,add=T)
 +
 
 +
legend("topleft", legend=names(attr(colcode, "table")),title="Building Age (Yr)", fill=attr(colcode, "palette"),  cex=1.0, bty="y",bg="white")
 
</rcode>
 
</rcode>

Latest revision as of 09:28, 27 August 2013


Health effects of Drinking Water Model

This example is model which is built for calculating health effects of drinking water and how water treatment processess affect to the outcome.

Ground water: Pathogenic concentrations

Water resource:

Cambylobacter-concentration estimation (microbe/l):

E.coli O157:H7 -concentration estimation (microbe/l):

Rotavirus-concentration estimation (microbe/l):

Norovirus-concentration estimation (microbe/l):

Cryptosporidium-concentration estimation (microbe/l):

Giardia-concentration estimation (microbe/l):

City default values:

Water purification: Purification processess and chlorinesation

Available purification methods:
Traditional purification
Highly effective purification
Enhanced purification
Slow sand filtration
Limestone filtration
Activated carbon filtration
UV filtration
Ozonisation

Chlorine dose (mg/l):

Water network and consumers

Water consumption (ml):

Population:

+ Show code

Polygons on dynamic Google Maps

This example plots municipalities of Finland on Google Maps using data from National Land Survey of Finland.

+ Show code

Points on dynamic Google Maps

This examples plots buildings of Kuopio on Google Maps. User can give the minimum age of buildings to plot as an input parameter.


Building minimum age:

+ Show code

Large quantity of points on a static Google Maps

This example plots large number of point data on static Google Maps. The map produced in this example shows the age (in years) distribution of buildings within Kuopio. User can select the number of age classes (4,6 or 8) and the type of classification.

Number of classes:

Type of classification:

+ Show code