Comments (8)
Seems that it fails here:
Line 229 in 69486ee
from stplanr.
After adding browser()
in the commit above it's clear that this issue is due to the following:
[1] 1 1 1 1 1 1
Browse[1]> length(res)
[1] 12565
Browse[1]> nrow(res_tbl)
[1] 12584
from stplanr.
A wider problem with the implementation: it outputs the same number of lengths 'sublines' regardless of the length of the original line in the vectorised version:
Browse[2]> segment_length = 10
Browse[2]> n_segments <- max(round(l_length / segment_length), 1)
Browse[2]> n_segments
[1] 56
Browse[2]> # segmentize the line strings
Browse[2]> res <- rsgeo::line_segmentize(geo, n_segments)
Browse[2]> # make them into sfc_LINESTRING
Browse[2]> res <- sf::st_cast(sf::st_as_sfc(res), "LINESTRING")
Browse[2]> summary(sf::st_length(res))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.01115 0.20942 0.48429 0.77075 1.01727 9.98451
Browse[2]> res
Geometry set for 64064 features
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 324174.3 ymin: 673163.9 xmax: 326361.4 ymax: 674519.1
CRS: NA
First 5 geometries:
LINESTRING (324797.2 673311.6, 324797.3 673311.6)
LINESTRING (324797.3 673311.6, 324797.3 673311.6)
LINESTRING (324797.3 673311.6, 324797.4 673311.7)
LINESTRING (324797.4 673311.7, 324797.4 673311.7)
LINESTRING (324797.4 673311.7, 324797.4 673311.7)
Browse[2]> # give them them CRS
Browse[2]> res <- sf::st_set_crs(res, crs)
Browse[2]> # calculate the number of original geometries
Browse[2]> n <- length(geo)
Browse[2]> # create index ids to grab rows from
Browse[2]> ids <- rep.int(1:n, rep(n_segments, n))
Browse[2]> res_tbl <- sf::st_drop_geometry(l)[ids,]
Browse[2]> # assign the geometry column
Browse[2]> res_tbl[[attr(l, "sf_column")]] <- res
Browse[2]> res_final = sf::st_as_sf(res_tbl)
Browse[2]> nrow(res_final) / nrow(l)
[1] 56
Browse[2]> names(res_final)
[1] "value" "Quietness" "geometry"
Browse[2]> res_final
Simple feature collection with 64064 features and 2 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 324174.3 ymin: 673163.9 xmax: 326361.4 ymax: 674519.1
Projected CRS: OSGB36 / British National Grid
# A tibble: 64,064 × 3
value Quietness geometry
<dbl> <dbl> <LINESTRING [m]>
1 0 50 (324797.2 673311.6, 324797.3 673311.6)
2 0 50 (324797.3 673311.6, 324797.3 673311.6)
3 0 50 (324797.3 673311.6, 324797.4 673311.7)
4 0 50 (324797.4 673311.7, 324797.4 673311.7)
5 0 50 (324797.4 673311.7, 324797.4 673311.7)
6 0 50 (324797.4 673311.7, 324797.5 673311.7)
7 0 50 (324797.5 673311.7, 324797.5 673311.7)
8 0 50 (324797.5 673311.7, 324797.6 673311.8)
9 0 50 (324797.6 673311.8, 324797.6 673311.8)
10 0 50 (324797.6 673311.8, 324797.7 673311.8)
# ℹ 64,054 more rows
# ℹ Use `print(n = ...)` to see more rows
Browse[2]> summary(sf::st_length(res_final))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.01115 0.20942 0.48429 0.77075 1.01727 9.98451
Browse[2]> summary(sf::st_length(l))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.6246 11.7273 27.1204 43.1622 56.9671 559.1324
from stplanr.
Update on this: latest commit in #548 diagnoses the line in rnet_y
that is failing: n. 108:
Processing row 108 of 1144
|+++++ | 9 % ~13s Processing row 109 of 1144
Error in `[[<-` at stplanr/R/linefuns.R:364:2:
! Assigned data `res` must be compatible with existing data.
✖ Existing data has 4 rows.
✖ Assigned data has 3 rows.
ℹ Only vectors of size 1 are recycled.
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 3 to size 4.
Run `rlang::last_trace()` to see where the error occurred.
from stplanr.
Minimal example for ya @JosiahParry
library(stplanr)
failing_line = structure(list(structure(c(324957.69921197, 324957.873557727,
324959.863123514, 324961.852683597, 324963.822867622, 324969.636546456,
324976.718443977, 324996.443964294, 673670.123131518, 673680.139281405,
673686.784106964, 673693.428933452, 673698.960855279, 673709.992098018,
673722.114520549, 673742.922904206), dim = c(8L, 2L), class = c("XY",
"LINESTRING", "sfg"))), class = c("sfc_LINESTRING", "sfc"), precision = 0, bbox = structure(c(xmin = 324957.69921197,
ymin = 673670.123131518, xmax = 324996.443964294, ymax = 673742.922904206
), class = "bbox"), n_empty = 0L)
sf::st_crs(failing_line) = "EPSG:27700"
line_segment(failing_line, segment_length = 20)
#> Error in line_segment.sfc_LINESTRING(failing_line, segment_length = 20): object 'segment' not found
Created on 2023-10-01 with reprex v2.0.2
from stplanr.
The {rsgeo}
bug:
failing_line = structure(list(structure(c(324957.69921197, 324957.873557727,
324959.863123514, 324961.852683597, 324963.822867622, 324969.636546456,
324976.718443977, 324996.443964294, 673670.123131518, 673680.139281405,
673686.784106964, 673693.428933452, 673698.960855279, 673709.992098018,
673722.114520549, 673742.922904206), dim = c(8L, 2L), class = c("XY",
"LINESTRING", "sfg"))), class = c("sfc_LINESTRING", "sfc"), precision = 0, bbox = structure(c(xmin = 324957.69921197,
ymin = 673670.123131518, xmax = 324996.443964294, ymax = 673742.922904206
), class = "bbox"), n_empty = 0L)
sf::st_crs(failing_line) = "EPSG:27700"
line_segment(failing_line, segment_length = 20)
#> Error in line_segment(failing_line, segment_length = 20): could not find function "line_segment"
# Try with rsgeo:
geo <- rsgeo::as_rsgeo(sf::st_geometry(failing_line))
# segmentize the line strings
res <- rsgeo::line_segmentize(geo, 4)
res <- sf::st_cast(sf::st_as_sfc(res), "LINESTRING")
res
#> Geometry set for 3 features
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 324957.7 ymin: 673670.1 xmax: 324996.4 ymax: 673742.9
#> CRS: NA
#> LINESTRING (324957.7 673670.1, 324957.9 673680....
#> LINESTRING (324961.1 673690.9, 324961.9 673693....
#> LINESTRING (324969.8 673710.2, 324976.7 673722....
nrow(res) # should be 4
#> NULL
sf::st_length(res)
#> [1] 21.23587 21.23587 42.47173
Created on 2023-10-01 with reprex v2.0.2
from stplanr.
For now, can you please install from github? This has been resolved. I need to make my PR to geo and push the patch to CRAN.
rnet_y = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_y_ed.geojson")
g <- rnet_y$geometry |>
sf::st_transform("EPSG:27700")
stplanr::line_segment(g, 5)
#> Geometry set for 5720 features
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 324174.3 ymin: 673163.4 xmax: 326361.3 ymax: 674518.6
#> Projected CRS: OSGB36 / British National Grid
#> First 5 geometries:
#> LINESTRING (324797.2 673311.1, 324797.7 673311.3)
#> LINESTRING (324797.7 673311.3, 324798.2 673311.5)
#> LINESTRING (324798.2 673311.5, 324798.7 673311.8)
#> LINESTRING (324798.7 673311.8, 324799.2 673312)
#> LINESTRING (324799.2 673312, 324799.7 673312.2)
Created on 2023-10-01 with reprex v2.0.2
from stplanr.
For now, can you please install from github?
Can do, will add as Remotes. Will keep this issue open until the next CRAN release of rsgeo
after which will be a good time to do a CRAN release of stplanr
.
from stplanr.
Related Issues (20)
- Comparing the results between angle_diff with calculate_angle/get_vector HOT 1
- Error message in bind_sf
- CRAN issues
- bug in the rnet_merge function when defining the funs HOT 3
- 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
- `rnet_merge()` fails when inputs are projected HOT 4
- `line_bearing()` is slow HOT 3
- Argument of segment_length in line_segment fun causes issue HOT 14
- 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
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.