/
classes.R
233 lines (215 loc) · 6.89 KB
/
classes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# register the S3 `igraph` class for use with S4 methods.
setOldClass("igraph")
selectMethod("show", "igraph")
#' The `hce` class
#'
#' Used internally.
#'
#' @slot voronoi The Voronoi tessellation of the patches and resistance
#' surface (`RasterLayer`).
#'
#' @slot patchLinks A `RasterLayer` whose values indicate patch ids
#' (positive integers) and link ids (negative integers).
#'
#' @slot linkData A `data.frame` of link attributes.
#'
#' @author Alex Chubaty and Sam Doctolero
#' @importClassesFrom raster RasterLayer
#' @include grainscape-package.R
#' @keywords internal
setClass(
"hce",
slots = list(
voronoi = "RasterLayer", patchLinks = "RasterLayer",
linkData = "data.frame"
)
)
#' The `mpg` class
#'
#' @slot mpg The minimum planar graph as class `igraph`.
#'
#' @slot patchId The input `patch` raster with patch cells assigned to
#' their id (`RasterLayer`).
#'
#' @slot voronoi The Voronoi tessellation of the patches and resistance
#' surface (`RasterLayer`).
#'
#' @slot lcpPerimWeight The paths of the links between patches and their
#' accumulated costs (`RasterLayer`).
#'
#' @slot lcpLinkId The paths of the links between patches and their id (`RasterLayer`).
#'
#' @slot mpgPlot A `RasterLayer` version of the `mpg`, which can be
#' easily plotted to visualize the MPG.
#'
#' The `mpg` slot contains useful vertex and edge attributes.
#' Vertex attributes give attributes of patches including patch area,
#' the area of patch edges, the core area of each patch, and the coordinates
#' of the patch centroid.
#' All areal measurements are given as raster cell counts.
#' Edge attributes give attributes of the graph links including link
#' weights giving accumulated resistance/least-cost path distance,
#' Euclidean distance, and the start and end coordinates of each link.
#'
#' @author Alex Chubaty and Paul Galpern
#' @importClassesFrom raster RasterLayer
#' @include grainscape-package.R
#'
setClass(
"mpg",
slots = list(
mpg = "igraph", patchId = "RasterLayer", voronoi = "RasterLayer",
lcpPerimWeight = "RasterLayer", lcpLinkId = "RasterLayer",
mpgPlot = "RasterLayer"
)
)
#' The `goc` class
#'
#'
#' @slot voronoi A `RasterLayer` describing the regions of proximity in
#' resistance units around the focal patches or points.
#'
#'
#' @slot summary A summary of the the grains of connectivity generated and
#' their properties.
#'
#' @slot th A list giving the GOC graph at each threshold.
#'
#' Each element of `th` contains a `goc` object giving the GOC graph
#' as class [igraph()].
#' Vertex attributes describes qualities of each polygon including the coordinates
#' of each polygon centroid, the area of these polygons, and the original patch
#' IDs in the MPG that are included in each polygon.
#' All areal measurements are given as raster cell counts.
#' A variety of edge attributes are also given in the GOC graph.
#' See [distance()] for more information.
#'
#' @author Alex Chubaty and Paul Galpern
#' @importClassesFrom raster RasterLayer
#' @importClassesFrom sp SpatialPolygons
setClass(
"goc",
slots = list(
voronoi = "RasterLayer",
summary = "data.frame", th = "list"
)
)
#' Show a `grainscape` object
#'
#' Custom `show` method to safely print the contents of a `goc` or
#' `grain` object.
#'
#'
#' @param object A [`goc()`][goc-class] or
#' [`grain()`][grain-class] object.
#'
#' @export
#' @rdname show
setMethod("show",
signature = "goc",
definition = function(object) {
cat("Slot voronoi:\n")
cat(show(object@voronoi))
cat("\nSlot summary:\n")
cat(show(object@summary))
cat("\nSlot th:\n")
cat("List of ", length(object@th), " goc elements", "\n")
}
)
#' The `grain` class
#'
#'
#' @slot voronoi A `RasterLayer` describing the regions of proximity in
#' resistance units around the focal patches or points.
#'
#' @slot summary A summary of the the grains of connectivity generated and
#' their properties.
#'
#' @slot centroids A `SpatialPoints` object indicating the grain's polygon
#' centroids.
#'
#' @slot th A list of `igraph` objects giving the graphs describing the relationship
#' among the polygons in that grain
#'
#' See [grain()] for more information.
#'
#' @author Alex Chubaty and Paul Galpern
#' @importClassesFrom raster RasterLayer
#' @importClassesFrom sp SpatialPoints SpatialPolygonsDataFrame
setClass(
"grain",
slots = list(
voronoi = "RasterLayer",
summary = "data.frame", centroids = "SpatialPoints",
th = "igraph"
)
)
#' @export
#' @rdname show
setMethod("show",
signature = "grain",
definition = function(object) {
cat("Slot voronoi:\n")
cat(show(object@voronoi))
cat("\nSlot summary:\n")
cat(show(object@summary))
cat("\nSlot centroids:\n")
cat("SpatialPoints objects with ", length(object@centroids), " features", "\n")
cat("\nSlot th:\n")
cat(show(object@th))
}
)
#' The `corridor` class
#'
#' @slot voronoi A `RasterLayer` representation of the boundaries
#' of the voronoi polygons.
#'
#' @slot linksSP A `SpatialLinesDataFrame` representation of links
#' in the grains of connectivity graph.
#'
#' @slot nodesSP A `SpatialPoints` representation of the nodes in
#' the grains of connectivity graph
#'
#' @slot shortestLinksSP A `SpatialLines` representation of the links in
#' the shortest path between coordinates
#'
#' @slot shortestNodesSP A `SpatialPoints` representation of the nodes in
#' the shortest path between coordinates
#'
#' @slot corridorLength A `numeric` of length 1 giving the length of the
#' shortest path between coordinates in accumulated
#' resistance units.
#'
#' See [corridor()] for more information.
#'
#' @author Alex Chubaty and Paul Galpern
#' @importClassesFrom raster RasterLayer
#' @importClassesFrom sp SpatialLines SpatialLinesDataFrame SpatialPoints
#'
setClass(
"corridor",
slots = list(
voronoi = "RasterLayer", linksSP = "SpatialLinesDataFrame",
nodesSP = "SpatialPoints", shortestLinksSP = "SpatialLines",
shortestNodesSP = "SpatialPoints", corridorLength = "numeric"
)
)
#' @export
#' @rdname show
setMethod("show",
signature = "corridor",
definition = function(object) {
cat("Slot voronoi:\n")
cat(show(object@voronoi))
cat("\nSlot linksSP:\n")
cat(show(object@linksSP))
cat("\nSlot nodesSP:\n")
cat(show(object@nodesSP))
cat("\nSlot shortestLinksSP:\n")
cat(show(object@shortestLinksSP))
cat("\nSlot shortestNodesSP:\n")
cat(show(object@shortestNodesSP))
cat("\nSlot corridorLength:\n")
cat(show(object@corridorLength))
}
)