-
Notifications
You must be signed in to change notification settings - Fork 46
/
google_map_layer_sf.R
51 lines (37 loc) · 1.36 KB
/
google_map_layer_sf.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
# Find Encoded Column
#
# This function is called early in each add_layer function to see if the
# object is sfencoded, and therefore tries to find the polyline column.
# This is required if the user has supplied an `sfencoded` object
#
# @param data the data object
# @param polyline the 'polyline' parameter set by the user in the add_ funciton call
findEncodedColumn <- function(data, polyline) UseMethod("findEncodedColumn")
#' @export
findEncodedColumn.sfencoded <- function(data, polyline) {
if(is.null(polyline)) polyline <- attr(data, "encoded_column")
return(polyline)
}
#' @export
findEncodedColumn.default <- function(data, polyline) polyline
normaliseSfData <- function(data, geom) UseMethod("normaliseSfData")
#' @export
normaliseSfData.sf <- function(data, geom) {
enc <- googlePolylines::encode(data)
data <- normaliseSfData(enc, geom)
return(data)
}
#' @export
normaliseSfData.sfencoded <- function(data, geom) {
idx <- googlePolylines::geometryRow(data, geom)
return(data[idx, names(data), drop = F])
}
#' @export
normaliseSfData.default <- function(data, geom) data
normalise_sf <- function(sf) UseMethod("normalise_sf")
#' @export
normalise_sf.sf <- function(sf) googlePolylines::encode(sf)
#' @export
normalise_sf.sfencoded <- function(sf) sf
#' @export
normalise_sf.default <- function(sf) stop("Expecting an sf or sfencoded object to add_sf")