encode: Encode

Description Usage Arguments Details Value Note See Also Examples

View source: R/Encode.R

Description

Encodes coordinates into an encoded polyline.

Usage

1
2
3
4
5
6
7
encode(obj, ...)

## S3 method for class 'sf'
encode(obj, strip = FALSE, ...)

## S3 method for class 'data.frame'
encode(obj, lon = NULL, lat = NULL, byrow = FALSE, ...)

Arguments

obj

either an sf object or data.frame

...

other parameters passed to methods

strip

logical indicating if sf attributes should be stripped. Useful if you want to reduce the size even further, but you will lose the spatial attributes associated with the sf object

lon

vector of longitudes

lat

vector of latitudes

byrow

logical indicating if the encoding should be done for each row

Details

The function assumes Google Web Mercator projection (WSG 84 / EPSG:3857 / EPSG:900913) for inputs and outputs.

Will work with

Value

sfencoded object

Note

When an sfencoded object is colulmn-subset using `[` and the encoded column is retained, the attributes of the column will remain. This is different behaviour to standard subsetting of data.frames, where all attributes are dropped by default. See examples.

When encoding an sf object, only the XY dimensions will be used, the Z or M (3D and/or Measure) dimensions are dropped.

See Also

encodeCoordinates

Examples

 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
## data.frame
df <- data.frame(polygonId = c(1,1,1,1),
  lineId = c(1,1,1,1),
  lon = c(-80.190, -66.118, -64.757, -80.190),
  lat = c(26.774, 18.466, 32.321, 26.774))
  
## on a data.frame, it will attemp to find the lon & lat columns
encode(df)

## use byrow = TRUE to convert each row individually
encode(df, byrow = TRUE)


## Not run: 

## sf objects
library(sf)
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"))

encoded <- encode(nc)

## view attributes
attributes(encoded) 

## view attributes of subset object
attributes(encoded[, c("AREA", "PERIMETER", "geometry")])

## view attributes without encoded column
attributes(encoded[, c("AREA", "PERIMETER")])

## strip attributes
encodedLite <- encode(nc, strip = TRUE)

attributes(encodedLite)

## view attributes of subset lite object
attributes(encodedLite[, c("AREA", "PERIMETER", "geometry")])

## view attributes without encoded column
attributes(encodedLite[, c("AREA", "PERIMETER")])

## End(Not run)

googlePolylines documentation built on Dec. 15, 2020, 5:25 p.m.