df_geojson {geojsonsf} | R Documentation |
df to GeoJSON
Description
Converts data.frame objects to GeoJSON. Each row is considerd a POINT
Usage
df_geojson(
df,
lon,
lat,
z = NULL,
m = NULL,
atomise = FALSE,
simplify = TRUE,
digits = NULL,
factors_as_string = TRUE
)
Arguments
df |
data.frame |
lon |
column of |
lat |
column of |
z |
column of |
m |
column of |
atomise |
logical indicating if the data.frame should be converted into a vector of GeoJSON objects |
simplify |
logical indicating if data.frame without property columns should simplify
( |
digits |
integer specifying the number of decimal places to round numerics.
numeric values are coorced using |
factors_as_string |
logical indicating if factors should be treated as strings. Defaults to TRUE. |
Value
vector of GeoJSON
Examples
df <- data.frame(lon = c(1:5, NA), lat = c(1:5, NA), id = 1:6, val = letters[1:6])
df_geojson( df, lon = "lon", lat = "lat")
df_geojson( df, lon = "lon", lat = "lat", atomise = TRUE)
df <- data.frame(lon = c(1:5, NA), lat = c(1:5, NA) )
df_geojson( df, lon = "lon", lat = "lat")
df_geojson( df, lon = "lon", lat = "lat", simplify = FALSE)
df <- data.frame(lon = c(1:5), lat = c(1:5), elevation = c(1:5) )
df_geojson( df, lon = "lon", lat = "lat", z = "elevation")
df_geojson( df, lon = "lon", lat = "lat", z = "elevation", simplify = FALSE)
df <- data.frame(lon = c(1:5), lat = c(1:5), elevation = c(1:5), id = 1:5 )
df_geojson( df, lon = "lon", lat = "lat", z = "elevation")
df_geojson( df, lon = "lon", lat = "lat", z = "elevation", atomise = TRUE)
## to sf objects
geo <- df_geojson( df, lon = "lon", lat = "lat", z = "elevation")
sf <- geojson_sf( geo )