Skip to content

Commit 04ec9b3

Browse files
committed
passing read tests using the stream interface
1 parent a032ecc commit 04ec9b3

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

R/read.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ default_st_read_use_stream = function() {
218218
)
219219
}
220220

221-
process_cpl_read_ogr_stream = function(x, crs, num_features, fid_column_name,
222-
...) {
221+
process_cpl_read_ogr_stream = function(x, default_crs, num_features, fid_column_name,
222+
crs = NULL, ...) {
223223
is_geometry_column = vapply(
224224
x$get_schema()$children,
225225
function(s) identical(s$metadata[["ARROW:extension:name"]], "ogc.wkb"),
226226
logical(1)
227227
)
228228

229-
crs = sf::st_crs(crs)
229+
crs = if (is.null(crs)) st_crs(default_crs) else st_crs(crs)
230230
if (num_features == -1) {
231231
num_features = NULL
232232
}
@@ -287,8 +287,8 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet
287287
stream = nanoarrow::nanoarrow_allocate_array_stream()
288288
info = CPL_read_gdal_stream(stream, dsn, layer, query, as.character(options), quiet,
289289
drivers, wkt_filter, dsn_exists, dsn_isdb, fid_column_name, getOption("width"))
290-
process_cpl_read_ogr_stream(stream, crs = info[[1]], num_features = info[[2]],
291-
fid_column_name = fid_column_name, ...)
290+
process_cpl_read_ogr_stream(stream, default_crs = info[[1]], num_features = info[[2]],
291+
fid_column_name = fid_column_name, stringsAsFactors = stringsAsFactors, ...)
292292
} else {
293293
x = CPL_read_ogr(dsn, layer, query, as.character(options), quiet, type, fid_column_name,
294294
drivers, wkt_filter, promote_to_multi, int64_as_string, dsn_exists, dsn_isdb, getOption("width"))

src/gdal_read_stream.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ Rcpp::List CPL_read_gdal_stream(
106106
}
107107

108108
GDALStreamWrapper::Make(&stream_temp, prep, stream_out);
109-
double num_features = (double) poLayer->GetFeatureCount(false);
109+
110+
// The reported feature count is incorrect if there is a query
111+
double num_features;
112+
if (query.size() == 0) {
113+
num_features = (double) poLayer->GetFeatureCount(false);
114+
} else {
115+
num_features = -1;
116+
}
110117

111118
return Rcpp::List::create(wkt_str, Rcpp::NumericVector::create(num_features));
112119
}

0 commit comments

Comments
 (0)