sp_to_geojson: Convert a spatial data object to a GeoJSON string

Description Usage Arguments Value Note Examples

View source: R/sp_to_geojson.R

Description

Convert an R spatial polygons object to a GeoJSON string that can be used in geojson_layer. The spatial classes are provided by the sp package.

Usage

1

Arguments

sp

A SpatialPolygonsDataFrame.

Value

A string containing unparsed GeoJSON.

Note

This function will write a GeoJSON file to the temporary directory created by R, but this file will be deleted when the R session ends.

Examples

1
2
3
4
5
6
7
8
if(require(USAboundaries)) {
  # Boundaries of the United States of America in 1800
  us <- us_boundaries(as.Date("1800-01-01"))
  us_geojson <- sp_to_geojson(us)

  cartographer(region = "United States") %>%
    geojson_layer(data = us_geojson, clickable = TRUE, label = "US 1800")
}

ropensci/cartographer documentation built on May 16, 2018, 6:58 a.m.