Disclaimer : The data has been sourced from the example dataset of the ECRINS database for the river Weser basin, Germany as included in the Spatial Watershed Aggregation and Spatial Drainage Network Analysis (Watersheds) package obtained from the Comprehensive R Archive Network (CRAN). The source code and data was obtained for academic use under the GNU General Public License v3 as released by the author of the package.
Excerpts from Spatial Data Analysis using R and QGIS
1. Excerpts from the Course
February 1, 2019
1 Methods for Spatial Watershed Aggregation and Spatial Drainage
Network Analysis
Dependencies: Watersheds, methods, sp, maptools, rgeos, sp, splancs, ggplot2, geojson, rgdal
Disclaimer : The data has been sourced from the example dataset of the ECRINS database for
the river Weser basin, Germany as included in the Spatial Watershed Aggregation and Spatial
Drainage Network Analysis (Watersheds) package obtained from the Comprehensive R Archive
Network (CRAN). The source code and data was obtained for academic use under the GNU Gen-
eral Public License v3 as released by the author of the package.
Spatial analysis on watersheds using tributary network to aggregate and order as per the run-
off outlet points and size of tributary watersheds based on the specific watershed.
• Identification of the locations of inlet for catchment and outlet for Runoff area are important
for creating the sub-sub basin area.
• Creation of sub-sub basin watersheds with identifying nodes of intersections of river and
tributes
• Implementation of R functions for determining the actual inlet and outlet nodes from tribu-
taries
1.1 Outline of Watershed Analysis
• Installation of required R packages (geojson, ggplot2, maptools, sp, and Watershed)
• Assign values to variables as per the requirement of each function as per the documentation
and the data.
• Use of data visualisation methods using appropriate plotting methods
1.2 Description of Dataset
The dataset contains the following subsets:
• basin : an object SpatialPolygonsDataFrame as is defined in package sp that represents the
river Weser basin. The data slot contains 6 variables as attributes of 1 observation.
1
2. • ctry : an object SpatialPolygonsDataFrame as is defined in package sp that represents the
administrative boundary of Germany. The data slot contains 6 variables as attributes of 1
observation.
• node: an object SpatialPointsDataFrame as is defined in package sp that represents the
nodes of the ECRINS river network of the river Weser basin. The data slot contains 13 vari-
ables as attributes of 3882 observations.
• rAller : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Aller, a major tributary of the river Weser. The data slot contains 74 vari-
ables as attributes of 88 observations.
• rDiemel : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Diemel, a major tributary of the river Weser. The data slot contains 74
variables as attributes of 39 observations.
• rFulda : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Fulda, a major tributary of the river Weser. The data slot contains 74
variables as attributes of 82 observations.
• rHunte : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Hunte, a major tributary of the river Weser. The data slot contains 74
variables as attributes of 34 observations.
• river : an object SpatialLinesDataFrame as is defined in package sp that represents the
ECRINS river network of the river Weser basin. The data slot contains 52 variables as at-
tributes of 3874 observations.
• rWerra : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Werra, a major tributary of the river Weser. The data slot contains 74
variables as attributes of 120 observations.
• rWeser : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Weser. The data slot contains 74 variables as attributes of 104 observations.
• rWiumme : an object SpatialLinesDataFrame as is defined in package sp that represents the
basin of the river Wiumme, a major tributary of the river Weser. The data slot contains 74
variables as attributes of 18 observations.
• station : an object SpatialPoints as is defined in package sp that represents a point of
interest for which the watershed will be aggregated an ordered. Could be a point with the
coordinates of a measurement station.
• subbasin : an object SpatialPolygonsDataFrame as is defined in package sp that represents
the subbasins of the tributaries of the river Weser. The data slot contains 4 variables as
attributes of 4 observations.
• zhyd : an object SpatialPolygonsDataFrame as is defined in package sp that contains the
primary hydrological units of the river Weser basin accordingly with ECRINS. The data slot
contains 50 variables as attributes and 915 observations.
1.3 Importing Dependencies
In [1]: library(sp)
library(Watersheds)
library(ggplot2)
library(geojson)
data(WatershedsData)
Loading required package: maptools
2
3. Checking rgeos availability: TRUE
Loading required package: rgeos
rgeos version: 0.4-2, (SVN revision 581)
GEOS runtime version: 3.6.1-CAPI-1.10.1
Linking to sp version: 1.3-1
Polygon checking: TRUE
Loading required package: lattice
Loading required package: splancs
Spatial Point Pattern Analysis Code in S-Plus
Version 2 - Spatial and Space-Time analysis
Attaching package: 'geojson'
The following object is masked from 'package:graphics':
polygon
1.4 Mapping of River Station and Tributaries-River Interactions
In [2]: station1 = WatershedsData$station
subbasin1 = WatershedsData$subbasin
zhyd1 = WatershedsData$zhyd
river1 = WatershedsData$river
node1 = WatershedsData$node
River Station shall be the intersection of spatial points station1 and the SpatialLines-
Dataframe river1
In [3]: tributary = RiverStation(
station1,
river1
)
plot(
tributary,
col = "blue"
)
plot(
station1,
pch = 21,
bg = "red",
cex = .8,
add = TRUE
3
5. 1.5 Plotting of Primary Watershed / River Sub-basin
In [4]: id = list(
gIntersects(
WatershedsData$rWerra,
WatershedsData$subbasin,
byid=TRUE)
)
subbasin_rWerra = SpDF_Subset(
id,
WatershedsData$subbasin
)
plot(
subbasin_rWerra
)
title(
"Pimary Watershed / River Sub-Basin"
)
5
6. 1.6 Mapping of River Sub-Basin and tributory Watershed
Subsetting the river Werra zhyd watersheds on the primary river basin.
In [5]: id = list(
gIntersects(
WatershedsData$rWerra,
WatershedsData$zhyd,
byid = TRUE
)
)
plot(
subbasin_rWerra
6
8. 1.7 Creation of Drainage Networks within Primary Watershed (River Basin)
Subsetting the river Werra river drainage watersheds on the primary river basin.
In [6]: id = list(
gIntersects(
subbasin_rWerra,
WatershedsData$river,
byid = TRUE
)
)
river_rWerra = SpDF_Subset(
id,
8
10. 1.7.1 Generation of Tibutary Watershed using River-Tributary Interscection (Case-1)
The Watersheds.IOR1 function determines the inlet and outlet nodes for zhyd watershed ob-
jects in Case 1 for those watersheds whose length between river inlet and outlet is unity
i.e. length(riverIO)=1
In [7]: station1 = SpatialPoints(
coords = cbind(
4232972,
3327634
),
proj4string = slot(
subbasin1,
10
11. "proj4string"
)
)
watershed = new(
"Watershed",
station = station1,
subbasin = subbasin1,
zhyd = zhyd1,
river = river1,
c1 = subbasin1,
node = node1
)
a = Watershed.Order(
watershed
)
c1 = a[[1]]
nodeIO = a[[9]]
c1_river = a[[10]]
[1] "length(riverIO) == 1"
Determining inlet and outlet watershed nodes, and distances of nodeIO to c1
In [8]: boundary = gBoundary(
c1
)
dist = gDistance(
nodeIO,
boundary,
byid = TRUE
)
a = Watershed.IOR1(
x = nodeIO,
dist = dist
)
c1_inlet = a$inlet; c1_inlet
c1_outlet = a$outlet; c1_outlet
0
coordinates OBJECTID ID WSO_ID SOURCE LEN_TOM NUM_SEG ELEV
143 (4234350, 3330950) 25485 587506 7 N 57980 9 2
WINDOW WXSOID NodID Is_2Keep LENK_FRS LENK_TOM
143 2000 <NA> Y000587506 -1 0 57.98
In [9]: plot(
c1,
11
13. 1.7.2 Generation of Tibutary Watershed using River-Tributary Interscection (Case-2)
The Watersheds.IOR2 function determines the inlet and outlet nodes for zhyd watershed ob-
jects in Case 2 for those watersheds whose length between river inlet and outlet object is 2
i.e. length(riverIO)=2
In [10]: station1 = SpatialPoints(
coords = cbind(
4330341.36,
3284797.06
),
proj4string = slot(
subbasin1,
13