[R-sig-Geo] rgdal: Cannot open data source

Rainer Hurling rhurlin at gwdg.de
Thu Jul 16 09:12:57 CEST 2015

I am using GDAL 2.0.0 on FreeBSD and having trouble to get rgdal-1.0-4 
work correctly.

(1) The error looks like this:

ogrInfo("/home/rhurlin/SpatialData/world", "TM_WORLD_BORDERS-0.3")
Fehler in ogrInfo("/home/rhurlin/SpatialData/world", 
   Cannot open data source

Obviously, rgdal does not find the path and/or files, given as 
parameters to functions like ogrInfo(). This problem also exists with 
similar rgdal tools like for example ogrListLayers:

Fehler in ogrListLayers("/home/rhurlin/SpatialData/world") :
   Cannot open data source

(2) The library rgdal loads fine so far:

Lade nötiges Paket: sp
rgdal: version: 1.0-4, (SVN revision 548)
  Geospatial Data Abstraction Library extensions to R successfully loaded
  Loaded GDAL runtime: GDAL 2.0.0, released 2015/06/14
  Path to GDAL shared files: /usr/local/share/gdal
  Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
  Path to PROJ.4 shared files: (autodetected)
  Linking to sp version: 1.1-1

(3) On the shell, outside of R, gdal 2.0.0 gives the expected output:

ogrinfo -so "/home/rhurlin/SpatialData/world" "TM_WORLD_BORDERS-0.3"
INFO: Open of `/home/rhurlin/SpatialData/world'
       using driver `ESRI Shapefile' successful.

Layer name: TM_WORLD_BORDERS-0.3
Geometry: Polygon
Feature Count: 246
Extent: (-180.000000, -90.000000) - (180.000000, 83.623596)
Layer SRS WKT:
FIPS: String (2.0)
ISO2: String (2.0)
ISO3: String (3.0)
UN: Integer (3.0)
NAME: String (50.0)
AREA: Integer (7.0)
POP2005: Integer64 (10.0)
REGION: Integer (3.0)
SUBREGION: Integer (3.0)
LON: Real (8.3)
LAT: Real (7.3)

This leads me to the assumption, that the new rgdal-1.0_4 has some 
problem with path and/or file strings, at least on FreeBSD and at least 
for GDAL 2.0.0.

(4) I tried to get some insight with gdb, but my skills are far to small 
to get deeper. What I did:

- Run R with 'R -d gdb791'
- Load library(rgdal) within R
- Set 'bt ogrInfo' in gdb for src/ogrsource.cpp:l46
- Continue R, run the following command:

ogrInfo("/home/rhurlin/SpatialData/world", "TM_WORLD_BORDERS-0.3")

Breakpoint 1, ogrInfo (ogrsourcename=0x4b8cf458, Layer=0x4b8cf428) at 
46	    int nFIDs, nFields, iField, *nCount, pc=0;
(gdb) n
60	    installErrorHandler();
(gdb) n
62	    poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrsourcename, 
(gdb) n
63	    if(poDS==NULL){
(gdb) bt
#0  ogrInfo (ogrsourcename=0x4b8cf458, Layer=0x4b8cf428) at ogrsource.cpp:63
#1  0x0000000040adf576 in R_doDotCall (ofun=0x4bc14201 <ogrInfo(SEXP, 
SEXP)>, nargs=2,
     cargs=0x7fffffffc5e0, call=0x4aae9f78) at dotcode.c:573
#2  0x0000000040aed4a2 in do_dotcall (call=0x4aae9f78, op=0x46ceeb50, 
args=0x4ab53468, env=0x4ab400b0)
     at dotcode.c:1251
#3  0x0000000040b291c1 in Rf_eval (e=0x4aae9f78, rho=0x4ab400b0) at 
#4  0x0000000040b2dab3 in do_set (call=0x4aae6190, op=0x46cd71c8, 
args=0x4aae88b0, rho=0x4ab400b0)
     at eval.c:2106
#5  0x0000000040b28f71 in Rf_eval (e=0x4aae6190, rho=0x4ab400b0) at 
#6  0x0000000040b2c9a0 in do_begin (call=0x4aae00b0, op=0x46cd8778, 
args=0x4aae61c8, rho=0x4ab400b0)
     at eval.c:1716
#7  0x0000000040b28f71 in Rf_eval (e=0x4aae00b0, rho=0x4ab400b0) at 
#8  0x0000000040b2a256 in Rf_applyClosure (call=0x4aadc1c8, 
op=0x4aade238, arglist=0x4ab40318,
     rho=0x46f0a708, suppliedvars=0x46cd4f78) at eval.c:1039
#9  0x0000000040b29304 in Rf_eval (e=0x4aadc1c8, rho=0x46f0a708) at 
#10 0x0000000040b6ad2c in Rf_ReplIteration (rho=0x46f0a708, savestack=0, 
     state=0x7fffffffd580) at main.c:258
#11 0x0000000040b6aef0 in R_ReplConsole (rho=0x46f0a708, savestack=0, 
browselevel=0) at main.c:308
#12 0x0000000040b6c682 in run_Rmainloop () at main.c:1009
#13 0x0000000040b6c697 in Rf_mainloop () at main.c:1016
#14 0x0000000000400a5c in main (ac=1, av=0x7fffffffe658) at Rmain.c:29
(gdb) n
64	      uninstallErrorHandlerAndTriggerError();
65	      error("Cannot open data source");
(gdb) n
Fehler in ogrInfo("/home/rhurlin/SpatialData/world", 
   Cannot open data source
run_Rmainloop () at main.c:1008
1008	    R_GlobalContext = R_ToplevelContext = R_SessionContext = 
(gdb) n
1009	    R_ReplConsole(R_GlobalEnv, 0, 0);

Hope, my analysis it ok so far. From here on, I am lost and could really 
need some help. Please ask me, if you need more information or if I 
should try something.

Many thanks in advance.
Rainer Hurling

R Under development (unstable) (2015-07-14 r68652)
Platform: amd64-portbld-freebsd11.0 (64-bit)
Running under: FreeBSD xxx.xxx.xxx 11.0-CURRENT FreeBSD 11.0-CURRENT #0 
r285383: Sat Jul 11 10:39:33 CEST 2015 
xxx at xxx.xxx.xxx:/usr/obj/usr/src/sys/XXX  amd64
[1] C/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
other attached packages:
[1] rgdal_1.0-4 sp_1.1-1
loaded via a namespace (and not attached):
[1] grid_3.3.0      lattice_0.20-33

More information about the R-sig-Geo mailing list