Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume sf geometry is always accessible via [['geometry']], fixes #1659 #1690

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion R/sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion tests/figs/colorscales/colorramp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/colorscales/test-df.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/colorscales/test-list.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/colorscales/test-matrix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/cookbook-axes/cookbook-axes-log2-labels.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/deps.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- vdiffr-svg-engine: 1.0
- vdiffr: 0.3.1
- vdiffr: 0.3.1.9000
- freetypeharfbuzz: 0.2.5
2 changes: 1 addition & 1 deletion tests/figs/heatmap/heatmap-midpoint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.