topoJSON
and geoJSON
files are know very common for drawing maps on the internet. Is it possible to import them in R
to draw choropleth maps?
Asked
Active
Viewed 9,599 times
19

Carl Witthoft
- 20,573
- 9
- 43
- 73

PAC
- 5,178
- 8
- 38
- 62
-
Have you tried the `rJSON` package? – Carl Witthoft Jun 12 '14 at 11:57
-
@vrajs5 Please use `code markdown` only for code, not for parts of sentences like "choropleth maps". – S.L. Barth is on codidact.com Jun 12 '14 at 12:10
1 Answers
26
Get the rgdal
package installed. Then if:
library(rgdal)
> "GeoJSON" %in% ogrDrivers()$name
[1] TRUE
then you can do something like:
> map = readOGR("foo.json", "OGRGeoJSON")
> plot(map)
But you need GeoJSON support in your ogrDrivers
list.
-
Thanks. Do you know if its possible to add new formats such as topojson to the ogrDrivers list ? – PAC Jun 13 '14 at 09:59
-
1That's a two step process. For a brand new format, it has to be implemented in C or C++ as a "driver" for the underlying GDAL/OGR library. Secondly it has to be compiled into the GDAL/OGR library binary on your system. There is a topojson driver from GDAL 1.11 (according to wikipedia). If you dont see that then you need to upgrade some things on your machine. – Spacedman Jun 13 '14 at 10:09