-
Notifications
You must be signed in to change notification settings - Fork 66
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
Argument of segment_length in line_segment fun causes issue #552
Comments
That definitely sounds like a bug. Will aim to take a look today. Did it work previously? |
I didn't spot the issue before, segment_length was not defined in
rnet_merge in the previous test.
…On Thu, 2 Nov 2023 at 11:51, Robin Lovelace ***@***.***> wrote:
That definitely sounds like a bug. Will aim to take a look today. Did it
work previously?
—
Reply to this email directly, view it on GitHub
<#552 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARZESTQDIDH2X7FMLY2IRX3YCOCNZAVCNFSM6AAAAAA6ZSJX7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJQGU4DOOJUGU>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
Can you provide a full reproducible example? |
Full reproducible example, showing that this is for sure an issue: rnet_x = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_x_ed.geojson")
rnet_y = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_y_ed.geojson")
segment_length = 15 # will cause error, but segment_length =10 is not
library(stplanr)
# ?rnet_merge
names(rnet_y)
#> [1] "value" "Quietness" "geometry"
funs = list(vaue = sum, Quietness = mean)
res = rnet_merge(rnet_x, rnet_y)
#> [1] "funs is NULL"
#> Joining with `by = join_by(identifier)`
res2 = rnet_merge(rnet_x, rnet_y, segment_length = segment_length)
#> [1] "funs is NULL"
#> Error in `[[<-`:
#> ! Assigned data `res` must be compatible with existing data.
#> ✖ Existing data has 3859 rows.
#> ✖ Assigned data has 3858 rows.
#> ℹ Only vectors of size 1 are recycled.
#> Caused by error in `vectbl_recycle_rhs_rows()`:
#> ! Can't recycle input of size 3858 to size 3859.
#> Backtrace:
#> ▆
#> 1. ├─stplanr::rnet_merge(rnet_x, rnet_y, segment_length = segment_length)
#> 2. │ └─stplanr::rnet_join(rnet_x, rnet_y, dist = dist, crs = crs, ...)
#> 3. │ ├─stplanr::line_segment(rnet_y, segment_length = segment_length)
#> 4. │ └─stplanr:::line_segment.sf(rnet_y, segment_length = segment_length)
#> 5. │ └─stplanr:::line_segment_rsgeo(l, n_segments = n_segments)
#> 6. │ ├─base::`[[<-`(`*tmp*`, attr(l, "sf_column"), value = `<LINESTRING [°]>`)
#> 7. │ └─tibble:::`[[<-.tbl_df`(`*tmp*`, attr(l, "sf_column"), value = `<LINESTRING [°]>`)
#> 8. │ └─tibble:::tbl_subassign(...)
#> 9. │ └─tibble:::vectbl_recycle_rhs_rows(value, fast_nrow(xo), i_arg = NULL, value_arg, call)
#> 10. │ ├─base::withCallingHandlers(...)
#> 11. │ └─vctrs::vec_recycle(value[[j]], nrow)
#> 12. └─vctrs:::stop_recycle_incompatible_size(...)
#> 13. └─vctrs:::stop_vctrs(...)
#> 14. └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
res3 = rnet_merge(rnet_x, rnet_y, segment_length = 10)
#> [1] "funs is NULL"
#> Joining with `by = join_by(identifier)` Created on 2023-11-02 with reprex v2.0.2 |
The line that jumps out to me is this one:
Could it be another issue with the Rust implementation? Heads-up @JosiahParry in case, I'll have a look and try to pull out a minimal example. |
Confirmed: seems one out of ~4k expected geometries is missing:
|
library(rsgeo)
x <- geom_linestring(
c(-3.19416, -3.19352, -3.19288),
c(55.95524, 55.95535, 55.95546)
)
line_segmentize(x, 6) |>
expand_geoms() Minimal reproducible example. I think this may be fixed upstream? I'm not sure what the cause is here. Alo as an aside, these are likely somewhat inaccurate segments since its being applied to geodetic coordinates instead of planar ones. |
I genuinely think its because the numbers are so small. library(rsgeo)
x <- geom_linestring(
c(-3.19416, -3.19352, -3.19288) * 10,
c(55.95524, 55.95535, 55.95546) * 10
)
line_segmentize(x, 6) |>
expand_geoms() |
Re-compiling now after entering remotes::install_dev("rsgeo") |
Update: same issue after rebuilding. |
Yes that could potentially explain it:
There shouldn't be any tiny linestrings in the example data though, minimum length should be 15m. |
This is likely a bug, yes and should be fixed. But more than anything I think this is a misuse of the function. It's running into an error because of floating point precision. You're applying a euclidean algorithm in a geodetic space. In this very specific example we're partitioning I have pushed a HaversineSegmentize trait to georust upstream which would measure this in units of meters instead of euclidean units. Creating a |
Yeah. Running it on projected data sounds like a good plan. Can you try that @wangzhao0217 ? |
Related georust/geo#1107 |
See JosiahParry/rsgeo#42 which this mitigates
…in-line_segment-fun-causes-issue-2 Use output of rsgeo for n_segments (#552)
for this minimal dataset:
rnet_x = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_x_ed.geojson")
rnet_y = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_y_ed.geojson")
segment_length = 15 will cause error, but segment_length =10 is not.
The text was updated successfully, but these errors were encountered: