[R-sig-Geo] multiple geometry columns in a table reading from PostGIS to rgdal

Duncan McPherson duncan at mcpherson.org.uk
Sun Feb 8 09:28:28 CET 2015


Dear list

Has the syntax changed for specifying which geometry column to import in rgdal when built against GDAL 1.11 when there are multiple geometry columns in a single table? RFC41 (http://trac.osgeo.org/gdal/wiki/rfc41_multiple_geometry_fields) seems to say something about this, but I’m not sure what the implications are for rgdal.

I have recently updated rgdal and gdal and previously functioning code now doesn’t. With the old version, rgdal built from source linked to GDAL=1.9.2 this would work (it also works with rgdal built against GDAL=1.10) :

dsn=“PG:dbname=[dbname] user=[username]"
sha<- readOGR(dsn, “table(geom_col_1)")
# Layer gets imported

But with rgdal built against GDAL 1.11.1:

dsn=“PG:dbname=[dbname] user=[username]"
sha<- readOGR(dsn, "table(geom_col_1)")
# Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
#                      Layer not found

I build rgdal from source on mac osx. Some more details of my setup:
 
library(rgdal)
# Loading required package: sp
# rgdal: version: 0.9-1, (SVN revision 518)
# Geospatial Data Abstraction Library extensions to R successfully loaded
# Loaded GDAL runtime: GDAL 1.11.1, released 2014/09/24
# Path to GDAL shared files: /Library/Frameworks/GDAL.framework/Versions/1.11/Resources/gdal
# Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
# Path to PROJ.4 shared files: (autodetected)
ogrListLayers(dsn)
# [1] "sha_fe”      //and the other tables with geometry columns
# attr(,"driver")
# [1] "PostgreSQL"
# attr(,"nlayers”)
# [1] 20

You can see that the table is listed but not the columns, and there are 20 layers. If I go to the terminal I get

DMcPiMac:~ duncan$ ogrinfo -ro PG:’dbname=[dbname] user=[username]'
INFO: Open of `PG:dbname=[dbname] user=[username]'
      using driver `PostgreSQL' successful.
1: sha_fe (Multi Polygon, Multi Polygon)
… upto 20

And the geometries are there:

DMcPiMac:~ duncan$ ogrinfo -ro -al -so PG:’dbname=[dbname] user=[username]’
...
Layer name: sha_fe
Geometry (the_geom): Multi Polygon
Geometry (geom_low): Multi Polygon
...

Which suggests that there are two MultiPolygon columns in that table, and that there are considered to be 20 layers. 

If I clean and build rgdal against GDAL 1.9 or 1.10 the old behaviour returns:

> ogrListLayers(dsn)
[1] "sha_fe(geom_low)"  "sha_fe(the_geom)”
# and the rest of the layers
attr(,"driver")
[1] "PostgreSQL"
attr(,"nlayers")
[1] 24

Many thanks for help with this.

Duncan


More information about the R-sig-Geo mailing list