Im running into an error when running the tween_sf function on a pair of sf polygons. For many of the pairs, the function works great, well done! However, for some polygons, there is an issue when assigning ids towards the end of the function sequence. I've tracked this down to the following sequence:
polys.zip
aligned <- Map(function(from, to, type) {
switch(type, POINT = ,
MULTIPOINT =align_sf_point(from, to),
LINESTRING = ,
MULTILINESTRING =align_sf_path(from, to, 50),
POLYGON = ,
MULTIPOLYGON = align_sf_polygon(from, to, 50))
}, from = from, to = to, type = from_type)
line 13 in align_sf_polygon
to$id <- id`
which throws the error: Error in $<-.data.frame(*tmp*, "id", value = c(1L, 1L, 1L, 1L, 1L, :
replacement has x rows, data has y
In this example, the issue is with poly2, but I cannot determine why. I have tried poly2 %>% st_simplify(), poly2 %>% st_make_valid(), etc. With simplify, the number of rows in the above error message will change, but the error is still thrown. I have also tried varying the ease function and the number of transitions, but this doesnt help.
Im running into an error when running the tween_sf function on a pair of sf polygons. For many of the pairs, the function works great, well done! However, for some polygons, there is an issue when assigning ids towards the end of the function sequence. I've tracked this down to the following sequence: polys.zip
`poly1 <- read_sf("poly1.shp") poly2 <- read_sf("poly2.shp") df1 <- data.frame(geo = poly1 %>% st_as_sfc()) df2 <- data.frame(geo = poly2 %>% st_as_sfc())
polys <- tween_sf(poly1, poly2, ease="linear", nframes=5)
line 24 in tween_sf
morph[which(sf_columns)] <- tween_sf_col(sf_from, sf_to, rep("linear", length.out = ncol(from))[sf_columns], nframes)
line 3 in tween_sf_col
aligned <- align_sf(from[[i]], to[[i]])
line 15 in align_sf
aligned <- Map(function(from, to, type) { switch(type, POINT = , MULTIPOINT =align_sf_point(from, to), LINESTRING = , MULTILINESTRING =align_sf_path(from, to, 50), POLYGON = , MULTIPOLYGON = align_sf_polygon(from, to, 50)) }, from = from, to = to, type = from_type)
line 13 in align_sf_polygon
to$id <- id`
which throws the error: Error in
$<-.data.frame
(*tmp*
, "id", value = c(1L, 1L, 1L, 1L, 1L, : replacement has x rows, data has yIn this example, the issue is with poly2, but I cannot determine why. I have tried poly2 %>% st_simplify(), poly2 %>% st_make_valid(), etc. With simplify, the number of rows in the above error message will change, but the error is still thrown. I have also tried varying the ease function and the number of transitions, but this doesnt help.