@@ -204,8 +204,33 @@ process_cpl_read_ogr = function(x, quiet = FALSE, ..., check_ring_dir = FALSE,
204204 x
205205}
206206
207- process_cpl_read_ogr_stream = function (x , ... ) {
208- x
207+ process_cpl_read_ogr_stream = function (x , crs , num_features , as_tibble = FALSE , ... ) {
208+ is_geometry_column = vapply(
209+ x $ get_schema()$ children ,
210+ function (s ) identical(s $ metadata [[" ARROW:extension:name" ]], " ogc.wkb" ),
211+ logical (1 )
212+ )
213+
214+ crs = sf :: st_crs(crs )
215+ if (num_features == - 1 ) {
216+ num_features = NULL
217+ }
218+ df = suppressWarnings(nanoarrow :: convert_array_stream(x , size = num_features ))
219+
220+ df [is_geometry_column ] = lapply(df [is_geometry_column ], function (x ) {
221+ x = sf :: st_as_sfc(wk :: as_wkb(x ))
222+ st_set_crs(x , crs )
223+ })
224+
225+ if (as_tibble ) {
226+ df = tibble :: as_tibble(df )
227+ }
228+
229+ if (any(is_geometry_column )) {
230+ st_as_sf(df )
231+ } else {
232+ df
233+ }
209234}
210235
211236# ' @name st_read
@@ -242,11 +267,9 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet
242267
243268 if (use_stream ) {
244269 stream = nanoarrow :: nanoarrow_allocate_array_stream()
245- CPL_read_gdal_stream(stream , dsn , layer , query , as.character(options ), quiet ,
270+ info <- CPL_read_gdal_stream(stream , dsn , layer , query , as.character(options ), quiet ,
246271 drivers , wkt_filter , dsn_exists , dsn_isdb , getOption(" width" ))
247- process_cpl_read_ogr_stream(stream , quiet , check_ring_dir = check_ring_dir ,
248- stringsAsFactors = stringsAsFactors , geometry_column = geometry_column ,
249- optional = optional , ... )
272+ process_cpl_read_ogr_stream(stream , crs = info [[1 ]], num_features = info [[2 ]], ... )
250273 } else {
251274 x = CPL_read_ogr(dsn , layer , query , as.character(options ), quiet , type , fid_column_name ,
252275 drivers , wkt_filter , promote_to_multi , int64_as_string , dsn_exists , dsn_isdb , getOption(" width" ))
0 commit comments