rpostgis: Linking R with a PostGIS Spatial Database

With the proliferation of sensors and the ease of data collection from online sources, large datasets have become the norm in many scientific disciplines, and efficient data storage, management, and retrival is imperative for large research projects. Relational databases provide a solution, but in order to be useful, must be able to be linked to analysis and visualization tools, such as R. Here, we present a package intended to facilitate integration of R with the open-source database software PostgreSQL, with a focus on its spatial extension, PostGIS. The package rpostgis (version 1.4.1) provides methods for spatial data handling (vector and raster) between PostGIS-enabled databases and R, methods for R “data.frame”s storage in PostgreSQL, and a set of convenient wrappers for common database procedures. We thus expect rpostgis to be useful for both (1) existing users of spatial data in R and/or PostGIS, and (2) R users who have yet to adopt relational databases for their projects.

David Bucklin , Mathieu Basille

Supplementary materials

Supplementary materials are available in addition to this article. It can be downloaded at RJ-2018-025.zip

CRAN packages used

rgdal, maptools, raster, RPostgreSQL, DBI, rpostgis, sp, rgeos, wkb, sf, rpostgisLT, adehabitatLT

CRAN Task Views implied by cited packages

Spatial, SpatioTemporal


Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".


For attribution, please cite this work as

Bucklin & Basille, "The R Journal: rpostgis: Linking R with a PostGIS Spatial Database", The R Journal, 2018

BibTeX citation

  author = {Bucklin, David and Basille, Mathieu},
  title = {The R Journal: rpostgis: Linking R with a PostGIS Spatial Database},
  journal = {The R Journal},
  year = {2018},
  note = {https://doi.org/10.32614/RJ-2018-025},
  doi = {10.32614/RJ-2018-025},
  volume = {10},
  issue = {1},
  issn = {2073-4859},
  pages = {251-268}