-
Notifications
You must be signed in to change notification settings - Fork 12
/
split_geoshape.Rd
127 lines (117 loc) · 4.17 KB
/
split_geoshape.Rd
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/split_geoshape.R
\name{split_geoshape}
\alias{split_geoshape}
\title{Annotate a dataframe containing a geoshape column with lon, lat, alt of the
geotrace's first point.}
\usage{
split_geoshape(
data,
colname,
wkt = FALSE,
odkc_version = get_default_odkc_version()
)
}
\arguments{
\item{data}{(dataframe) A dataframe with a geoshape column.}
\item{colname}{(chr) The name of the geoshape column.
This column will be retained.}
\item{wkt}{Whether geofields are GeoJSON (if FALSE) or WKT
strings (if TRUE), default: FALSE.}
\item{odkc_version}{The ODK Central version as a semantic version string
(year.minor.patch), e.g. "2023.5.1". The version is shown on ODK Central's
version page \verb{/version.txt}. Discard the "v".
\code{ruODK} uses this parameter to adjust for breaking changes in ODK Central.
Default: \code{\link{get_default_odkc_version}} or "2023.5.1" if unset.
Set default \code{get_default_odkc_version} through
\code{ru_setup(odkc_version="2023.5.1")}.
See \code{vignette("Setup", package = "ruODK")}.}
}
\value{
The given dataframe with the geoshape column colname, plus
three new columns, \code{colname_longitude}, \code{colname_latitude},
\code{colname_altitude}.
The three new columns are prefixed with the original \code{colname} to
avoid naming conflicts with any other geoshape columns.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}
}
\details{
This function is used by \code{\link{handle_ru_geopoints}}
on all \code{geopoint} fields as per \code{\link{form_schema}}.
}
\examples{
\dontrun{
library(magrittr)
data("geo_fs")
data("geo_wkt_raw")
data("geo_gj_raw")
# Find variable names of geoshapes
geo_fields <- geo_fs \%>\%
dplyr::filter(type == "geoshape") \%>\%
magrittr::extract2("ruodk_name")
geo_fields[1] # First geoshape in data: shape_location_shape_gps
# Rectangle but don't parse submission data (GeoJSON and WKT)
geo_gj_rt <- geo_gj_raw \%>\%
odata_submission_rectangle(form_schema = geo_fs)
geo_wkt_rt <- geo_wkt_raw \%>\%
odata_submission_rectangle(form_schema = geo_fs)
# Data with first geoshape split
gj_first_gt <- split_geoshape(geo_gj_rt, geo_fields[1], wkt = FALSE)
cn_gj <- names(gj_first_gt)
testthat::expect_true("shape_location_shape_gps_longitude" \%in\% cn_gj)
testthat::expect_true("shape_location_shape_gps_latitude" \%in\% cn_gj)
testthat::expect_true("shape_location_shape_gps_altitude" \%in\% cn_gj)
testthat::expect_true(
is.numeric(gj_first_gt$shape_location_shape_gps_longitude)
)
testthat::expect_true(
is.numeric(gj_first_gt$shape_location_shape_gps_latitude)
)
testthat::expect_true(
is.numeric(gj_first_gt$shape_location_shape_gps_altitude)
)
wkt_first_gt <- split_geoshape(geo_wkt_rt, geo_fields[1], wkt = TRUE)
cn_wkt <- names(wkt_first_gt)
testthat::expect_true("shape_location_shape_gps_longitude" \%in\% cn_wkt)
testthat::expect_true("shape_location_shape_gps_latitude" \%in\% cn_wkt)
testthat::expect_true("shape_location_shape_gps_altitude" \%in\% cn_wkt)
testthat::expect_true(
is.numeric(wkt_first_gt$shape_location_shape_gps_longitude)
)
testthat::expect_true(
is.numeric(wkt_first_gt$shape_location_shape_gps_latitude)
)
testthat::expect_true(
is.numeric(wkt_first_gt$shape_location_shape_gps_altitude)
)
}
}
\seealso{
Other utilities:
\code{\link{attachment_get}()},
\code{\link{attachment_link}()},
\code{\link{attachment_url}()},
\code{\link{drop_null_coords}()},
\code{\link{form_schema_parse}()},
\code{\link{get_one_attachment}()},
\code{\link{get_one_submission}()},
\code{\link{get_one_submission_att_list}()},
\code{\link{get_one_submission_audit}()},
\code{\link{handle_ru_attachments}()},
\code{\link{handle_ru_datetimes}()},
\code{\link{handle_ru_geopoints}()},
\code{\link{handle_ru_geoshapes}()},
\code{\link{handle_ru_geotraces}()},
\code{\link{isodt_to_local}()},
\code{\link{odata_submission_rectangle}()},
\code{\link{predict_ruodk_name}()},
\code{\link{prepend_uuid}()},
\code{\link{split_geopoint}()},
\code{\link{split_geotrace}()},
\code{\link{strip_uuid}()},
\code{\link{tidyeval}},
\code{\link{unnest_all}()}
}
\concept{utilities}