Skip to content
Prev 21488 / 29559 Next

WriteOGR to GeoJSON loses CRS

On Tue, 12 Aug 2014, Philip Greenwood wrote:

            
Which is from February 2013, current is 0.8-16. More importantly, we don't 
know which version of GDAL is loaded when rgdal loads - messages are 
printed on-screen to tell you - nor do we know how you installed rgdal.

With GDAL 1.11.0, released 2014/04/16, I see:

dsn <- system.file("vectors", package = "rgdal")[1]
cities <- readOGR(dsn=dsn, layer="cities")
summary(cities)
#...
#[+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0]
#...
td <- tempdir()
writeOGR(cities, paste(td, ".geojson", sep=.Platform$file.sep),
  "OGRGeoJSON", driver="GeoJSON")
summary(readOGR(paste(td, ".geojson", sep=.Platform$file.sep),
  "OGRGeoJSON"))
#...
#[+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs]
#...

with the head of:

file.show(paste(td, ".geojson", sep=.Platform$file.sep))

"crs": { "type": "name", "properties": { "name": 
"urn:ogc:def:crs:OGC:1.3:CRS84" } },

where urn:ogc:def:crs:OGC:1.3:CRS84 is WGS 84 longitude-latitude on p. 18 
of https://portal.opengeospatial.org/files/?artifact_id=24045.

Not quite the same CRS, but a CRS is recorded. I think that your problem 
is related to the version of GDAL loaded into rgdal. The driver page on 
www.gdal.org relates to the current release and may include information 
for the development version. Your version seems to be old.
ogrinfo --formats, or equivalently ogrDrivers() in R with rgdal loaded.

Hope this clarifies,

Roger