# NOT RUN {
############
## Loading the monthly time series of precipitation within the Ebro River basin.
data(EbroPPtsMonthly)
## Loading the gis data
data(EbroPPgis)
## Loading the shapefile with the subcatchments
data(EbroCatchmentsCHE)
## Projection for the Subcatchments file
# European Datum 50, Zone 30N
require(sp)
p4s <- CRS("+proj=utm +zone=30 +ellps=intl +units=m +no_defs")
## Selecting the first day of 'EbroPPtsMonthly' for all the stations.
# The first column of 'EbroPPtsMonthly' has the dates
x.ts <- as.numeric(EbroPPtsMonthly[1, 2:ncol(EbroPPtsMonthly)])
## Setting the name of the gauging stations
names(x.ts) <- colnames(EbroPPtsMonthly[1,2:ncol(EbroPPtsMonthly)])
##################################################
## 1) IDW interpolation and plot
## Probably you will need to resize your window
# }
# NOT RUN {
x.idw <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID", bname="CHE_BASIN_NAME",
type= "both",
subcatchments= EbroCatchmentsCHE,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "IDW Precipitation on the Ebro")
# }
# NOT RUN {
##################################################
## 2) Ordinary Kriging interpolation and plot, in catchments defined by a shapefile
## Probably you will need to resize your window
# }
# NOT RUN {
# Computing OK, over of 3000x3000m, sampled withinthe subcatchments defined by 'subcatchments'
x.ok <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID", bname="CHE_BASIN_NAME",
type= "both", formula=value~1,
subcatchments= EbroCatchmentsCHE,
p4s= p4s,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "OK Precipitation on the Ebro", arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
# Getting the interpolated values in each polygon
# ('var1.pred' field in the output data.frame object)
x.ok.block <- slot(x.ok[["Block"]], "data")
# Getting the interpolated values in each cell (SpatialPixelsDataFrame object)
# (the pedicted values in each cell are stored in the 'var1.pred' field of the
# 'data' slot)
x.ok.cells <- x.ok[["Cells"]]
# Plotting the interpolated values in each cell
spplot(x.ok.cells, "var1.pred")
# }
# NOT RUN {
##################################################
## 3) Ordinary Kriging interpolation and plot, in an area defined by a raster map.
## The raster map may be any \link[sp]{SpatialGridDataFrame-class} object, read with
## the \code{\link[rgdal]{readGDAL}} function of the \pkg{rgdal} package or similar.
## Probably you will need to resize your window
#Loading the DEM
data(EbroDEM1000m)
#Giving a meaningful name to the predictor
EbroDEM1000m$ELEVATION <- EbroDEM1000m$band1
# Saving memory
EbroDEM1000m$band1 <- NULL
# Computing OK, over the spatial grid defined by the DEM
# }
# NOT RUN {
x.ok <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
formula=value~1,
p4s= p4s,
predictors=EbroDEM1000m,
ColorRamp= "Precipitation",
main= "OK Precipitation on the Ebro",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
# }
# NOT RUN {
##################################################
## 4) Kriging with External Drift interpolation and plot
## Probably you will need to resize your window
#Loading the DEM
data(EbroDEM1000m)
#Giving a meaningful name to the predictor
EbroDEM1000m$ELEVATION <- EbroDEM1000m$band1
# Saving memory
EbroDEM1000m$band1 <- NULL
# Forcing the projection of the DEM to be the same of the 'subcatchments' argument
# (just because I know in advance they are the same)
proj4string(EbroDEM1000m) <- p4s
# Computing KED
# }
# NOT RUN {
x.ked <- hydrokrige(x.ts= x.ts, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
bname="CHE_BASIN_NAME", elevation="ELEVATION",
type= "cells",
formula=value~ELEVATION,
subcatchments= EbroCatchmentsCHE,
predictors=EbroDEM1000m,
cell.size= 3000,
ColorRamp= "Precipitation",
main= "KED Precipitation on the Ebro",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000)
# }
# NOT RUN {
##################################################
## 5) Block IDW interpolation and plot of 'EbroPPtsMonthly' for 3 months
# }
# NOT RUN {
x.idw <- hydrokrige(x.ts= EbroPPtsMonthly, x.gis=EbroPPgis,
X="EAST_ED50", Y="NORTH_ED50", sname="ID",
bname="CHE_BASIN_NAME",
type= "cells", #'both'
subcatchments= EbroCatchmentsCHE,
cell.size= 3000,
ColorRamp= "Precipitation",
arrow.plot= TRUE,
arrow.offset= c(900000,4750000), arrow.scale= 20000,
scalebar.plot= TRUE,
sb.offset= c(400000,4480000), sb.scale= 100000,
dates=1,
from="1942-01-01", to="1942-03-01")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab