#' A function to convert sf objects into data frames including lon/lat columns
#'
#'
#' @param x an sf object
#' @examples
#' @export
geometry_to_lonlat <- function(x) {
if (any(sf::st_geometry_type(x) != "POINT")) {
stop("Selecting non-points isn't implemented.")
}
coord_df <- sf::st_transform(x, sf::st_crs("+proj=longlat +datum=WGS84")) %>%
sf::st_coordinates() %>%
dplyr::as_tibble() %>%
dplyr::select(X, Y) %>%
dplyr::rename(lon = X, lat = Y)
out <- sf::st_set_geometry(x, NULL) %>%
dplyr::bind_cols(coord_df)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.