This walkthrough covers some of the same concepts from Jamie Montgomery’s guide on spatial data in R, which is how I first learned to use the sf
package. It will cover some of the same concepts and also some different ones.
As her guide does, I will start with background from the sf vignette:
"Simple features or simple feature access refers to a formal standard (ISO 19125-1:2004) that describes how objects in the real world can be represented in computers, with emphasis on the spatial geometry of these objects. It also describes how such objects can be stored in and retrieved from databases, and which geometrical operations should be defined for them.
"The standard is widely implemented in spatial databases (such as PostGIS), commercial GIS (e.g., ESRI ArcGIS) and forms the vector data basis for libraries such as GDAL. A subset of simple features forms the GeoJSON standard.
"R has well-supported classes for storing spatial data (sp) and interfacing to the above mentioned environments (rgdal, rgeos), but has so far lacked a complete implementation of simple features, making conversions at times convoluted, inefficient or incomplete. The package sf tries to fill this gap, and aims at succeeding sp in the long term."
We will read in a shapefile of wildfire perimeters from the US Geological Survey (USGS) Monitoring Trends in Burn Severity (MTBS) dataset. The data contained in this repo are for California wildfires from 2010 through 2016.
Taking a look at the data:
## Simple feature collection with 6 features and 7 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -117.1918 ymin: 32.54717 xmax: -116.2191 ymax: 33.01739
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
## # A tibble: 6 x 8
## Fire_ID Fire_Name Year StartMonth StartDay Fire_Type Acres
## <chr> <chr> <int> <int> <int> <chr> <dbl>
## 1 CA3260~ BORDER 6 2012 5 17 WF 5302
## 2 CA3260~ BORDER 3 2016 6 19 WF 7958
## 3 CA3264~ SHOCKEY 2012 9 23 WF 2667
## 4 CA3271~ OLD 2 2012 6 17 WF 1058
## 5 CA3289~ MONTE 2010 8 21 WF 1013
## 6 CA3300~ BERNARDO 2014 5 13 WF 1525
## # ... with 1 more variable: geometry <MULTIPOLYGON [°]>
An sf
object is similar to a dataframe except that it has an additional column, the geometry column, which contains a list of coordinates used to plot each polygon.
## [1] "sf" "tbl_df" "tbl" "data.frame"
Visualizing the data spatially using mapview
.