encode {googlePolylines} | R Documentation |
Encode
Description
Encodes coordinates into an encoded polyline.
Usage
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 |
... |
other parameters passed to methods |
strip |
logical indicating if |
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
sf
andsfc
objects directlydata.frames
- It will attempt to find lat & lon coordinates, or you can explicitely define them using thelat
andlon
arguments
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
Examples
## 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)