Converts data.frame objects to GeoJSON. Each row is considerd a POINT
df_geojson(
df,
lon,
lat,
z = NULL,
m = NULL,
atomise = FALSE,
simplify = TRUE,
digits = NULL,
factors_as_string = TRUE
)data.frame
column of df containing the longitude data
column of df containing the latitude data
column of df containing the Z attribute of the GeoJSON
column of df containing the M attribute of the GeoJSON.
If supplied, you must also supply z
logical indicating if the data.frame should be converted into a vector of GeoJSON objects
logical indicating if data.frame without property columns should simplify
(TRUE) into a vector of GeoJSON, or (FALSE). If atomise is TRUE
this argument is ignored.
integer specifying the number of decimal places to round numerics.
numeric values are coorced using as.integer, which may round-down the value you supply.
Default is NULL - no rounding
logical indicating if factors should be treated as strings. Defaults to TRUE.
vector of GeoJSON
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")
#> {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1,"val":"a"},"geometry":{"type":"Point","coordinates":[1.0,1.0]}},{"type":"Feature","properties":{"id":2,"val":"b"},"geometry":{"type":"Point","coordinates":[2.0,2.0]}},{"type":"Feature","properties":{"id":3,"val":"c"},"geometry":{"type":"Point","coordinates":[3.0,3.0]}},{"type":"Feature","properties":{"id":4,"val":"d"},"geometry":{"type":"Point","coordinates":[4.0,4.0]}},{"type":"Feature","properties":{"id":5,"val":"e"},"geometry":{"type":"Point","coordinates":[5.0,5.0]}},{"type":"Feature","properties":{"id":6,"val":"f"},"geometry":null}]}
df_geojson( df, lon = "lon", lat = "lat", atomise = TRUE)
#> {"type":"Feature","properties":{"id":1,"val":"a"},"geometry":{"type":"Point","coordinates":[1.0,1.0]}}
#> {"type":"Feature","properties":{"id":2,"val":"b"},"geometry":{"type":"Point","coordinates":[2.0,2.0]}}
#> {"type":"Feature","properties":{"id":3,"val":"c"},"geometry":{"type":"Point","coordinates":[3.0,3.0]}}
#> {"type":"Feature","properties":{"id":4,"val":"d"},"geometry":{"type":"Point","coordinates":[4.0,4.0]}}
#> {"type":"Feature","properties":{"id":5,"val":"e"},"geometry":{"type":"Point","coordinates":[5.0,5.0]}}
#> {"type":"Feature","properties":{"id":6,"val":"f"},"geometry":null}
df <- data.frame(lon = c(1:5, NA), lat = c(1:5, NA) )
df_geojson( df, lon = "lon", lat = "lat")
#> {"type":"Point","coordinates":[1.0,1.0]}
#> {"type":"Point","coordinates":[2.0,2.0]}
#> {"type":"Point","coordinates":[3.0,3.0]}
#> {"type":"Point","coordinates":[4.0,4.0]}
#> {"type":"Point","coordinates":[5.0,5.0]}
#> null
df_geojson( df, lon = "lon", lat = "lat", simplify = FALSE)
#> {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[1.0,1.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[2.0,2.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[3.0,3.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[4.0,4.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[5.0,5.0]}},{"type":"Feature","properties":{},"geometry":null}]}
df <- data.frame(lon = c(1:5), lat = c(1:5), elevation = c(1:5) )
df_geojson( df, lon = "lon", lat = "lat", z = "elevation")
#> {"type":"Point","coordinates":[1.0,1.0,1.0]}
#> {"type":"Point","coordinates":[2.0,2.0,2.0]}
#> {"type":"Point","coordinates":[3.0,3.0,3.0]}
#> {"type":"Point","coordinates":[4.0,4.0,4.0]}
#> {"type":"Point","coordinates":[5.0,5.0,5.0]}
df_geojson( df, lon = "lon", lat = "lat", z = "elevation", simplify = FALSE)
#> {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[1.0,1.0,1.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[2.0,2.0,2.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[3.0,3.0,3.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[4.0,4.0,4.0]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[5.0,5.0,5.0]}}]}
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")
#> {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":1},"geometry":{"type":"Point","coordinates":[1.0,1.0,1.0]}},{"type":"Feature","properties":{"id":2},"geometry":{"type":"Point","coordinates":[2.0,2.0,2.0]}},{"type":"Feature","properties":{"id":3},"geometry":{"type":"Point","coordinates":[3.0,3.0,3.0]}},{"type":"Feature","properties":{"id":4},"geometry":{"type":"Point","coordinates":[4.0,4.0,4.0]}},{"type":"Feature","properties":{"id":5},"geometry":{"type":"Point","coordinates":[5.0,5.0,5.0]}}]}
df_geojson( df, lon = "lon", lat = "lat", z = "elevation", atomise = TRUE)
#> {"type":"Feature","properties":{"id":1},"geometry":{"type":"Point","coordinates":[1.0,1.0,1.0]}}
#> {"type":"Feature","properties":{"id":2},"geometry":{"type":"Point","coordinates":[2.0,2.0,2.0]}}
#> {"type":"Feature","properties":{"id":3},"geometry":{"type":"Point","coordinates":[3.0,3.0,3.0]}}
#> {"type":"Feature","properties":{"id":4},"geometry":{"type":"Point","coordinates":[4.0,4.0,4.0]}}
#> {"type":"Feature","properties":{"id":5},"geometry":{"type":"Point","coordinates":[5.0,5.0,5.0]}}
## to sf objects
geo <- df_geojson( df, lon = "lon", lat = "lat", z = "elevation")
sf <- geojson_sf( geo )