# geojson to topojson
x <- '{"type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]}'
z <- geo2topo(x)
jsonlite::prettify(z)
if (FALSE) {
library(leaflet)
leaflet() %>%
addProviderTiles(provider = "Stamen.Terrain") %>%
addTopoJSON(z)
}
# geojson to topojson as a list
x <- list(
'{"type": "LineString", "coordinates": [ [100, 0], [101, 1] ]}',
'{"type": "LineString", "coordinates": [ [110, 0], [110, 1] ]}',
'{"type": "LineString", "coordinates": [ [120, 0], [121, 1] ]}'
)
geo2topo(x)
# change the object name created
x <- '{"type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]}'
geo2topo(x, object_name = "HelloWorld")
geo2topo(x, object_name = "4")
x <- list(
'{"type": "LineString", "coordinates": [ [100, 0], [101, 1] ]}',
'{"type": "LineString", "coordinates": [ [110, 0], [110, 1] ]}',
'{"type": "LineString", "coordinates": [ [120, 0], [121, 1] ]}'
)
geo2topo(x, "HelloWorld")
geo2topo(x, c("A", "B", "C"))
# 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