reading geojson with readOGR

Viewed 2360

I am attempting to load some ggvis mapping code via this git: https://github.com/hrbrmstr/ggvis-maps

The code is returning errors on line 27 in the server file:

Warning: Error in ogrInfo: Cannot open data source
Stack trace (innermost first):
41: ogrInfo
40: withCallingHandlers
39: suppressMessages
38: readOGR
37: server [\ggvis-maps-master/server.R#27]
 1: runApp
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = 
use_iconv,  : 
Cannot open data source

I've used path.expand and a few other solutions I found, nothing has worked so far.

2 Answers

This error can come up if you recently installed GDAL which is the program that the readOGR function is calling. GDAL 2.2.0 introduced an API change to how it reads GeoJSON files. You can check your GDAL version by running gdalinfo --version in terminal.

If this is the case, you can adjust this part of your code from

maine <- readOGR(dsn="/data/maine.geojson", layer="OGRGeoJSON")

to

maine <- readOGR(dsn="/data/maine.geojson", layer="maine")

Then I suspect it will work.

Related