sf
{#importing-vector-sf}Most vector data that you use in everyday GIS work are so called "simple features". Simple features are an open standard developed by the Open Geospatial Consortium (OGC). The most common feature types are displayed in figure \@ref(fig:sf-types).
knitr::include_graphics("images/sf-classes.png")
To handle these simple features in R
, we need the library sf
, and to import a vector dataset into R
, we can use the function read_sf
as in the example below.
library(sf) ARE_waedenswil <- read_sf("sample_data/ARE_waedenswil.shp") ARE_waedenswil
And you are done! The shapefile is now imported into your R
Session and you can start working with it. Much of the beauty in sf
comes from it's simplicity: As you see from importing the shapefile, it is very much like a data.frame
, a structure that you probably know very well. In fact, it is a data.frame, as you can see here:
is.data.frame(ARE_waedenswil)
sf
provides methods for various generics, e.g. you can use plot()
on the object for a simple visualisation. By default, using plot()
on an sf
object visualizes the geometry in small multiples, where each "facet" is colour coded based on a column in the dataset (see below). If you find this annoying (like I do), see chapter \@ref(chapter-staticmaps).
plot(ARE_waedenswil)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.