Skip to content
Prev 21390 / 29559 Next

GeoJSON errors when reading/writing with rgdal

Without access to your system, it is very difficult to advise. However, 
the behaviour of this driver under Linux and GDAL 1.11.0 is:

library(rgdal)
library(maptools)
nc <- readShapePoly(system.file("shapes/sids.shp",
  package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
td <- tempdir()
writeOGR(nc, paste(td, '.geojson', sep="/"), 'nc', driver='GeoJSON')
list.files(td, all.files=TRUE)
ogrListLayers(paste(td, ".geojson", sep="/"))
ogrInfo(paste(td, ".geojson", sep="/"), "OGRGeoJSON")
writeOGR(nc, paste(td, 'ncGeoJson', sep="/"), 'nc', driver='GeoJSON')
ogrListLayers(paste(td, "ncGeoJson", sep="/"))
ogrInfo(paste(td, "ncGeoJson", sep="/"), "OGRGeoJSON")

that is that the dsn is an arbitrary file name (may have a leading or 
trailing dot, but no dot anywhere else). The layer is always "OGRGeoJSON" 
on arrival irrespective of the given layer name - this from:

http://www.gdal.org/drv_geojson.html

"A GeoJSON datasource is translated to single OGRLayer object with 
pre-defined name OGRGeoJSON"

Hope this helps,

Roger
On Mon, 28 Jul 2014, Josh London wrote: