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

Inconsisent id numbers in tween_sf #13

Open
BBranoff opened this issue Oct 26, 2023 · 1 comment
Open

Inconsisent id numbers in tween_sf #13

BBranoff opened this issue Oct 26, 2023 · 1 comment

Comments

@BBranoff
Copy link

BBranoff commented Oct 26, 2023

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 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.

@BBranoff
Copy link
Author

update: interestingly, reversing the order of the polygons sometimes works...

`
polys <- tween_sf(poly2, poly1, ease="linear", nframes=5)

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant