Learn R Programming

⚠️There's a newer version (1.6.0) of this package.Take me there.

rpostgis

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.:

drv<-dbDriver("PostgreSQL")
conn<-dbConnect(drv,dbname='db_name',host='localhost',port='5432',user='postgres',password='PASSWORD')

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", new.id = "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 (1.0) from CRAN:

install.packages("rpostgis")

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. To install it, use the devtools package from Hadley Wickham:

library(devtools)
install_github("mablab/rpostgis")

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

install_github("mablab/rpostgis",ref="develop")

Getting started

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

Copy Link

Version

Install

install.packages('rpostgis')

Monthly Downloads

503

Version

1.0.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

David Bucklin

Last Published

August 20th, 2016

Functions in rpostgis (1.0.0)

dbIndex

Create an index.
dbAsDate

Converts to timestamp.
dbSchema

Check and create schema.
dbColumn

Add or remove a column.
dbTableInfo

Get information about table columns.
dbComment

Comment table/view/schema.
dbVacuum

Vacuum.
dbDrop

Drop table/view/schema.
dbTableNameFix

Format input for database schema/table names.
dbAddKey

Add key.
pgMakePts

Add a POINT or LINESTRING geometry field.
pgGetPts

Load a PostGIS point geometry from a PostgreSQL table/view into R.
pgGetLines

Load a PostGIS linestring geometry from a PostgreSQL table/view into R.
pgInsertizeGeom

Format R data objects for insert into a PostgreSQL table.
pgGetRast

Load raster from PostGIS database.
pgGetBoundary

Retrieve bounding envelope of geometries or rasters.
pgGetPolys

Load a PostGIS polygon geometry from a PostgreSQL table/view into R.
pgInsert

Inserts data into a PostgreSQL table.
pgListGeom

List geometries.
pgGetGeom

Load a PostGIS geometry from a PostgreSQL table/view into R.
pgSRID

Find (or create) PostGIS SRID based on CRS object.
pgPostGIS

Check and create PostGIS extension.
rpostgis

R interface to a PostGIS database.