使用 st_read 在迭代 R 中导入大型 geojson

Using st_read to import large geojson in iterations R

我想在 R 中使用 st_read 将一个非常大的 geojson 导入到一个简单的特征对象中,但是从 geojson 转换为 sf 时硬件需求似乎很大。例如,导入用于为俄亥俄州 (https://github.com/Microsoft/USBuildingFootprints) 构建足迹的 Microsoft 数据是一个 1.2 GB 的 geojson,在转换时会占用超过 32 GB 的 RAM。它们是一种在函数中遍历 geojson 行的方法,因此我可以导入整个文件的一部分而不会耗尽所有 RAM,类似于 read.csv?

中的跳过行

使用 library(geojsonsf) 在我的 Mac 和 16gb RAM

上似乎没有问题
library(geojsonsf)
library(sf)

sf <- geojsonsf::geojson_sf("~/Downloads/Ohio.geojson")

sf
# Simple feature collection with 5449419 features and 0 fields
# geometry type:  POLYGON
# dimension:      XY
# bbox:           xmin: -84.82027 ymin: 38.40334 xmax: -80.51887 ymax: 41.97041
# epsg (SRID):    4326
# proj4string:    +proj=longlat +datum=WGS84 +no_defs
# First 10 features:
#   geometry
# 1  POLYGON ((-84.81222 39.9087...
# 2  POLYGON ((-84.80084 39.8882...
# 3  POLYGON ((-84.78565 39.8811...
# 4  POLYGON ((-84.7373 39.9014,...
# 5  POLYGON ((-84.73916 39.8980...
# 6  POLYGON ((-84.80422 39.8646...
# 7  POLYGON ((-84.80025 39.8592...
# 8  POLYGON ((-84.79336 39.8593...
# 9  POLYGON ((-84.79268 39.8604...
# 10 POLYGON ((-84.80194 39.8639...