Roger

Thanks for the response. I finally had some additional time to pursue
troubleshooting this and, it turns out, your comment that "the dsn is an
arbitrary file name (may have a leading or trailing dot, but no dot
anywhere else)." was the key bit of information I needed.

In my example code, I specified 'nc.geojson' as the output file name. I
know this (providing a .geojson extension) worked previously (approx. 6
months ago) and there are at least a few examples on the internet that
specify a filename with a '.geojson' extension (e.g. how to create a
geojson in r <http://www.jose-gonzalez.org/create-geojson-r/#.U-EE54BdWv0>, r,
geojson and leaflet
<http://stackoverflow.com/questions/17181339/r-geojson-and-leaflet>). But,
the current behavior is just as you described. As long as I do not specify
an output filename with a dot in the middle of the name, all works just as
expected.

This also seems to be an issue with just the GeoJSON driver as

writeOGR(nc,'nc.sql','nc',driver='SQLite')

seems to work without issue.
I also confirmed that the following code works:

library(rgdal)
library(maptools)
nc <- readShapePoly(system.file("shapes/sids.shp",
 package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
td <- tempdir()
setwd(td)
writeOGR(nc, 'nc_esri', 'nc', driver='ESRI Shapefile')
list.files(td, all.files=TRUE)
system("ogr2ogr -f GeoJSON -t_srs crs:84 nc_ogr.geojson nc_esri")
list.files(td,all.files=TRUE)

This seems to demonstrate that GDAL/OGR can handle dots within the file
name.
So, I take from this that the requirement for a 'leading or trailing dot,
but no dot anywhere else' is a R/rgdal specification. Is that correct? Is
that expected? A result of a recent change?

I'm trying to be as thorough as possible here, documenting the issue and
observed behavior, in case others run into the same situation. My
understanding of all the GDAL/OGR drivers and specifications, and how rgdal
interacts with each of them, is still somewhat limited. I'm not sure if the
observed behavior is expected or if this is a bug in rgdal ... or, if this
is still some artifact of my OS X/homebrew setup.

Thanks again for taking the time to read and respond to my original posts.

cheers
Josh


On Mon, Jul 28, 2014 at 11:52 AM, Roger Bivand <Roger.Bivand@nhh.no> wrote:

> 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@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@nhh.no
>
>


-- 
*Josh M. London, PhDWildlife BiologistPolar Ecosystems ProgramAFSC National
Marine Mammal LaboratoryNOAA Fisheries, Seattle, Washington*

	[[alternative HTML version deleted]]

