CRAN_Status_Badge Project Status: Active - The project has reached a stable, usable state and is being actively developed.

This is the development area for the package rpostgis, which provides additional functions to the RPostgreSQL package to interface R with a PostGIS-enabled database, as well as convenient wrappers to common PostgreSQL queries.

All functions require a database connection object (from the RPostgreSQL package) to a PostgreSQL database, e.g.:


You can import a PostgreSQL data table with a PostGIS GEOMETRY data type as a sp-type Spatial* or Spatial*DataFrame (points, lines or polygons) object into R:

my_spdf<-pgGetGeom(conn, name=c("schema","my_geom_table"), geom = "my_geom_column")

The function pgInsert allows sp-type Spatial* and Spatial*DataFrames (in addition to regular R data.frame) objects to be written (inserted) into new or existing PostgreSQL tables:

pgInsert(conn, name=c("schema","my_new_geom_table"), data.obj=my_spdf, geom = "my_new_geom_column", = "gid")

General-purpose database functions such as dbAddKey and dbIndex provide PostgreSQL table management:

## Add primary key
dbAddKey(conn, name = c("schema", "my_new_geom_table"), colname = "gid", type = "primary")
## Add index to GEOMETRY column
dbIndex(conn, name = c("schema", "my_new_geom_table"), colname = "my_new_geom_column", method = "gist")

Package functions which are primarily for general database procedures have the prefix (db), while PostGIS-enabled database specific fuctions have the prefix (pg).

Installation of the released versions

You can install the latest released version from CRAN:


You can use update.packages() to update to the latest CRAN version.

Installation of the development version

A stable development version of the package will be available on the project's Github page, which may be ahead the CRAN version (check versions to verify). To install it, use the devtools package from Hadley Wickham:


For the latest (possibly unstable) development version, use:


Getting started

For a list of documented functions, use library(help = "rpostgis") or see the Reference manual.

Try the rpostgis package in your browser

Any scripts or data that you put into this service are public.

rpostgis documentation built on Dec. 11, 2017, 1:06 a.m.