[Gdal-dev] Connecting to PostGIS using rgdal

Mike Leahy mgleahy at golden.net
Tue May 29 19:28:14 EDT 2007


Hello,

I am trying to see if I can access a table from PostGIS using rgdal in
the R statistics program.  I've been able to read information from
shapefiles, as the example below demonstrates.  However, whenever I try
to read from a PG connection, I get a message saying it cannot open the
file (also in my output below).  I'm on WinXP, running R-2.5.0, rgdal
0.5-9 installed from CRAN, and I have FWTools 1.3.1 installed.  Output
from ogrinfo (from FWTools) reports information from the same PG
connection/dataset I'm trying to access using rgdal without any trouble.

I'm wondering what step I've missed in the setup of R, rgdal, or
FWTools/GDAL.  I have added the FWTools bin folder to my Path
environment variable, as well as added GDAL_DATA, but that doesn't seem
to help.  Is there anything I'm likely to have missed?  I checked the
output from ogrDrivers(), and it looks like PostgreSQL isn't included -
so would this mean that I have to compile rgdal myself?  If so, are
there instructions for this?

Thanks in advance for any help,
Mike

===========================================

> ogrInfo("d:/data/canada","popplace")
Driver: ESRI Shapefile number of rows 497
Number of fields: 18
         name type length typeName
1        AREA    2     12     Real
2   PERIMETER    2     12     Real
3   POPPLACE_    2     11     Real
4  POPPLACE_I    2     15     Real
5  UNIQUE_KEY    4      5   String
6        NAME    4     50   String
7      NAME_E    4     50   String
8      NAME_F    4     50   String
9  UNIQUE_K_1    4      5   String
10 UNIQUE_K_2    4      5   String
11   REG_CODE    0      2  Integer
12      NTS50    4      7   String
13        LAT    4      7   String
14       LONG    4      7   String
15   SGC_CODE    0      7  Integer
16    CAPITAL    0      3  Integer
17  POP_RANGE    0      3  Integer
18       MSID    0      9  Integer

> readOGR("PG: host=127.0.0.1 dbname=rgdaltest user=postgres
port=5432","pop")
Error in ogrInfo(dsn = dsn, layer = layer) :
        Cannot open file

> ogrDrivers()
             name write
1          AVCBin FALSE
2             CSV  TRUE
3             DGN  TRUE
4  ESRI Shapefile  TRUE
5             GML  TRUE
6             KML  TRUE
7    MapInfo File  TRUE
8          Memory  TRUE
9             REC FALSE
10            S57  TRUE
11           SDTS FALSE
12          TIGER  TRUE
13        UK .NTF FALSE
14            VRT FALSE






More information about the Gdal-dev mailing list