Skip to content

Commit

Permalink
have st_layers() return sf_layers,data.frame objects
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Apr 23, 2024
1 parent bdaa655 commit b8ff604
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# version 1.0-17

* `st_layers()` returns an object of class `c("sf_layers", "data.frame")`, with a dedicated `print` method.

* when `dim` is not `XYZM`, `sf_as_sf.data.frame()` interprets a length 4 `coords` argument to specify the corners of a rectangular polygon; #2357

* `st_interpolate_aw()` gains an `na.rm` argument, for removing features with `NA` attributes before interpolating; #830
Expand Down
2 changes: 1 addition & 1 deletion R/read.R
Expand Up @@ -700,7 +700,7 @@ st_layers = function(dsn, options = character(0), do_count = FALSE) {
Encoding(ret[[1]]) <- "UTF-8"
ret[[1]] <- enc2native(ret[[1]])
}
ret
structure(ret, row.names = seq_along(ret[[1]]), class = c("sf_layers", "data.frame"))
}

guess_driver = function(dsn) {
Expand Down
18 changes: 8 additions & 10 deletions src/gdal_read.cpp
Expand Up @@ -182,17 +182,15 @@ Rcpp::List CPL_get_layers(Rcpp::CharacterVector datasource, Rcpp::CharacterVecto
feature_count(iLayer) = count_features(poLayer);
}

Rcpp::List out(6);
out(0) = names;
out(1) = geomtype;
out(2) = poDS->GetDriverName();
out(3) = feature_count;
out(4) = field_count;
out(5) = layer_crs;
Rcpp::List ret = Rcpp::List::create(
Rcpp::_["name"] = names,
Rcpp::_["geomtype"] = geomtype,
Rcpp::_["driver"] = poDS->GetDriverName(),
Rcpp::_["features"] = feature_count,
Rcpp::_["fields"] = field_count,
Rcpp::_["crs"] = layer_crs);
GDALClose(poDS); // close & destroys data source
out.attr("names") = Rcpp::CharacterVector::create("name", "geomtype", "driver", "features", "fields", "crs");
out.attr("class") = Rcpp::CharacterVector::create("sf_layers");
return out;
return ret;
}

Rcpp::List sf_from_ogrlayer(OGRLayer *poLayer, bool quiet, bool int64_as_string,
Expand Down

0 comments on commit b8ff604

Please sign in to comment.