[R-sig-Geo] memory allocation problem with small PostGIS-layer in readOGR()

Roger Bivand Roger.Bivand at nhh.no
Tue Apr 12 15:39:57 CEST 2011

On Tue, 12 Apr 2011, Tom Gottfried wrote:

> Dear list,
> since some upgrades of R-packages and GDAL (I'm sorry I can not exactly 
> reproduce which) I got memory allocation problems reading a relatively small 
> PostGIS layer (type POLYGON with 21 polygons):
>> library(rgdal)
> Loading required package: sp
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.8.0, released 2011/01/12
> Path to GDAL shared files:
> Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009
> Path to PROJ.4 shared files: (autodetected)
>> readOGR("PG:dbname=myDB", "layer(the_geom)")
> Error: cannot allocate vector of size 13.9 Gb

Since this has to be debugged on your system, please first use ogr2ogr to 
convert it to another format - this will test the PostGIS driver. You are 
on Linux, so should have ogr2ogr installed. If (unlikely) there are 
problems with the driver, you may need to check how PostgreSQL, PostGIS, 
and their dependencies were installed, then GDAL and its dependencies.

Otherwise, this must be in readOGR() somewhere, so do debug(readOGR) and 
run the same command step-by-step. Start by doing debug(ogrInfo) and 
ogrInfo("PG:dbname=myDB", "layer(the_geom)"), because unless you have set 
verbose=FALSE and not reported it (unlikely), ogrInfo() called within 
readOGR() should have reported the DSN and layer names, the driver name, 
etc., before the error if the error occurred later Also look at 
traceback() after the error before trying debug() - this feels like 
ogrInfo() having trouble.


>> sessionInfo()
> R version 2.12.2 Patched (2011-03-18 r55401)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> locale:
> [1] LC_CTYPE=en_US       LC_NUMERIC=C         LC_TIME=en_US
> [7] LC_PAPER=en_US       LC_NAME=C            LC_ADDRESS=C
> attached base packages:
> [1] stats     graphics  grDevices utils     methods   base
> other attached packages:
> [1] rgdal_0.6-33 sp_0.9-79    RODBC_1.3-2
> loaded via a namespace (and not attached):
> [1] grid_2.12.2     lattice_0.19-17
> Any help is appreciated!
> Thanks,
> Tom

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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