/
meta.R
66 lines (61 loc) · 1.98 KB
/
meta.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
#' Extract meta information
#'
#' @inheritParams wk::wkb_translate_wkt
#' @param recursive Pass `TRUE` to recurse into multi-geometries
#' and collections to extract meta of sub-geometries
#' @param type A string version of the geometry type (e.g.,
#' point, linestring, polygon, multipoint, multilinestring,
#' multipolygon, geometrycollection)
#' @param type_id An integer version of the geometry type
#'
#' @return A data.frame with columns:
#' - `feature_id`: The index of the top-level feature
#' - `nest_id`: The recursion level (if feature is a geometry collection)
#' - `part_id`: The part index (if nested within a multi-geometry or collection)
#' - `type_id`: The type identifier (see [wk_geometry_type()])
#' - `size`: For points and linestrings the number of points, for polygons
#' the number of rings, and for mutlti-geometries and collection types,
#' the number of child geometries.
#' - `srid`: The spatial reference identifier as an integer
#'
#' @export
#'
#' @examples
#' wkt_meta("POINT (30 10)")
#' wkt_meta("GEOMETRYCOLLECTION (POINT (30 10))", recursive = FALSE)
#' wkt_meta("GEOMETRYCOLLECTION (POINT (30 10))", recursive = TRUE)
#'
wkb_meta <- function(wkb, recursive = FALSE) {
new_data_frame(cpp_meta_wkb(wkb, recursive = recursive))
}
#' @rdname wkb_meta
#' @export
wkt_meta <- function(wkt, recursive = FALSE) {
new_data_frame(cpp_meta_wkt(wkt, recursive = recursive))
}
#' @rdname wkb_meta
#' @export
wkt_streamer_meta <- function(wkt, recursive = FALSE) {
new_data_frame(cpp_meta_wkt_streamer(wkt, recursive = recursive))
}
#' @rdname wkb_meta
#' @export
wk_geometry_type <- function(type_id) {
c(
"point", "linestring", "polygon",
"multipoint", "multilinestring", "multipolygon",
"geometrycollection"
)[as.integer(type_id)]
}
#' @rdname wkb_meta
#' @export
wk_geometry_type_id <- function(type) {
match(
type,
c(
"point", "linestring", "polygon",
"multipoint", "multilinestring", "multipolygon",
"geometrycollection"
)
)
}