-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
coordinates.R
157 lines (150 loc) · 3.13 KB
/
coordinates.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
# gm_dimensions
#
# Calculates the dimensions of geometries.
#
# @return
# A list containing
# \itemize{
# \item{dimensions - a 5-column matrix where \itemize{
# \item{column 1 - the start-index of the geometry}
# \item{column 2 - the end-index of the geometry}
# \item{column 3 - the dimension of the geometry}
# \item{column 4 - the nesting level of the geometry}
# \item{column 5 - the SEXP type of the geometry}
# }
# }
# \item{max_dimension - the maximum dimension in all the geometries}
# \item{max_nest - the maximum nesting level in all the geometries}
# }
#
# @examples
#
# ## A vector (representing an POINT)
# x <- 1:2
# gm_dimensions( x )
#
# ## A matrix (representing a LINE)
# m <- matrix(1:6, ncol = 2 )
# gm_dimensions( m )
#
# ## A list (representing a POLYGON)
# l <- list( m )
# gm_dimensions( l )
#
# ## A list of lists (representing a MULTIPOLYGON)
# l <- list( l )
# gm_dimensions( l )
#
# ## A list of matrices, points and lists (representing multiple, mixed geometries)
# l <- list( x, m, list( m ) )
# gm_dimensions( l )
#
# @param x object representing a geometry shape (e.g., list of matrices)
#
gm_dimensions <- function( x ) {
rcpp_geometry_dimensions( x )
}
#' gm_coordinates
#'
#' Converts all coordinates from various geometric shapes into a single data.frame.
#'
#' @details
#'
#' The data.frame returned will always have an 'id' column. Then will follow an
#' 'id+counter' column for every level of nesting the geometry is within.
#'
#' The coordinates always start in column 'c1', the first column after all the id columns.
#' Then there is a column 'c+counter' for every coordinate in the geometry.
#'
#' This function is designed to handle multiple and different nested of geometry structures.
#'
#' @param x object representing geometry shapes (e.g., list of matrices)
#'
#' @return a single data.frame representing all the values in the input lists and matrices.
#'
#' @examples
#'
#' x <- 1:3
#' gm_coordinates( x )
#'
#' m <- matrix(1:12, ncol = 3)
#' gm_coordinates( m )
#'
#' l <- list(
#' matrix(1:12, ncol = 2 )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' matrix(1:12, ncol = 4 )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' list(
#' matrix(1:12, ncol = 2)
#' )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' list(
#' matrix(1:12, ncol = 2)
#' , matrix(1:4, ncol = 2)
#' )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' list(
#' matrix(1:12, ncol = 2)
#' , matrix(1:4, ncol = 2)
#' )
#' , 1:5
#' , 1:2
#' , matrix(1:9, ncol = 3)
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' matrix(1:4, ncol = 2)
#' , list(
#' matrix(1:9, ncol = 3)
#' )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' list(
#' list(
#' matrix(1:12, ncol = 2)
#' )
#' )
#' , list(
#' list(
#' matrix(1:24, ncol = 2)
#' )
#' )
#' )
#' gm_coordinates( l )
#'
#' l <- list(
#' list(
#' list(
#' matrix(1:12, ncol = 2)
#' )
#' )
#' , list(
#' list(
#' matrix(1:3, ncol = 3)
#' , matrix(1:24, ncol = 2)
#' )
#' )
#' )
#' gm_coordinates( l )
#'
#'
#' @export
gm_coordinates <- function( x ) {
rcpp_coordinates( x )
}