[R-sig-Geo] GeoJSON errors when reading/writing with rgdal

Roger Bivand Roger.Bivand at nhh.no
Mon Jul 28 20:52:54 CEST 2014


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:

> As a followup to this, I downgraded to GDAL 1.10.1 (released 2013/08/26)
> and I still get a file creation error, although instead of 'GDAL Error 3:
> Cannot open file', I get 'Creation of output file failed'.
>
> as before, ogr2ogr, still works as expected when reading/writing GeoJSON
> files.
>
> I also realized I was clear in my previous post that I am running OS X
> 10.9.4
>
> cheers
> Josh
>
>
> On Fri, Jul 25, 2014 at 9:17 AM, Josh London <josh.london at noaa.gov> wrote:
>
>> Hello
>>
>> I am trying to track down the source of an error that has crept up on me
>> in the last 3-4 months. I was suspicious the issues was related to the
>> release of GDAL 1.11 in April, but it has taken me a while to confirm.
>>
>> Essentially, any time use readOGR(), writeOGR() or ogrInfo() on a GeoJSON
>> file, I get 'GDAL Error 3: Cannot open file'.
>>
>> The following code reliably reproduces the error for me:
>>
>>> library(rgdal)
>>>
>>> library(maptools)
>>> nc <-
>> readShapePoly(system.file("shapes/sids.shp",package="maptools")[1],
>> proj4string=CRS("+proj=longlat +datum=NAD27"))
>>>
>>> writeOGR(nc, 'nc.geojson','nc', driver='GeoJSON')
>>
>> I confirmed the "GeoJSON" drivers are installed and available with
>>
>>> "GeoJSON" %in% ogrDrivers()$name
>>> [1] TRUE
>>
>> and, I also confirmed that ogr2ogr can read/write GeoJSON outside of R, so
>> the issue seems to only impact rgdal.
>>
>> My GDAL libraries are all built from Homebrew and then rgdal is built from
>> source against these libraries. I have the following versions:
>>
>>> rgdal: version: 0.8-16, (SVN revision 498)
>>> GDAL 1.11.0, released 2014/04/16
>>> Path to GDAL shared files: /usr/local/Cellar/gdal/1.11.0/share/gdal
>>> PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
>>> Path to PROJ.4 shared files: (autodetected)
>>
>> As a final test, I installed rgdal via
>>
>>> install.packages("rgdal",type="mac.binary")
>>
>> With this version of the rgdal library, the code above works successfully.
>> The 'mac.binary' library appears to install with GDAL 1.9.2. So, I suspect
>> the issue is related to GDAL 1.11. I am fairly certain the code worked
>> without issue with GDAL 1.10, but I haven't had a chance to confirm this.
>>
>> A search for issues related to GeoJSON, GDAL and rgdal has not turned up
>> any useful clues, so I am suspicious the issue may be isolated to my
>> machine/setup. That said, a colleague with a similar setup is able to
>> reproduce the issues.
>>
>> Any assistance or guidance troubleshooting and resolving this issue would
>> be appreciated.
>>
>> cheers
>> josh
>>
>>> sessionInfo()
>>> R version 3.1.1 (2014-07-10)
>>> Platform: x86_64-apple-darwin13.1.0 (64-bit)
>>>
>>> locale:
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> other attached packages:
>>> [1] maptools_0.8-30 rgdal_0.8-16    sp_1.0-15
>>>
>>> loaded via a namespace (and not attached):
>>> [1] foreign_0.8-61  grid_3.1.1      lattice_0.20-29 tools_3.1.1
>>
>> --
>> *Josh M. London, PhD Wildlife BiologistPolar Ecosystems ProgramAFSC
>> National Marine Mammal LaboratoryNOAA Fisheries, Seattle, Washington*
>>
>
>
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list