19

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?

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
PAC
  • 5,178
  • 8
  • 38
  • 62

1 Answers1

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.

marbel
  • 7,560
  • 6
  • 49
  • 68
Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • 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
  • 1
    That'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