RPostgreSQL
package to interface R with a PostGIS-enabled
database, as well as convenient wrappers to common PostgreSQL
queries. For a list of documented functions, use
library(help = "rpostgis")
.
library(rpostgis)
con <- dbConnect("PostgreSQL", dbname =
For example, this could be:
con <- dbConnect("PostgreSQL", dbname = "rpostgis", host = "localhost", user = "postgres", password = "postgres")
The next step typically involves checking if PostGIS was installed on the working database, and if not try to install it:
pgPostGIS(con)
The function should return TRUE
for all pg-
functions to work.
Finally, at the end of an interactive session, the connection to the database should be closed:
dbDisconnect(con)