Learn R Programming

geojsonio (version 0.4.2)

geo2topo: GeoJSON to TopoJSON and back

Description

GeoJSON to TopoJSON and back

Usage

geo2topo(x)

topo2geo(x, ...)

Arguments

x

GeoJSON or TopoJSON as a character string, json, a file path, or url

...

for topo2geo args passed on to readOGR

Value

An object of class json, of either GeoJSON or TopoJSON

See Also

topojson_write, topojson_read

Examples

Run this code
# NOT RUN {
# geojson to topojson
x <- '{"type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]}'
z <- geo2topo(x)
jsonlite::prettify(z)
# }
# NOT RUN {
library(leaflet)
leaflet() %>% 
  addProviderTiles(provider = "Stamen.Terrain") %>% 
  addTopoJSON(z)
# }
# NOT RUN {
# topojson to geojson
w <- topo2geo(z)
jsonlite::prettify(w)

## larger examples
file <- system.file("examples", "us_states.topojson", package = "geojsonio")
topo2geo(file)
# }

Run the code above in your browser using DataLab