diff --git a/NEWS.md b/NEWS.md index c6bd2c3f3d..d12a400de9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# 4.9.1.9000 + +## BUG FIXES + +* `add_sf()`/`geom_sf()` now correctly handle geometry columns that are named something other than `"geometry"` (#1659). + # 4.9.1 ## Changes to plotly.js diff --git a/R/layers2traces.R b/R/layers2traces.R index 1a7dd7ef85..6920e6ce4c 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -273,16 +273,14 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) { #' @export to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) { - - data[["geometry"]] <- sf::st_sfc(data[["geometry"]]) - data <- sf::st_as_sf(data, sf_column_name = "geometry") + + data <- sf::st_as_sf(data) geom_type <- sf::st_geometry_type(data) # st_cast should "expand" a collection into multiple rows (one per feature) if ("GEOMETRYCOLLECTION" %in% geom_type) { data <- sf::st_cast(data) geom_type <- sf::st_geometry_type(data) } - data <- remove_class(data, "sf") basic_type <- dplyr::recode( as.character(geom_type), @@ -310,6 +308,7 @@ to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) { d[[i]] <- prefix_class( fortify_sf(d[[i]]), c(names(d)[[i]], "GeomSf") ) + d[[i]] <- remove_class(d[[i]], "sf") } if (length(d) == 1) d[[1]] else d } diff --git a/R/sf.R b/R/sf.R index 3db4218243..a92c919bca 100644 --- a/R/sf.R +++ b/R/sf.R @@ -11,7 +11,7 @@ fortify_sf <- function(model, ...) { # the coordinate belongs; for POINT this is absent (each coordinate is a feature), # for LINESTRING L1 refers to the feature, for MULTIPOLYGON L1 refers to the main # ring or holes, L2 to the ring id in the MULTIPOLYGON, and L3 to the simple feature. - coords <- sf::st_coordinates(model$geometry) + coords <- sf::st_coordinates(sf::st_geometry(model)) colnames(coords) <- tolower(colnames(coords)) lcols <- grep("^l", colnames(coords)) diff --git a/tests/figs/colorscales/colorramp.svg b/tests/figs/colorscales/colorramp.svg index c94999d52f..a7c69f3419 100644 --- a/tests/figs/colorscales/colorramp.svg +++ b/tests/figs/colorscales/colorramp.svg @@ -1 +1 @@ -246810246810246810 +246810246810246810 diff --git a/tests/figs/colorscales/test-df.svg b/tests/figs/colorscales/test-df.svg index 21dec1f79b..ebbccd210d 100644 --- a/tests/figs/colorscales/test-df.svg +++ b/tests/figs/colorscales/test-df.svg @@ -1 +1 @@ -246810246810123456789 +246810246810123456789 diff --git a/tests/figs/colorscales/test-list.svg b/tests/figs/colorscales/test-list.svg index 21dec1f79b..ebbccd210d 100644 --- a/tests/figs/colorscales/test-list.svg +++ b/tests/figs/colorscales/test-list.svg @@ -1 +1 @@ -246810246810123456789 +246810246810123456789 diff --git a/tests/figs/colorscales/test-matrix.svg b/tests/figs/colorscales/test-matrix.svg index 21dec1f79b..ebbccd210d 100644 --- a/tests/figs/colorscales/test-matrix.svg +++ b/tests/figs/colorscales/test-matrix.svg @@ -1 +1 @@ -246810246810123456789 +246810246810123456789 diff --git a/tests/figs/cookbook-axes/cookbook-axes-log2-labels.svg b/tests/figs/cookbook-axes/cookbook-axes-log2-labels.svg index a7aaa10483..3713591fd2 100644 --- a/tests/figs/cookbook-axes/cookbook-axes-log2-labels.svg +++ b/tests/figs/cookbook-axes/cookbook-axes-log2-labels.svg @@ -1 +1 @@ -012345[object Object][object Object][object Object][object Object]xvalyval +0123455.0010.0015.0020.00xvalyval diff --git a/tests/figs/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg b/tests/figs/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg index f584685bb5..11ea1f758e 100644 --- a/tests/figs/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg +++ b/tests/figs/cookbook-axes/cookbook-axes-scale-y-log10-labels.svg @@ -1 +1 @@ -012345[object Object][object Object][object Object][object Object][object Object][object Object]xvalyval +0123451.002.003.004.005.006.00xvalyval diff --git a/tests/figs/deps.txt b/tests/figs/deps.txt index 0f64e23e67..9e920bb55e 100644 --- a/tests/figs/deps.txt +++ b/tests/figs/deps.txt @@ -1,3 +1,3 @@ - vdiffr-svg-engine: 1.0 -- vdiffr: 0.3.1 +- vdiffr: 0.3.1.9000 - freetypeharfbuzz: 0.2.5 diff --git a/tests/figs/heatmap/heatmap-midpoint.svg b/tests/figs/heatmap/heatmap-midpoint.svg index bae986f9b8..71d4b9cd3f 100644 --- a/tests/figs/heatmap/heatmap-midpoint.svg +++ b/tests/figs/heatmap/heatmap-midpoint.svg @@ -1 +1 @@ -0.000.250.500.751.000.000.250.500.751.000.000.250.500.751.00zxy +0.000.250.500.751.000.000.250.500.751.000.000.250.500.751.00zxy diff --git a/tests/figs/plotly-color/plotly-color-scatterplot-color-factor-custom.svg b/tests/figs/plotly-color/plotly-color-scatterplot-color-factor-custom.svg index 07bed2fe24..527fb34c9c 100644 --- a/tests/figs/plotly-color/plotly-color-scatterplot-color-factor-custom.svg +++ b/tests/figs/plotly-color/plotly-color-scatterplot-color-factor-custom.svg @@ -1 +1 @@ -56781234567setosaversicolorvirginicaSepal.LengthPetal.Length +56781234567setosaversicolorvirginicaSepal.LengthPetal.Length