[R-sig-Geo] install rgdal to query postgis database

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 6 11:56:07 CEST 2013


On Sun, 4 Aug 2013, Duncan McPherson wrote:

> An update that may shed some light on my issue:
>
> Mysteriously it started working, I was able to import some spatial 
> tables form PostGIS to R, and plot them, and I was about to thank the 
> list and close the discussion, when it broke again. This was just after 
> I updated some packages, so, through luck I still had the old version of 
> rgdal and tried both.
>
> The old one works, the new one doesn't. But the difference is also in 
> the version of GDAL that is loaded. And, what is more confusing, is that 
> once I have loaded the old version of rgdal, which has found the new 
> version of GDAL, loading the new version of rgdal again also finds this 
> new version of GDAL and works (see the session details below). However, 
> my original problem was with the old version of rgdal and new version of 
> GDAL, that now works.
>
> Now I'm thoroughly confused. But here is a question:
>
> Is there a way of controlling where rgdal looks for GDAL? And for other 
> users, is it worth flagging this as an issue with rgdal, or is it some 
> quirk of my system?

Your system. If you have multiple GDAL installed and install rgdal from 
source, you may see the rgdal configure script choosing one gdal-config, 
building using the path values it returns, but find another GDAL 
installation at run time on loading, if it is earlier in the search path 
for dylibs. There is a check that the GDAL_VERSION_MAJOR, 
GDAL_VERSION_MINOR values agree for the build phase and the run time, but 
if they do agree, it cannot distinguish between one GDAL with the driver 
you need, and another without it. You can check for the presence of the 
driver with ogrDrivers().

Roger

>
> Thanks again,
>
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] tools_3.0.1
>> dsn="PG:dbname=health_england user=postgres"
>> ogrListLayers(dsn)
> Error: could not find function "ogrListLayers" #obviously
>> library("rgdal", lib.loc="/Library/Frameworks/R.framework/Versions/3.0/Resources/library")    #The NEW version, that fails
> Loading required package: sp
> rgdal: version: 0.8-10, (SVN revision 478)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
> Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/gdal
> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
> Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/proj
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] rgdal_0.8-10 sp_1.0-11
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.1      lattice_0.20-15 tools_3.0.1
>> ogrListLayers(dsn)
> Error in ogrListLayers(dsn) : Cannot open data source
>> detach("package:rgdal", unload=TRUE)
> Warning messages:
> 1: In FUN(X[[2L]], ...) :
>  Created a package name, ‘2013-08-04 21:51:37’, when none found
> 2: In FUN(X[[2L]], ...) :
>  Created a package name, ‘2013-08-04 21:51:37’, when none found
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] sp_1.0-11
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.1      lattice_0.20-15 tools_3.0.1
>> library("rgdal", lib.loc="/Users/duncan/Library/R/3.0/library")    #The OLD version, that works
> rgdal: version: 0.8-8, (SVN revision 463)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24
> Path to GDAL shared files:
> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
> Path to PROJ.4 shared files: (autodetected)
>> sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] rgdal_0.8-8 sp_1.0-11
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.1      lattice_0.20-15 tools_3.0.1
>> ogrListLayers(dsn)
> [1] … [list of layers]
>> detach("package:rgdal", unload=TRUE)
> Warning messages:
> 1: In FUN(X[[2L]], ...) :
>  Created a package name, ‘2013-08-04 22:06:10’, when none found
> 2: In FUN(X[[2L]], ...) :
>  Created a package name, ‘2013-08-04 22:06:10’, when none found
>> library("rgdal", lib.loc="/Library/Frameworks/R.framework/Versions/3.0/Resources/library")	#The NEW version again, now it works
> rgdal: version: 0.8-10, (SVN revision 478)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24
> Path to GDAL shared files:
> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
> Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/proj
>> ogrListLayers(dsn)
> [1] …[list of layers]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

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


More information about the R-sig-Geo mailing list