Last active
April 30, 2020 00:54
-
-
Save MilesMcBain/57e722b75e58778bdc42f94260f6fb15 to your computer and use it in GitHub Desktop.
lon_lat_to_point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##' Create an sf POINT column from long and lat columns | |
##' | |
##' This is a vectorised function that takes 2 columns of longitude and latitude | |
##' as arguments and returns a simple features geometry collection column in the | |
##' EPSG 4326 coordinate reference system (lon, lat). | |
##' | |
##' @title lon_lat_to_point | |
##' @param lon a numeric column of longitudes | |
##' @param lat a numeric column of latitudes | |
##' @return a simple features collection column of POINT geometries representing the lon/lat pairs. | |
##' @author Miles McBain | |
##' @export | |
lon_lat_to_point <- function(lon, lat) { | |
purrr::map2( | |
lon, | |
lat, | |
~ sf::st_point(c(.x, .y)) | |
) %>% | |
sf::st_sfc(crs = 4326) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Miles.
I found this gist while exploring your hex-binning example and thought you might be interested in a
sfheaders
version of this code