Skip to content

Instantly share code, notes, and snippets.

@rCarto
Created April 29, 2020 08:05
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 rCarto/d84ac851f6e65d0109b8b0f758772a6f to your computer and use it in GitHub Desktop.
Save rCarto/d84ac851f6e65d0109b8b0f758772a6f to your computer and use it in GitHub Desktop.
library(sf)
nc = st_read(system.file("shape/nc.shp", package="sf"))
nc <- st_transform(nc, 32119)
# regular grid 512096 polygons
grid <- st_make_grid(x = nc, cellsize = 500)
t0 <- Sys.time()
plot(st_geometry(nc))
plot(grid, add = TRUE)
# end of the second plot
t1 <- Sys.time()
# actual display in RStudio Plots window
t2 <- Sys.time()
# t2 - t0
# ~ 58 secs
t3 <- Sys.time()
png("test.png")
plot(st_geometry(nc))
plot(grid, add = TRUE)
dev.off()
t4 <- Sys.time()
# t4 - t3
# ~ 23 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment