Skip to content

Commit 7d2ea6d

Browse files
committed
Don't assume sf geometry is always accessible via [['geometry']], fixes #1659
1 parent c47c1f9 commit 7d2ea6d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

R/layers2traces.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,14 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) {
273273

274274
#' @export
275275
to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {
276-
277-
data[["geometry"]] <- sf::st_sfc(data[["geometry"]])
278-
data <- sf::st_as_sf(data, sf_column_name = "geometry")
276+
277+
data <- sf::st_as_sf(data)
279278
geom_type <- sf::st_geometry_type(data)
280279
# st_cast should "expand" a collection into multiple rows (one per feature)
281280
if ("GEOMETRYCOLLECTION" %in% geom_type) {
282281
data <- sf::st_cast(data)
283282
geom_type <- sf::st_geometry_type(data)
284283
}
285-
data <- remove_class(data, "sf")
286284

287285
basic_type <- dplyr::recode(
288286
as.character(geom_type),
@@ -310,6 +308,7 @@ to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {
310308
d[[i]] <- prefix_class(
311309
fortify_sf(d[[i]]), c(names(d)[[i]], "GeomSf")
312310
)
311+
d[[i]] <- remove_class(d[[i]], "sf")
313312
}
314313
if (length(d) == 1) d[[1]] else d
315314
}

R/sf.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fortify_sf <- function(model, ...) {
1111
# the coordinate belongs; for POINT this is absent (each coordinate is a feature),
1212
# for LINESTRING L1 refers to the feature, for MULTIPOLYGON L1 refers to the main
1313
# ring or holes, L2 to the ring id in the MULTIPOLYGON, and L3 to the simple feature.
14-
coords <- sf::st_coordinates(model$geometry)
14+
coords <- sf::st_coordinates(sf::st_geometry(model))
1515
colnames(coords) <- tolower(colnames(coords))
1616
lcols <- grep("^l", colnames(coords))
1717

0 commit comments

Comments
 (0)