-
Notifications
You must be signed in to change notification settings - Fork 0
/
extendr-wrappers.R
101 lines (92 loc) · 3.25 KB
/
extendr-wrappers.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
# Generated by extendr: Do not edit by hand
# nolint start
#
# This file was created with the following call:
# .Call("wrap__make_arcpbf_wrappers", use_symbols = TRUE, package_name = "arcpbf")
#' @docType package
#' @usage NULL
#' @useDynLib arcpbf, .registration = TRUE
NULL
read_pbf_ <- function(path) .Call(wrap__read_pbf_, path)
#' Read a pbf file as a raw vector
#'
#' @param path the path to the `.pbf` file.
#'
#' @returns a raw vector
#' @export
#' @examples
#' count_fp <- system.file("count.pbf", package = "arcpbf")
#' oid_fp <- system.file("ids.pbf", package = "arcpbf")
#' tbl_fp <- system.file("small-table.pbf", package = "arcpbf")
#' fc_fp <- system.file("small-points.pbf", package = "arcpbf")
#' count_raw <- open_pbf(count_fp)
#' oid_raw <- open_pbf(oid_fp)
#' tbl_raw <- open_pbf(tbl_fp)
#' fc_raw <- open_pbf(fc_fp)
open_pbf <- function(path) .Call(wrap__open_pbf, path)
#' Process a FeatureCollection PBF
#'
#' Process a pbf from a raw vector or a list of raw vectors.
#'
#' @param proto either a raw vector or a list of raw vectors containing a FeatureCollection pbf
#'
#' @details
#'
#' There are three types of PBF FeatureCollection responses that may be
#' returned.
#'
#' ### Feature Result
#'
#' In the case the PBF is a `FeatureResult` and `use_sf = FALSE`, a `data.frame`
#' is returned with the spatial reference stored in the `crs` attribute.
#' Otherwise an `sf` object is returned.
#'
#' ### Count Result
#'
#' The PBF can also return a count result, for example if the [query parameter](https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-layer-.htm)
#' `returnCountOnly` is set to `true`. In this case, a scalar integer vector
#' is returned.
#'
#' ### Object ID Result
#'
#' In the case that the query parameter `returnIdsOnly` is `true`, a
#' `data.frame` is returned containing the object IDs and the column name
#' set to the object ID field name in the feature service.
#'
#' @returns
#'
#' - For count results, a scalar integer.
#' - For object ID results a `data.frame` with one column.
#' - For pbfs that contain geometries, a list of 3 elements:
#' - `attributes` is a `data.frame` of the fields of the FeatureCollection
#' - `geometry` is an sfc object _**without a computed bounding box or coordinate reference system set**_
#' - `sr` is a named list of the spatial reference of the feature collection
#'
#' **Important**: Use [`post_process_pbf()`] to convert to an `sf` object with a computed bounding box and CRS.
#'
#' @export
#'
#' @examples
#' count_fp <- system.file("count.pbf", package = "arcpbf")
#' oid_fp <- system.file("ids.pbf", package = "arcpbf")
#' tbl_fp <- system.file("small-table.pbf", package = "arcpbf")
#' fc_fp <- system.file("small-points.pbf", package = "arcpbf")
#'
#' # count response
#' count_raw <- open_pbf(count_fp)
#' process_pbf(count_raw)
#'
#' # object id response
#' oid_raw <- open_pbf(oid_fp)
#' head(process_pbf(oid_raw))
#'
#' # table feature collection
#' tbl_raw <- open_pbf(tbl_fp)
#' process_pbf(tbl_raw)
#'
#' # feature collection with geometry
#' fc_raw <- open_pbf(fc_fp)
#' process_pbf(fc_raw)
process_pbf <- function(proto) .Call(wrap__process_pbf, proto)
multi_resp_process_ <- function(resps) .Call(wrap__multi_resp_process_, resps)
# nolint end