Skip to content

Instantly share code, notes, and snippets.

@batpigandme
Last active March 5, 2020 12:38
Show Gist options
  • Save batpigandme/55b1fb595c9507917fd843ffa6d643ea to your computer and use it in GitHub Desktop.
Save batpigandme/55b1fb595c9507917fd843ffa6d643ea to your computer and use it in GitHub Desktop.
Playing w/ Kyle E. Walker's crssuggest package.
# {crssuggest} by Kyle E Walker
# Get appropriate CRS suggestions for your spatial data in R
# src: https://github.com/walkerke/crsuggest
# remotes::install_github("walkerke/crsuggest")
## Use case 1: Analyzing unprojected data
library(tigris)
library(sf)
options(tigris_class = "sf")
# get Montana landmrks
mt_landmarks <- landmarks("MT")
# try to add a buffer...can't w/out projected coordinate system
landmark_buf <- st_buffer(mt_landmarks, 1)
# find a suggested crs
library(crsuggest)
possible_crs <- suggest_crs(mt_landmarks)
# check 'em out and pick one
dplyr::glimpse(possible_crs)
# project the landmarks
landmarks_projected <- st_transform(mt_landmarks, 2818)
# units are meters, so make the buffer 10000
buffer_1km <- st_buffer(landmarks_projected, 1000)
# plot the buffered landmarks
plot(buffer_1km)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment