Skip to content

Instantly share code, notes, and snippets.

@smach
Created February 21, 2021 14:53
Show Gist options
  • Save smach/1201646acc9f86fdcc4c770b699a8966 to your computer and use it in GitHub Desktop.
Save smach/1201646acc9f86fdcc4c770b699a8966 to your computer and use it in GitHub Desktop.
RStudio code snippet for combining smaller polygons (precincts) into larger polygons (City Council Districts)
snippet mygis_dt_merge_districts_2_precincts
${1:my_geography} <- as.data.table(${1:my_geography})
${2:my_new_geography} <- fram2[, .(geometry = st_union(geometry)), by = ${3:larger_district}]
${2:my_new_geography} <- sf::st_sf(${2:my_new_geography})
# test plot
# ggplot(${2:my_new_geography}, aes(geometry=geometry)) +
# geom_sf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment