Home

Awesome

<!-- badges: start -->

R-CMD-check tic-db Coverage Status License CRAN cran checks Downloads status

<!-- badges: end -->

Simple Features for R

<a href="https://gist.github.com/edzer/f461a3a95570c4ab7edf3125c2f19d20"><img align="right" src="https://user-images.githubusercontent.com/520851/34887433-ce1d130e-f7c6-11e7-83fc-d60ad4fae6bd.gif" /></a>

A package that provides simple features access for R.

Blogs, linksCheatsheetInstallingContributingAcknowledgmentHow to cite

Package sf:

<a href="https://gist.github.com/edzer/442d74a5775abcd5068cf3e73b23687b"><img align="left" src="https://user-images.githubusercontent.com/520851/50280460-e35c1880-044c-11e9-9ed7-cc46754e49db.jpg" /></a>

(Illustration (c) 2018 by <a href="https://twitter.com/allison_horst/status/1071456081308614656">Allison Horst</a>)

Books, journal articles, blogs, presentations, vignettes, sp-sf wiki

Cheatsheet

CC 4.0 BY Ryan Garnett

<a href="https://github.com/rstudio/cheatsheets/blob/main/sf.pdf"><img src="https://raw.githubusercontent.com/rstudio/cheatsheets/main/pngs/sf.png" /></a>

Installing

Install either from CRAN with:

install.packages("sf")

This will install binary packages on Windows and MacOS, unless you configured R such that it tries to install source packages; in that case, see below.

Install development versions from GitHub with:

library(remotes)
install_github("r-spatial/sf")

Windows

Installing sf from source works under Windows when Rtools is installed.

MacOS

MacOS users are strongly encouraged to install the sf binary packages from CRAN, unless they are familiar with compilers, linking, C++ source code, and homebrew.

The easiest way to install gdal is using Homebrew. Recent versions of Homebrew include a full-featured up-to-date gdal formula, which installs proj and gdal at the same time:

brew install pkg-config
brew install gdal

Once gdal is installed, you will be able to install sf package from source in R. With the current version of proj on homebrew, installation requires additional configuration:

install.packages("sf", type = "source", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")

Or the development version:

library(remotes)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")

If you are using sf and rgdal together, it is necessary to install rgdal from source using this configuration:

install.packages("rgdal", type = "source", configure.args = c("--with-proj-lib=$(brew --prefix)/lib/", "--with-proj-include=$(brew --prefix)/include/"))

Alternatively, these instructions explain how to install gdal using kyngchaos frameworks.

For Mac OS 11 Big Sur source install instruction, see here

Linux

For Unix-alikes, GDAL (>= 2.0.1), GEOS (>= 3.4.0) and Proj.4 (>= 4.8.0) are required.

Ubuntu

Dependencies for recent versions of Ubuntu (18.04 and later) are available in the official repositories; you can install them with:

apt-get -y update && apt-get install -y  libudunits2-dev libgdal-dev libgeos-dev libproj-dev

However, to get more up-to-date versions of dependencies such as GDAL, we recommend adding the ubuntugis-unstable PPA to the package repositories and installing them as follows:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev libsqlite0-dev

Adding this PPA is required for installing sf on older versions of Ubuntu (e.g. Xenial).

Another option, for advanced users, is to install dependencies from source; see e.g. an older Travis config file for hints.

Fedora

The following command installs all required dependencies:

sudo dnf install gdal-devel proj-devel geos-devel sqlite-devel udunits2-devel

Arch

Get gdal, proj, geos and podofo from the main repos, and udunits from the AUR:

pacman -S gdal proj geos arrow podofo
yay/pacaur/yaourt/whatever -S udunits

renv or conda

There are several reports that sf fails to install as a source package when R is used with renv, or when R is installed in a conda environment. If you experience this, please do not raise an issue here, but

Other

To install on Debian, the rocker geospatial Dockerfiles may be helpful. Ubuntu Dockerfiles are found here.

Multiple GDAL, GEOS and/or PROJ versions on your system

If you use dynamic linking (installation from source) and have multiple versions of these libraries installed (e.g. one from ubuntugis-unstable, another installed from source in /usr/local/lib) then this will in general not work, even when setting LD_LIBRARY_PATH manually. See here for the reason why.

lwgeom

Functions and methods that require liblwgeom, including ellipsoidal (not spherical or Euclidean) metrics (area, distances), are provide by and used from lwgeom, which is also on CRAN.

Contributing

How to cite

Package sf can be cited as:

Acknowledgment

This project gratefully acknowledges financial support from the

<a href="https://r-consortium.org/all-projects/2016-group-1.html#simple-features-for-r"> <img src="https://r-consortium.org/images/RConsortium_Horizontal_Pantone.webp" width="300"> </a> <!-- <img src="http://pebesma.staff.ifgi.de/RConsortium_Horizontal_Pantone.png" width="300"> -->