geojsonsf (version 2.0.3)

sf_geojson: sf to GeoJSON

Description

Converts `sf` objects to GeoJSON

Usage

sf_geojson(
  sf,
  atomise = FALSE,
  simplify = TRUE,
  digits = NULL,
  factors_as_string = TRUE
)

Arguments

sf

simple feature object

atomise

logical indicating if the sf object should be converted into a vector of GeoJSON objects

simplify

logical indicating if sf objects without property columns should simplify (TRUE) into a vector of GeoJSON, or return a Featurecollection with empty property fields (FALSE). If atomise is TRUE this argument is ignored.

digits

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

factors_as_string

logical indicating if factors should be treated as strings. Defaults to TRUE.

Value

vector of GeoJSON

Examples

Run this code
# NOT RUN {
library(sf)
sf <- sf::st_sf(geometry = sf::st_sfc(list(sf::st_point(c(0,0)), sf::st_point(c(1,1)))))
sf$id <- 1:2
sf_geojson(sf)
sf_geojson(sf, atomise = T)

ls <- st_linestring(rbind(c(0,0),c(1,1),c(2,1)))
mls <- st_multilinestring(list(rbind(c(2,2),c(1,3)), rbind(c(0,0),c(1,1),c(2,1))))
sfc <- st_sfc(ls,mls)
sf <- st_sf(sfc)
sf_geojson( sf )
sf_geojson( sf, simplify = FALSE )

# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace