[R-sig-Geo] Connection between R and PostGIS

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Mar 28 15:14:34 CEST 2012


see

http://wiki.intamap.org/index.php/PostGIS

(which, to my surprise, has been accessed nearly 30000 times).

On 03/28/2012 03:01 PM, Johannes Signer wrote:
> Dear All,
> 
> I have been trying to connect R and PostGIS. My approach so far is:
> 
> ## load libraries
> library(RODBC)
> library(rgeos)
> 
> ## Connect to db
> con <- odbcConnect("gisdb")
> 
> ## query
> sql <- "SELECT ST_AsText(the_geom) from gis_data.gadm2 where name_2='Berlin'"
> 
> ## execute query
> d <- readWKT(sqlQuery(con, sql, stringsAsFactors=F)[1,1])
> 
> This works well for small polygons.
> 
> My questions are:
> 
> 1.) Is there a more straightforward approach to access data stored
> PostGIS from R?
> 2.) While my approach described above worked ok for small polygons, it
> failed for larger ones. My guess is that the strings to be stored are
> long. Does anyone has a workaround for that?
> 
> Thanks in advance for any comments
> Johannes
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list