SNAPverse R package: snappoly

This post introduces the snappoly R package, a data package in the SNAPverse R package ecosystem. It contains a number of convenient SpatialPolygonsDataFrame objects sourced from shapefiles commonly used at SNAP. This is the first R package member of the SNAPverse introduced here and is one of the simplest. It is a data package, but is best thought of as providing auxiliary data rather than SNAP data end products. Access to and analysis of common SNAP data sets will be topics of later posts on other SNAPverse packages. The purpose of snappoly is to offer convenient access to common spatial polygons map layers used across various SNAP projects.

Available maps

There are eight available maps in the current version of the package:

  • alaska: State of Alaska.
  • canada: Canadian provinces.
  • ecoreg: Alaska ecological regions (ecoregions).
  • aklcc: Alaska Landscape Conservation Cooperative.
  • lcc: Alaska and Canada Landscape Conservation Cooperative.
  • cavm: Circumpolar Arctic Vegetation (Alaska).
  • fmz: Alaska Fire Service fire management zones.
  • tpa: Terrestrial protected areas.

Installation

You can install snappoly from github with:

# install.packages('devtools')
devtools::install_github("leonawicz/snappoly")

Basic example

In the example below, the raster package is unnecessary, but it is loaded because it offers a compact print method. Data sets from the above list can immediately be referred to directly once snappoly is loaded. To access documentation on the package from R, use ?snappoly, or for a data set for example, ?fmz.

Display some metadata associated with the one of the SpatialPolygonsDataFrame objects by entering its name at the R console. Here is the result for aklcc.

library(raster)  # compact print method
library(snappoly)
aklcc
#> class       : SpatialPolygonsDataFrame 
#> features    : 5 
#> extent      : -738286.4, 1491802, 517942.6, 2378458  (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 
#> variables   : 6
#> names       :           LCC_Name,    Acres_, Shape_Leng, Shape_Le_1,   Shape_Area, Unit.ID 
#> min values  :         Arctic LCC,  93457602,   11965337,   11941320, 1.353159e+12,       1 
#> max values  : Western Alaska LCC, 728185322,  133482546,  133482546, 3.782110e+11,       5

While there are different ways to plot the map, the simplest is plot. Assign some interesting colors for the five polygon features in aklcc first.

clrs <- c("#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F")
plot(aklcc, col = clrs, border = NA)

Via snappoly, these auxiliary map layers can easily merge into existing analysis workflows in R just by loading the package and referring to their names, or without even explicitly loading the package if you are explicit with the package namespace instead, e.g., by calling snappoly::aklcc. The maps are immediately available in your R session to be used for subsetting other data sets, computing region-specific statistics, or even just providing a quick, convenient graphic of the spatial domain you may we working with for documentation purposes.

Like any of the SNAPverse R packages, even if you are not using other R packages and functions that are part of the broader SNAPverse for analyzing your SNAP data set, snappoly can be leveraged directly and independently as needed. There is no requirement to couple it in your workflow with other SNAPverse packages that pertain to statistical analysis. The SNAPverse R package ecosystem offers the independence to select only the pieces you need and inject them into you analysis chain where applicable.

Notes

Cleaning and curating is kept to a minimum for this package. The data sets come from various sources so they are not intended to share conventions regarding attribute names or other properties. However, shapefiles were reprojected as needed in order for the collection to share the NAD83 Alaska Albers Equal Area Conic projection in common:

+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs

Reference

Complete package reference and function documentation

This entry was posted by Matt Leonawicz.
%d bloggers like this: