Skip to content

Commit 7a36142

Browse files
committed
align column ordering and printing
1 parent 5595f5d commit 7a36142

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

R/read.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,26 @@ process_cpl_read_ogr_stream = function(x, default_crs, num_features, fid_column_
233233
df = suppressWarnings(nanoarrow::convert_array_stream(x, size = num_features))
234234

235235
df[is_geometry_column] = lapply(df[is_geometry_column], function(x) {
236-
attributes(x) <- NULL
237-
sf::st_as_sfc(wk::new_wk_wkb(x, crs = crs))
236+
class(x) <- "WKB"
237+
x <- st_as_sfc(x)
238+
st_set_crs(x, crs)
238239
})
239240

240241
# Prefer "geometry" as the geometry column name
241242
if (any(is_geometry_column) && !("geometry" %in% names(df))) {
242243
names(df)[which(is_geometry_column)[1]] = "geometry"
243244
}
244-
245-
# Rename OGC_FID to fid_column_name
245+
246+
# Rename OGC_FID to fid_column_name and move to end
246247
if (length(fid_column_name) == 1 && "OGC_FID" %in% names(df)) {
248+
df <- df[c(setdiff(names(df), "OGC_FID"), "OGC_FID")]
247249
names(df)[names(df) == "OGC_FID"] = fid_column_name
248250
}
251+
252+
# Move geometry to the end
253+
if ("geometry" %in% names(df)) {
254+
df <- df[c(setdiff(names(df), "geometry"), "geometry")]
255+
}
249256

250257
process_cpl_read_ogr(df, ...)
251258
}
@@ -288,7 +295,7 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet
288295
info = CPL_read_gdal_stream(stream, dsn, layer, query, as.character(options), quiet,
289296
drivers, wkt_filter, dsn_exists, dsn_isdb, fid_column_name, getOption("width"))
290297
process_cpl_read_ogr_stream(stream, default_crs = info[[1]], num_features = info[[2]],
291-
fid_column_name = fid_column_name, stringsAsFactors = stringsAsFactors, ...)
298+
fid_column_name = fid_column_name, stringsAsFactors = stringsAsFactors, quiet = quiet, ...)
292299
} else {
293300
x = CPL_read_ogr(dsn, layer, query, as.character(options), quiet, type, fid_column_name,
294301
drivers, wkt_filter, promote_to_multi, int64_as_string, dsn_exists, dsn_isdb, getOption("width"))

0 commit comments

Comments
 (0)