library(downloader)
library(sf)
library(data.table)
library(withr)
library(usmap)
library(RcensusPkg)
# Get the major places locations in the state of Kentucky
# Define a temporary, self deleting output folder for the downloaded shapefiles
output_dir <- withr::local_tempdir()
if(!dir.exists(output_dir)){
dir.create(output_dir)
}
# Get the fips code for the state
kentucky_fips <- usmap::fips(state = "kentucky")
# Create a filter expression to get select places
major_places_express <- expression(NAME %in% c(
"Bardstown",
"Bowling Green",
"Louisville",
"Versailles",
"Owensboro",
"Frankfort",
"Elizabethtown",
"Danville"
))
# Get the sf object and the geometric locations of the selected places
kentucky_places_sf <- RcensusPkg::tiger_places_sf(
state = kentucky_fips,
express = major_places_express,
general = TRUE,
output_dir = output_dir,
delete_files = FALSE
)
Run the code above in your browser using DataLab