Skip to content

Instantly share code, notes, and snippets.

@paleolimbot
Created April 7, 2020 18:44
Show Gist options
  • Save paleolimbot/06e91204f5777ac65552f198bc149e13 to your computer and use it in GitHub Desktop.
Save paleolimbot/06e91204f5777ac65552f198bc149e13 to your computer and use it in GitHub Desktop.
library(sf)
library(geovctrs)
nc_sf <- read_sf(system.file("shape/nc.shp", package = "sf"))
nc_sfc <- st_geometry(nc_sf)
nc_geo <- geo_nc
nc_wkb <- geo_nc$geometry
nc_wkt <- as_geo_wkt(nc_wkb)
# bbox
bench::mark(
st_bbox(nc_sf),
st_bbox(nc_sfc),
geo_bbox(nc_sf),
geo_bbox(nc_sfc),
geo_bbox(nc_geo),
geo_bbox(nc_wkb),
geo_bbox(nc_wkt),
check = FALSE, relative = TRUE
)
@paleolimbot
Copy link
Author

library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(geovctrs)

nc_sf <- read_sf(system.file("shape/nc.shp", package = "sf"))
nc_sfc <- st_geometry(nc_sf)
nc_geo <- geo_nc
nc_wkb <- geo_nc$geometry
nc_wkt <- as_geo_wkt(nc_wkb)

# bbox
bench::mark(
  st_bbox(nc_sf),
  st_bbox(nc_sfc),
  geo_bbox(nc_sf),
  geo_bbox(nc_sfc),
  geo_bbox(nc_geo),
  geo_bbox(nc_wkb),
  geo_bbox(nc_wkt),
  check = FALSE, relative = TRUE
)
#> # A tibble: 7 x 6
#>   expression          min median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>        <dbl>  <dbl>     <dbl>     <dbl>    <dbl>
#> 1 st_bbox(nc_sf)     1.47   1.55    178.         Inf     4.36
#> 2 st_bbox(nc_sfc)    1      1       272.         NaN     4.43
#> 3 geo_bbox(nc_sf)  115.   117.        2.41       Inf     2.60
#> 4 geo_bbox(nc_sfc) 114.   116.        2.36       Inf     2.68
#> 5 geo_bbox(nc_geo)  80.5   80.8       3.42       Inf     3.12
#> 6 geo_bbox(nc_wkb)  73.3   76.5       3.56       Inf     3.12
#> 7 geo_bbox(nc_wkt) 284.   279.        1          Inf     1

Created on 2020-04-07 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment