## 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)
if (FALSE) {
## 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")])
}
Run the code above in your browser using DataLab