Comments (14)
That definitely sounds like a bug. Will aim to take a look today. Did it work previously?
from stplanr.
from stplanr.
I didn't spot the issue before, segment_length was not defined in rnet_merge in the previous test.
Can you provide a full reproducible example?
from stplanr.
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
from stplanr.
The line that jumps out to me is this one:
stplanr:::line_segment_rsgeo(l, n_segments = n_segments)
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.
from stplanr.
Confirmed: seems one out of ~4k expected geometries is missing:
res_tbl[[attr(l, "sf_column")]] <- res
Error in `[[<-`(`*tmp*`, attr(l, "sf_column"), value = list(c(-3.20572, :
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.
from stplanr.
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.
from stplanr.
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()
from stplanr.
I think this may be fixed upstream?
Re-compiling now after entering
remotes::install_dev("rsgeo")
from stplanr.
Update: same issue after rebuilding.
from stplanr.
I genuinely think its because the numbers are so small.
Yes that could potentially explain it:
> line_segmentize(x, 6) |>
+ expand_geoms()
[[1]]
<rs_LINESTRING[5]>
[1] LineString([Coord { x: -3.19416, y: 55.95524 }, Coord { x: -3.194, y: 55.955267500000005 }, Coord { x: -3.193946666666667, y: 55.95527666666...
[2] LineString([Coord { x: -3.193946666666667, y: 55.95527666666667 }, Coord { x: -3.19384, y: 55.95529500000001 }, Coord { x: -3.19373333333333...
[3] LineString([Coord { x: -3.1937333333333333, y: 55.955313333333336 }, Coord { x: -3.19368, y: 55.9553225 }, Coord { x: -3.19352, y: 55.95535 }]))
[4] LineString([Coord { x: -3.19352, y: 55.95535 }, Coord { x: -3.19352, y: 55.95535 }, Coord { x: -3.193306666666667, y: 55.95538666666667 }]))
[5] LineString([Coord { x: -3.193306666666667, y: 55.95538666666667 }, Coord { x: -3.1933066666666665, y: 55.95538666666667 }, Coord { x: -3.193...
There shouldn't be any tiny linestrings in the example data though, minimum length should be 15m.
from stplanr.
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 0.001298769
into 6 equal length pieces of size 0.0002164615
. We're dealing with tiny units of precision that is getting futzed up. This does not occur if you increase the scale by even 1 decimal place.
I have pushed a HaversineSegmentize trait to georust upstream which would measure this in units of meters instead of euclidean units. Creating a line_segmentize_haversine()
would be the real fix here.
from stplanr.
Yeah. Running it on projected data sounds like a good plan. Can you try that @wangzhao0217 ?
from stplanr.
Related georust/geo#1107
from stplanr.
Related Issues (20)
- Use different buffer options in `rnet_merge()`
- Convert large GeoJSON file to PMTiles HOT 1
- bug in geo_buffer HOT 7
- Possible speed enhancement to `mats2line()` HOT 3
- Invalid LineStrings in routes_fast_sf HOT 1
- Use `od::odc_to_sfc()` do the legwork in `mats2line()` HOT 3
- Bug in `line_segment()` when using certain values on projected data with `rsgeo` implementation HOT 8
- `rnet_merge()` fails when inputs are projected HOT 4
- `line_bearing()` is slow HOT 3
- Tried creating a route from desirelines using osrm function HOT 9
- rnet merge function can't not handle attributes containing strings HOT 1
- Add links to more papers in DESCRIPTION
- Re-add n_segments argument to line_segment() HOT 1
- `line_segment()` fails when n_segments has multiple values HOT 1
- od2line() throws an error if only one origin-destination relation is selected HOT 5
- Tests fail if {rsgeo} is not installed
- Work-around rsgeo not on cran
- Checks when Suggests are unavailable HOT 1
- Actions failing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stplanr.