[R-sig-Geo] rgdal_1.1-1: dsn path string problems

Roger Bivand Roger.Bivand at nhh.no
Sun Nov 8 18:02:57 CET 2015


On Sun, 8 Nov 2015, Rainer Hurling wrote:

> Dear Roger, dear list,
>
> many thanks for the newest update 1.1-1 of package rgdal. It is really
> helpful.
>
> I am using rgdal with R-devel and GDAL 2.0.1, both on FreeBSD
> 11.0-CURRENT and Windows7. On both platforms, I have problems with path
> strings in dsn.
>
>
>
> (a) The minor problem is on Windows. While a dsn="C:/some/path" works
> fine, the same path with a slash at the end (dsn="C:/some/path/") fails.
>
> On most other software it is conventional to allow a closing slash.
> Wouldn't it be nice, if rgdal would be more tolerant about it?
>

R base::file.exists does include this in its help file: "However, 
directory names must not include a trailing backslash or slash on 
Windows".

so this isn't just rgdal. The dsn= argument for many drivers is a file 
name, not a directory; a work-around seems like overkill.

>
> Now my main problem:
> (b) On FreeBSD, for some time now, the dsn path can not be used anymore
> to check for existence of a file.
>
> I want to use writeOGR to overwrite an existing shapefile. I use
> something like dsn="/path/to/somewhere" and layer="layername".
>
> Within writeOGR(), R/ogr_write.R calls the C++ function
> 'ogrCheckExists'. ogrCheckExists is not able to return TRUE, if a
> shapefile already exists. Every time its result is FALSE:
>
> R/ogr_write.R
> 61:        ogrI <- .Call("ogrCheckExists", as.character(dsn),
> s.character(layer), PACKAGE = "rgdal")
> [1] FALSE
>
>
> As far, as I can see, 'ogrCheckExists' comes from src/ogrsource.cpp.
> Something must go wrong in that C++ file, at least for FreeBSD :(
>
> Unfortunalety, I have no skills how to debug such a C++ code within an R
> package ...
>

I do not have access to such a system. As a first step, does 
rgdal::ogrListLayers work correctly?

Beyond that, you'd need to insert Rprintf() statements into the C++ file 
to see whether the FALSE result comes from a failure to open the dsn with 
a known driver, or from the fact that such a layer is not found in that 
dsn.

Does using a different driver help? Does using the shapefile.shp as the 
dsn help (I think this works better in GDAL2)?

Hope this helps,

Roger

> Any help is really appreciated. Please tell me, if I could try and test
> something. My box has FreeBSD, R-devel, gcc-4.8.5, gdb-7.1.0 ...
>
> Greetings,
> Rainer Hurling
>
>

-- 
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