1
|
# Exploratory assessment of differences between ESRI's flow direction
|
2
|
# output and GRASS Terraflow's flow direction output, with focus here on
|
3
|
# the SFD (D8) Terraflow output, which is (I think) basically the same
|
4
|
# as what ESRI uses.
|
5
|
#
|
6
|
# The input DEM in all cases is what I gather to be the Oregon case
|
7
|
# study DEM, which is this 3x3 degree, 3" resolution, smoothed (somehow?
|
8
|
# by someone?) SRTM:
|
9
|
# jupiter:~organisms/flow/experimental/srtmv41_smth
|
10
|
#
|
11
|
# The ESRI flowdirection raster used here is what I gather was produced by
|
12
|
# layers.aml, which applies the GRID flowdirection function to the
|
13
|
# smoothed DEM to produce this output:
|
14
|
# jupiter:~organisms/flow/experimental/flowdir
|
15
|
#
|
16
|
# I converted both of the above rasters to GeoTIFFs to bring them over
|
17
|
# to my machine to work with.
|
18
|
#
|
19
|
# I then generated the two Terraflow output flow direction grids (SFD
|
20
|
# and MFD) using the commands contained in grass-terraflow.sh.
|
21
|
#
|
22
|
# Other resources:
|
23
|
# * ESRI ArcGIS 9.3 Flow Direction documentation
|
24
|
# http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?topicname=flow%20direction
|
25
|
# * GRASS terraflow documentation
|
26
|
# http://grass.osgeo.org/grass64/manuals/html64_user/r.terraflow.html
|
27
|
#
|
28
|
# Jim Regetz
|
29
|
# NCEAS
|
30
|
# Created 16-Jun-2011
|
31
|
|
32
|
|
33
|
# data directory (local to xander)
|
34
|
datadir <- "~/media/temp/dem/new/flow"
|
35
|
|
36
|
# load data
|
37
|
|
38
|
# ESRI flowdirection output (see notes above)
|
39
|
or.flowdir.esri <- raster(file.path(datadir, "flowdir_OR_esri.tif"))
|
40
|
# GRASS terraflow (MFD) output
|
41
|
or.flowdir.grass.mfd <- raster(file.path(datadir,
|
42
|
"flowdir_OR_grass.tif"))
|
43
|
# GRASS terraflow (SFD) output
|
44
|
or.flowdir.grass.sfd <- raster(file.path(datadir,
|
45
|
"flowdir_OR_grass_sfd.tif"))
|
46
|
|
47
|
# create raster indicating where ESRI and terraflow(SFD) differ
|
48
|
flow.disagreement <- or.flowdir.esri
|
49
|
flow.disagreement[] <- ifelse(values(or.flowdir.esri !=
|
50
|
or.flowdir.grass.sfd), 1, NA)
|
51
|
|
52
|
# illustrated differences
|
53
|
plot(or.hs, col=grey.colors(100))
|
54
|
mp <- prod(dim(flow.disagreement))
|
55
|
plot(flow.disagreement, add=TRUE, col="blue", legend=FALSE, maxpixels=mp)
|
56
|
|
57
|
# now isolate differences in cases where terraflow is not zero (i.e.,
|
58
|
# places calculated as pits?
|
59
|
flow.disagreement[or.flowdir.grass.sfd==0] <- NA
|
60
|
plot(flow.disagreement, add=TRUE, col="red", legend=FALSE, maxpixels=mp)
|
61
|
|
62
|
# notice what happens at the edges...
|
63
|
|
64
|
# in northernmost row, esri routes most cells east or west (i.e, along
|
65
|
# border) plus some north, and a few other misc directions
|
66
|
table(as.matrix(or.flowdir.esri)[1,])
|
67
|
## 1 2 4 8 16 32 64
|
68
|
## 1574 4 1 3 1600 1 425
|
69
|
|
70
|
# whereas terraflow SFD routes all cells north
|
71
|
table(as.matrix(or.flowdir.grass.sfd)[1,])
|
72
|
## 64
|
73
|
## 3608
|
74
|
|
75
|
# (analogous patterns for the other 3 raster edges)
|
76
|
|
77
|
# quantify proportion in concordance, excluding the edges
|
78
|
edges <- c(1, 3608)
|
79
|
mean(as.matrix(or.flowdir.esri)[-edges, -edges] ==
|
80
|
as.matrix(or.flowdir.grass.sfd)[-edges, -edges])
|
81
|
## [1] 0.9086855
|
82
|
|
83
|
# ...and what proportion are either in concordance or have 0 values
|
84
|
# associated with terraflow SFD? (means pits?)
|
85
|
mean((as.matrix(or.flowdir.esri)[-edges, -edges] ==
|
86
|
as.matrix(or.flowdir.grass.sfd)[-edges, -edges]) |
|
87
|
as.matrix(or.flowdir.grass.sfd)[-edges, -edges]==0)
|
88
|
## [1] 0.9755789
|
89
|
|