In {sf}
you can find the
sf_project()
function, which is used to reproject points by
the PROJ library directly (bypassing GDAL), which is a faster
alternative to st_transform()
.
library("sf")
n = 500000
df = data.frame(x = rnorm(n), y = rnorm(n))
pts = st_as_sf(df, coords = c("x", "y"), crs = "EPSG:4326")
system.time({
x = st_transform(pts, crs = "EPSG:3857")
})
## user system elapsed
## 1.57 0.06 1.65
system.time({
y = sf_project(from = "EPSG:4326", to = "EPSG:3857", pts = st_coordinates(pts))
y = st_as_sf(as.data.frame(y), crs = "EPSG:3857", coords = 1:2)
})
## user system elapsed
## 0.19 0.00 0.19
identical(x, y)
## [1] TRUE