8000 Don't assume sf geometry is always accessible via [['geometry']], fixes #1659 by cpsievert · Pull Request #1690 · plotly/plotly.R · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Don't assume sf geometry is always accessible via [['geometry']], fixes
  • Loading branch information
cpsievert committed Feb 4, 2020
commit 7d2ea6dfd96f032c542b7c16d861249643690cbd
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
0