Skip to content

Instantly share code, notes, and snippets.

@cybernar
Last active April 10, 2020 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybernar/749cdd5e92f4734e2c3f5cffd1f9feb5 to your computer and use it in GitHub Desktop.
Save cybernar/749cdd5e92f4734e2c3f5cffd1f9feb5 to your computer and use it in GitHub Desktop.
sf snippets
# genere sf à partir de data.frame
df2sf <- function(df, x_col, y_col, epsg) {
geomdef <- paste0("POINT(", df[[x_col]], " ", df[[y_col]],")")
sfc <- st_as_sfc(geomdef, epsg)
st_geometry(df) <- sfc
df
}
# autre solution
sf_points <- st_as_sf(df, crs=4326, coords=c("longitude", "latitude"), remove=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment