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

Upcoming sf version will break MODIS (when using s2 for geometries with ellipsoidal coordinates) #110

Closed
edzer opened this issue Apr 17, 2021 · 7 comments

Comments

@edzer
Copy link

edzer commented Apr 17, 2021

Please see r-spatial/sf#1649 - please consider commenting there if you get stuck! (@paleolimbot: another ✖ Loop 0 is not valid: Edge 1 crosses edge 6)

@edzer
Copy link
Author

edzer commented Jun 2, 2021

Still the case. Please consider using sf::st_make_valid on data with ellipsoidal coordinates.

  > getTile(Up)
  Error: Problem with `filter()` input `..1`.
  ℹ Input `..1` is `lengths(.predicate(x, y, ...)) > 0`.
  ✖ Evaluation error: Found 4 features with invalid spherical geometry.
  [13] Loop 0 is not valid: Edge 1 crosses edge 6
  [18] Loop 0 is not valid: Edge 0 crosses edge 5
  [446] Loop 0 is not valid: Edge 1 crosses edge 4
  [451] Loop 0 is not valid: Edge 2 crosses edge 5.
  Backtrace:
       █
    1. ├─MODIS::getTile(Up)
    2. ├─MODIS::getTile(Up)
    3. │ ├─MODIS::getTile(sf::st_as_sf(x), ...)
    4. │ └─MODIS::getTile(sf::st_as_sf(x), ...)
    5. │   ├─base::suppressMessages(sf::st_filter(sr, x))
    6. │   │ └─base::withCallingHandlers(...)
    7. │   ├─sf::st_filter(sr, x)
    8. │   └─sf:::st_filter.sf(sr, x)
    9. │     ├─dplyr::filter(x, lengths(.predicate(x, y, ...)) > 0)
   10. │     ├─sf:::filter.sf(x, lengths(.predicate(x, y, ...)) > 0)
   11. │     │ └─sf:::.re_sf(...)
   12. │     │   └─base::stopifnot(...)
   13. │     ├─base::NextMethod()
   14. │     └─dplyr:::filter.data.frame(...)
   15. │       └─dplyr:::filter_rows(.data, ...)
   16. │         ├─base::withCallingHandlers(...)
   17. │         └─mask$eval_all_filter(dots, env_filter)
   18. ├─base::lengths(.predicate(x, y, ...))
   19. ├─sf:::.predicate(x, y, ...)
   20. ├─sf:::st_intersects.sf(x, y, ...)
   21. │ └─sf:::st_geos_binop(...)
   22. │   └─s2:::fn(x, y, s2::s2_options(model = s2_model, ...))
   23. │     ├─s2:::cpp_s2_intersects_matrix(...)
   24. │     ├─s2::as_s2_geography(x)
   25. │     └─sf:::as_s2_geography.sf(x)
   26. │       └─sf:::st_as_s2.sf(x, ..., oriented = oriented)
   27. │         ├─sf::st_as_s2(st_geometry(x), ...)
   28. │         └─sf:::st_as_s2.sfc(st_geometry(x), ...)
   29. │           ├─s2::as_s2_geography(st_as_binary(x), ..., oriented = oriented)
   30. │           └─s2:::as_s2_geography.WKB(st_as_binary(x), ..., oriented = oriented)
   31. │             ├─s2:::new_s2_xptr(...)
   32. │             └─s2:::s2_geography_from_wkb(x, oriented = oriented, check = check)
   33. ├─base::stop(...)
   34. └─(function (e) ...
  Execution halted

You can test with s2 (1.0.5) from CRAN, and sf branch sf_1_0 from the github repo. Let me know if we can help.

@karldw
Copy link

karldw commented Jun 30, 2021

FYI, MODIS was been removed from CRAN on June 28, 2021 because of these errors.

Users can install an archived version with remotes::install_version("MODIS", "1.2.3") (though you'll run into the issues described above unless you also install an old version of sf).

@edzer
Copy link
Author

edzer commented Jun 30, 2021

install an old version of sf

... or use sf_use_s2(FALSE).

@MatMatt
Copy link
Collaborator

MatMatt commented Jul 1, 2021 via email

@edzer
Copy link
Author

edzer commented Jul 1, 2021

Great - let me know when you need help!

@fdetsch
Copy link
Owner

fdetsch commented Aug 20, 2021

@edzer Thanks for the notification! I haven't been following the discussion in quite a while. From what I understand, would it be enough to examine any incoming geometry with sf::st_is_valid() and, if required, then invoke sf::st_make_valid()?

@fdetsch
Copy link
Owner

fdetsch commented Aug 20, 2021

So to answer my own question, it seems like this approach is not viable. At least,

sf::sf_use_s2(TRUE)

data(meuse, package = "sp")
pts = sf::st_as_sf(meuse, coords = c("x", "y"), crs = 28992)

all(sf::st_is_valid(pts))
# TRUE

MODIS::getTile(pts[1, ])

using valid geometries only leads to the same error:

 Error: Problem with `filter()` input `..1`.Input `..1` is `lengths(.predicate(x, y, ...)) > 0`.
x Evaluation error: Found 4 features with invalid spherical geometry.
[13] Loop 0 is not valid: Edge 1 crosses edge 6
[18] Loop 0 is not valid: Edge 0 crosses edge 5
[446] Loop 0 is not valid: Edge 1 crosses edge 4
[451] Loop 0 is not valid: Edge 2 crosses edge 5.

Will start investigating with temporarily setting sf_use_s2(FALSE), in particular if this impacts the operability of the pkg.

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

Successfully merging a pull request may close this issue.

4 participants