Skip to content

Performance: import of many points is much faster in sp than in sf #700

@pbaylis

Description

@pbaylis

I'd like to import many points as quickly as possible. It was taking longer than expected in sf, so I tried sp and was surprised to find that it was much quicker. I'm not sure if this is issue-appropriate, but perhaps this issue is unique to me? I'm running OS X, sf 0.6.0.

library(sf)
library(sp)

N <- 1000000

df <- data.frame(lng = runif(N, -120, -100), 
                 lat = runif(N, 30, 48))

tic <- Sys.time()
df_sf <- st_as_sf(df, coords = c("lng", "lat"), crs = "+proj=longlat +datum=WGS84")
print(Sys.time() - tic)
# Time difference of 22.33289 secs

tic <- Sys.time()
coordinates(df) <- ~lng+lat
proj4string(df) <- "+proj=longlat +datum=WGS84"
print(Sys.time() - tic)
# Time difference of 0.8412709 secs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions