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 will break nhdR (when adopting s2) #70

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

upcoming sf will break nhdR (when adopting s2) #70

edzer opened this issue Apr 17, 2021 · 3 comments

Comments

@edzer
Copy link

edzer commented Apr 17, 2021

Hi! please see r-spatial/sf#1649 - please also consider commenting there when you run into troubles or need advice or help. Best,

@edzer
Copy link
Author

edzer commented Jun 2, 2021

Seeing this output:

══ Failed tests ════════════════════════════════════════════════════════════════
── Error (test-utils.R:10:3): find_vpu works with character vpus ───────────────
Error: Evaluation error: Found 2 features with invalid spherical geometry.
[6] Loop 18 is not valid: Edge 1 crosses edge 3
[22] Loop 49 is not valid: Edge 0 crosses edge 2.
Backtrace:
     █
  1. ├─testthat::expect_equal(nhdR:::find_vpu(pnt), "03S") test-utils.R:10:2
  2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
  3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
  4. └─nhdR:::find_vpu(pnt)
  5.   ├─base::suppressMessages(st_join(sf::st_sf(pnt), vpu)$UnitID)
  6.   │ └─base::withCallingHandlers(...)
  7.   ├─sf::st_join(sf::st_sf(pnt), vpu)
  8.   └─sf:::st_join.sf(sf::st_sf(pnt), vpu)
  9.     ├─sf:::join(x, y, ...)
 10.     └─sf:::st_intersects.sf(x, y, ...)
 11.       └─sf:::st_geos_binop(...)
 12.         └─s2:::fn(x, y, s2::s2_options(model = s2_model, ...))
 13.           ├─s2:::cpp_s2_intersects_matrix(...)
 14.           ├─s2::as_s2_geography(y)
 15.           └─sf:::as_s2_geography.sf(y)
 16.             └─sf:::st_as_s2.sf(x, ..., oriented = oriented)
 17.               ├─sf::st_as_s2(st_geometry(x), ...)
 18.               └─sf:::st_as_s2.sfc(st_geometry(x), ...)
 19.                 ├─s2::as_s2_geography(st_as_binary(x), ..., oriented = oriented)
 20.                 └─s2:::as_s2_geography.WKB(st_as_binary(x), ..., oriented = oriented)
 21.                   ├─s2:::new_s2_xptr(...)
 22.                   └─s2:::s2_geography_from_wkb(x, oriented = oriented, check = check)
── Error (test-utils.R:16:3): find_vpu works with numeric vpus ─────────────────
Error: Evaluation error: Found 2 features with invalid spherical geometry.
6] Loop 18 is not valid: Edge 1 crosses edge 3
[22] Loop 49 is not valid: Edge 0 crosses edge 2.
Backtrace:
     █
  1. ├─testthat::expect_equal(nhdR:::find_vpu(pnt), "01") test-utils.R:16:2
  2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
  3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
  4. └─nhdR:::find_vpu(pnt)
  5.   ├─base::suppressMessages(st_join(sf::st_sf(pnt), vpu)$UnitID)
  6.   │ └─base::withCallingHandlers(...)
  7.   ├─sf::st_join(sf::st_sf(pnt), vpu)
  8.   └─sf:::st_join.sf(sf::st_sf(pnt), vpu)
  9.     ├─sf:::join(x, y, ...)
 10.     └─sf:::st_intersects.sf(x, y, ...)
 11.       └─sf:::st_geos_binop(...)
 12.         └─s2:::fn(x, y, s2::s2_options(model = s2_model, ...))
 13.           ├─s2:::cpp_s2_intersects_matrix(...)
 14.           ├─s2::as_s2_geography(y)
 15.           └─sf:::as_s2_geography.sf(y)
 16.             └─sf:::st_as_s2.sf(x, ..., oriented = oriented)
 17.               ├─sf::st_as_s2(st_geometry(x), ...)
 18.               └─sf:::st_as_s2.sfc(st_geometry(x), ...)
 19.                 ├─s2::as_s2_geography(st_as_binary(x), ..., oriented = oriented)
 20.                 └─s2:::as_s2_geography.WKB(st_as_binary(x), ..., oriented = oriented)
 21.                   ├─s2:::new_s2_xptr(...)
 22.                   └─s2:::s2_geography_from_wkb(x, oriented = oriented, check = check)

[ FAIL 2 | WARN 0 | SKIP 14 | PASS 3 ]

so it seems there are some geometries not valid on the sphere. Let me know if we can help. Testing with branch sf_1_0 from the sf repo, and s2 from CRAN (1.0.5).

@jsta
Copy link
Owner

jsta commented Jun 6, 2021

I think I solved the issue. sf::st_make_valid was not creating valid s2 geometries for some internal package data. The somewhat complex solution at r-spatial/s2#99 (comment) seems to work.

@jsta jsta closed this as completed in 79fee8d Jun 6, 2021
@edzer
Copy link
Author

edzer commented Jun 6, 2021

Hi Jem! Great work - I looked into it yesterday, and didn't succeed - I couldn't find that issue you refer to back! Maybe this is also of interest to @dblodgett-usgs who might be fighting with the same weird polygons.

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

2 participants