Go to file
edzer e5bce2e972 closes #2429 2024-08-28 10:54:07 +02:00
.github add rhub 2024-04-12 09:33:54 +02:00
R closes #2429 2024-08-28 10:54:07 +02:00
demo Avoid && in stopifnot() conditions 2023-06-21 22:12:44 -07:00
inst add CPL_transform_bounds() 2024-05-06 22:58:23 +02:00
man closes #2415 2024-07-31 10:49:56 +02:00
pkgdown/favicon add favicons 2024-02-15 09:17:39 -05:00
src closes #2415 2024-07-31 10:49:56 +02:00
tests closes #2429 2024-08-28 10:54:07 +02:00
tools path fix 2020-04-30 20:27:09 -07:00
vignettes Update sf6.Rmd 2024-02-08 19:04:31 +01:00
.Rbuildignore Merge branch 'r-spatial:main' into doc-polish 2024-02-22 09:15:47 -05:00
.gitattributes Check out configure.ac with LF on Windows 2023-01-13 04:04:39 +01:00
.gitignore Rename test files to work better with usethis. (align them with R files) 2024-02-15 11:16:25 -05:00
CONDUCT.md address https://github.com/edzer/sfr/pull/166#issuecomment-271222433 2017-01-09 08:26:49 +01:00
DESCRIPTION closes #2429 2024-08-28 10:54:07 +02:00
LICENSE update 2024-01-08 12:06:17 +01:00
NAMESPACE closes #2415 2024-07-31 10:49:56 +02:00
NEWS.md closes #2429 2024-08-28 10:54:07 +02:00
PROPOSAL.md Update links with `urlchecker::url_update()` 2023-12-08 12:53:45 -05:00
README.md fix arch install example 2024-06-19 11:29:30 -03:00
_pkgdown.yml forgot url in _pkgdown.yml 2023-03-31 13:14:08 +02:00
cleanup release clean ups 2020-03-04 10:41:31 +01:00
codecov.yml shot in the dark 2018-10-01 11:07:24 +02:00
configure Fix cross-compiling 2023-11-21 20:44:39 +00:00
configure.ac Fix cross-compiling 2023-11-21 20:44:39 +00:00
sf.Rproj [.sfc and [<-.sfc can deal with matrix/array lists 2024-07-07 17:48:49 +02:00
tic.R see #2147 2023-04-14 17:46:47 +02:00
vignettes.awk switches of mapview example 2021-01-04 15:37:22 +01:00

README.md

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

Simple Features for R

A package that provides simple features access for R.

Blogs, linksCheatsheetInstallingContributingAcknowledgmentHow to cite

Package sf:

  • represents simple features as records in a data.frame or tibble with a geometry list-column
  • represents natively in R all 17 simple feature types for all dimensions (XY, XYZ, XYM, XYZM)
  • interfaces to GEOS for geometrical operations on projected coordinates, and (through R package s2) to s2geometry for geometrical operations on ellipsoidal coordinates
  • interfaces to GDAL, supporting all driver options, Date and POSIXct and list-columns
  • interfaces to PRØJ for coordinate reference system conversion and transformation
  • uses well-known-binary serialisations written in C++/Rcpp for fast I/O with GDAL and GEOS
  • reads from and writes to spatial databases such as PostGIS using DBI
  • is extended by
    • lwgeom for selected liblwgeom/PostGIS functions
    • stars for raster data, and raster or vector data cubes (spatial time series)
    • sfnetworks for geospatial network data

(Illustration (c) 2018 by Allison Horst)

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

Cheatsheet

CC 4.0 BY Ryan Garnett

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

  • try to sort this out with the renv developers or the conda maintainers, or
  • try to use binary installs of the sf package, e.g. from r2u, or the Posit package manager

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 Eucledian) metrics (area, distances), are provide by and used from lwgeom, which is also on CRAN.

Contributing

  • Contributions of all sorts are most welcome, issues and pull requests are the preferred ways of sharing them.
  • When contributing pull requests, please adhere to the package style (in package code use = rather than <-; don't change indentation; tab stops of 4 spaces are preferred)
  • This project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

How to cite

Package sf can be cited as:

Acknowledgment

This project gratefully acknowledges financial support from the