[R-sig-Geo] readOGR and PostGIS: "Error getting field 0"

Mathieu Basille basille at ase-research.org
Fri Nov 30 16:15:44 CET 2012


Dear R users,

I have a working PostGIS database that I routinely access through R, using 
readOGR or readGDAL. I have this point layer, however, that I can't read in R:

 > ctrdcoast <- readOGR("PG:dbname=florida host=localhost user=pguser", 
layer = "gis.world_ctrdcoast")
OGR data source with driver: PostgreSQL
Source: "PG:dbname=florida host=localhost user=pguser", layer: 
"gis.world_ctrdcoast"
with 35398 features and 2 fields
Error in readOGR("PG:dbname=florida host=localhost user=pguser", layer = 
"gis.world_ctrdcoast") :
   Error getting field 0

The layer is basically a table with just 2 fields: geom (a point feature) 
and gid (a serial primary key). I can export this layer without any problem 
using ogr2ogr, and the layer looks fine to me (it displays fine in QGIS):

ogr2ogr -f "ESRI Shapefile" ctrd.shp PG:"dbname=florida host=localhost 
user=pguser" "gis.world_ctrdcoast"

Any idea where this is going wrong? Thanks in advance for any suggestion.
Mathieu.


 > sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C 
LC_TIME=fr_FR.UTF-8
  [4] LC_COLLATE=fr_FR.UTF-8     LC_MONETARY=fr_FR.UTF-8 
LC_MESSAGES=fr_FR.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C                  LC_ADDRESS=C 

[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 
LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] raster_2.0-31 rgdal_0.7-22  sp_1.0-2

loaded via a namespace (and not attached):
[1] compiler_2.15.1 grid_2.15.1     lattice_0.20-6  tools_2.15.1


# SELECT PostGIS_Full_Version();
 
     postgis_full_version 

-------------------------------------------------------------------------
  POSTGIS="2.1.0SVN r10597" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 
September 2009" GDAL="GDAL 2.0dev, released 2011/12/29" LIBXML="2.8.0" 
LIBJSON="UNKNOWN" TOPOLOGY RASTER



-- 

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard



More information about the R-sig-Geo mailing list