-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Description
Hello
I'm slowly working through various analyses and trying to convert from an sp
-centric approach to an sf
-centric approach. For the most part, so far so good.
One step I can't quite figure out how to replicate converting an sf
data.frame with an sfc_POINT
geometry column into a data.frame with separate x
and y
columns.
Here's how I would have done it via sp
library(tidyverse)
library(argosfilter) #needed for the example seal data
library(sp)
data(seal)
seal_sp <- seal
coordinates(seal_sp) <- ~ lon + lat
proj4string(seal_sp) <- CRS("+init=epsg:4326")
head(seal_sp)
as.data.frame(seal_sp) %>% head()
and here's my best attempt via sf
library(tidyverse)
library(argosfilter)
library(sf)
data(seal)
seal_sf <- st_as_sf(seal, coords = c("lon","lat")) %>%
st_set_crs(4326)
seal_coords <- unlist(st_geometry(seal_sf)) %>%
matrix(ncol=2,byrow=TRUE) %>%
as_tibble() %>%
setNames(c("lon","lat"))
bind_cols(seal_sf,seal_coords) %>% head()
Is there a better (simpler) approach I'm not seeing?
Metadata
Metadata
Assignees
Labels
No labels