#' Reproject coordinates to longlat
#'
#' Reprojects coordinates to tbe preferred coordinate system of Google Maps.
#' Removes all NA, but keep row index number for reference.
#'
#' @param df data frame with coordinates
#' @param x a vector of x - coordinates
#' @param y a vector of y - coordinates
#' @param crs coordinate system (before reproject)
#' @return A data frame with coordinates in Google Maps preferred format
#' @examples
#' reproj(x = 317105, y = 6776765, crs = "+proj=utm +zone=32N +datum=WGS84")
reproj <- function(x, y, crs){
library(dplyr)
df <- data.frame(x = x, y = y)
df <- df %>%
mutate(id = 1:n()) %>%
filter(!is.na(x), !is.na(y))
df <- sp::SpatialPoints(df, proj4string = sp::CRS(crs))
df <- sp::spTransform(df, sp::CRS("+proj=longlat +datum=WGS84"))
df <- data.frame(df@coords)
return(df)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.