R: df to GeoJSON

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 `df` containing the longitude data
`lat` | column of `df` containing the latitude data
`z` | column of `df` containing the Z attribute of the GeoJSON
`m` | column of `df` containing the M attribute of the GeoJSON. If supplied, you must also supply `z`
`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 (`TRUE`) into a vector of GeoJSON, or (`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

    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 )

[Package geojsonsf version 2.0.1 Index]