Skip to content

Instantly share code, notes, and snippets.

@NewGraphEnvironment
Last active November 6, 2023 15:57
Show Gist options
  • Save NewGraphEnvironment/9e20702275c63bf6f15304944a85d535 to your computer and use it in GitHub Desktop.
Save NewGraphEnvironment/9e20702275c63bf6f15304944a85d535 to your computer and use it in GitHub Desktop.
Extract coordinates from `sf` spatial object and add to object as columns
# asssumes UTMs. Column nmaes would be `lat` `long` if in Albers or WSG84
#option 1 - retains the sf object
sf_object %>%
mutate(
easting = sf::st_coordinates(.)[,1],
northing = sf::st_coordinates(.)[,2])
# option 2 - this changes from sf object to a dbl_df - not usually helpful
sf_object %>%
poisspatial::ps_sfc_to_coords(X = 'easting', Y = 'northing')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment