Skip to content

Instantly share code, notes, and snippets.

@elipousson
Last active October 11, 2024 16:57
Show Gist options
  • Select an option

  • Save elipousson/34519783401ca88d613d77e3edcca0ea to your computer and use it in GitHub Desktop.

Select an option

Save elipousson/34519783401ca88d613d77e3edcca0ea to your computer and use it in GitHub Desktop.
library(tictoc)
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
# pak::pkg_install('geoarrow/[email protected]')
# https://github.com/geoarrow/geoarrow-r/issues/28
library(geoarrow)

tf_parquet <- tempfile(fileext = ".parquet")
tf_gpkg <- tempfile(fileext = ".gpkg")

nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source 
#>   `/Users/elipousson/Library/R/arm64/4.4/library/sf/shape/nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27

sf_obj <- rep(list(nc), 1000) |> 
  purrr::list_rbind() |> 
  sf::st_as_sf()

tic()
st_write(sf_obj, tf_gpkg)
#> Writing layer `fileac263a294a7a' to data source 
#>   `/var/folders/3f/50m42dx1333_dfqb5772j6_40000gn/T//RtmprWrCzd/fileac263a294a7a.gpkg' using driver `GPKG'
#> Writing 100000 features with 14 fields and geometry type Multi Polygon.
toc()
#> 1.778 sec elapsed

tic()
# Read from GeoPackage
sf_gpkg_obj <- st_read(tf_gpkg)
#> Reading layer `fileac263a294a7a' from data source 
#>   `/private/var/folders/3f/50m42dx1333_dfqb5772j6_40000gn/T/RtmprWrCzd/fileac263a294a7a.gpkg' 
#>   using driver `GPKG'
#> Simple feature collection with 100000 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
toc()
#> 1.333 sec elapsed

tic()
# Write to parquet
geoarrow::write_geoparquet(sf_obj, tf_parquet)
toc()
#> 0.183 sec elapsed

tic()
# Read from parquet
sf_parquet_obj <- geoarrow::read_geoparquet_sf(tf_parquet)
toc()
#> 0.228 sec elapsed

Created on 2024-10-11 with reprex v2.1.1

library(tictoc)
library(sf)
# pak::pkg_install('geoarrow/[email protected]')
# https://github.com/geoarrow/geoarrow-r/issues/28
library(geoarrow)
tf_parquet <- tempfile(fileext = ".parquet")
tf_gpkg <- tempfile(fileext = ".gpkg")
nc <- st_read(system.file("shape/nc.shp", package="sf"))
sf_obj <- rep(list(nc), 1000) |>
purrr::list_rbind() |>
sf::st_as_sf()
tic()
st_write(sf_obj, tf_gpkg)
toc()
tic()
# Read from GeoPackage
sf_gpkg_obj <- st_read(tf_gpkg)
toc()
tic()
# Write to parquet
geoarrow::write_geoparquet(sf_obj, tf_parquet)
toc()
tic()
# Read from parquet
sf_parquet_obj <- geoarrow::read_geoparquet_sf(tf_parquet)
toc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment