snaplocs is as package in the functional sector of the SNAPverse. Like most packages, it contains some form of data. However, it is not a data sector package. Data packages are those that contain a large enough amount of data to warrant a standalone package so that functional packages remain small. This is not one of those packages. Unlike snappoly and snapgrid it does not contain any maps. snaplocs contains point location data in a single data frame. There are 3,914 locations in all, spread across Alaska and western Canada. Compared to SNAPverse data packages, this is quite small.

While snaplocs is nevertheless still typically treated as a data package for basic access to the locs data set, the package does provide a collection of functions for working with the data. This vignette provides example usage of several functions.

Point location data

Print a summary of the data.

library(snaplocs)
locs
#> # A tibble: 3,914 x 4
#>    Location      Group    lon   lat
#>    <chr>         <fct>  <dbl> <dbl>
#>  1 Adak Station  Alaska -177.  51.9
#>  2 Afognak       Alaska -153.  58.0
#>  3 Akhiok        Alaska -154.  56.9
#>  4 Akiachak      Alaska -161.  60.9
#>  5 Akiak         Alaska -161.  60.9
#>  6 Akutan        Alaska -166.  54.1
#>  7 Alakanuk      Alaska -165.  62.7
#>  8 Alatna        Alaska -153.  66.6
#>  9 Aleknagik     Alaska -159.  59.3
#> 10 Aleut Village Alaska -153.  58.0
#> # ... with 3,904 more rows

Metadata helpers

There are some basic helper functions that grab metadata associated with point locations of interest.

x <- "Fairbanks"
get_state(x)
#> [1] "Alaska"
get_country(x)
#> [1] "United States"
get_coords(x)
#> # A tibble: 1 x 2
#>     lon   lat
#>   <dbl> <dbl>
#> 1 -148.  64.8

These calls also take vectors and get_coords with keep_cols = TRUE retains all columns of locs.

x <- c("Fairbanks", "Calgary")
get_state(x)
#> [1] "Alaska"  "Alberta"
get_country(x)
#> [1] "United States" "Canada"
get_coords(x)
#> # A tibble: 2 x 2
#>     lon   lat
#>   <dbl> <dbl>
#> 1 -148.  64.8
#> 2 -114.  51.0
get_coords(x, keep_cols = TRUE)
#> # A tibble: 2 x 4
#>   Location  Group     lon   lat
#>   <chr>     <fct>   <dbl> <dbl>
#> 1 Fairbanks Alaska  -148.  64.8
#> 2 Calgary   Alberta -114.  51.0

Typically a user is interested in all communities, or all those in a particular province. Less commonly, a user may have a specific location name and query the table as demonstrated above. Not only must the name be exact, but the results returned may not be unique. These helper functions that take specific locations as input are only intended to provide rough convenience. For example, Galena is not unique.

x <- c("Galena")
get_state(x)
#> [1] "Alaska"
get_country(x)
#> [1] "United States"
get_coords(x)
#> # A tibble: 1 x 2
#>     lon   lat
#>   <dbl> <dbl>
#> 1 -157.  64.7
get_coords(x, keep_cols = TRUE)
#> # A tibble: 1 x 4
#>   Location Group    lon   lat
#>   <chr>    <fct>  <dbl> <dbl>
#> 1 Galena   Alaska -157.  64.7

An additional group argument can be passed to any of these functions to protect against this possibility. group may be a vector.

grp <- "Alaska"
get_state(x, group = grp)
#> [1] "Alaska"
get_country(x, grp)
#> [1] "United States"
get_coords(x, grp)
#> # A tibble: 1 x 2
#>     lon   lat
#>   <dbl> <dbl>
#> 1 -157.  64.7
get_coords(x, grp, keep_cols = TRUE)
#> # A tibble: 1 x 4
#>   Location Group    lon   lat
#>   <chr>    <fct>  <dbl> <dbl>
#> 1 Galena   Alaska -157.  64.7

Spatial reprojection

Alaska- and western Canada-centric projects at SNAP often use data in a NAD83 Alaska Albers equal area conic projection. To quickly convert a 2-column matrix or data frame of WGS84 lon/lat coordinates to a 2-column matrix in this projection, do the following:

wgs2ak(get_coords(x))
#>              x       y
#> [1,] -139348.5 1644384
head(wgs2ak(locs[3:4]))
#>                x         y
#> [1,] -1537921.57  472626.5
#> [2,]    72613.04  890268.7
#> [3,]   -10323.86  770992.1
#> [4,]  -400865.13 1236452.4
#> [5,]  -389171.90 1235473.0
#> [6,]  -766686.42  526437.1

More functions will be added in the next package revision.