Comments (9)
That does seem to be from your screenshots @subha-nair. Can you share a reproducible example?
from stplanr.
desirelines <-sf::st_read("Desirelines.geojson")
mapview::mapview(desirelines)
[
routes <- route(
l = desirelines,
route_fun = route_osrm,
osrm.profile ="car",
returnclass = "sf"
)
plot(sf::st_geometry(routes))
from stplanr.
Function works OK:
library(stplanr)
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is TRUE
# ?route_osrm
l1 = od_data_lines[49, ]
l1m = od_coords(l1)
from = l1m[, 1:2]
to = l1m[, 3:4]
r_foot = route_osrm(from, to)
r_bike = route_osrm(from, to, osrm.profile = "bike")
r_car = route_osrm(from, to, osrm.profile = "car")
plot(r_foot$geometry, lwd = 9, col = "grey")
plot(r_bike, col = "blue", add = TRUE)
#> Warning in plot.sf(r_bike, col = "blue", add = TRUE): ignoring all but the
#> first attribute
plot(r_car, col = "red", add = TRUE)
#> Warning in plot.sf(r_car, col = "red", add = TRUE): ignoring all but the first
#> attribute
Created on 2023-11-21 with reprex v2.0.2
from stplanr.
But not within a route()
call:
library(stplanr)
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is TRUE
u = "https://github.com/ropensci/stplanr/files/13431574/Desirelines.zip"
f = basename(u)
if (!file.exists(f)) {
download.file(u, f)
}
unzip(f)
l = sf::read_sf("Desirelines.geojson")
l$length = as.numeric(sf::st_length(l))
summary(l$length)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0 4314 14740 53992 54380 491260
l_2km = l[l$length > 1900 & l$length < 2100, ]
l_minimal = l_2km[1:5, ]
# mapview::mapview(l_minimal)
r = route(l = l_minimal, route_fun = route_osrm, wait = 1)
#> Most common output is subscriptOutOfBoundsError
#> These routes failed: 2, 3, 4, 5
#> The first of which was:
#> <subscriptOutOfBoundsError in ldf[i, 1:2]: subscript out of bounds>
plot(r)
#> Warning: plotting the first 9 out of 10 attributes; use max.plot = 10 to plot
#> all
Created on 2023-11-21 with reprex v2.0.2
from stplanr.
Only the first route is being returned for some reason.
from stplanr.
desirelines <-sf::read_sf("Desirelines.geojson")
r_car <- desirelines[1:10, ]
mapview::mapview(r_car)
routes <- route(l = r_car, route_fun = route_osrm, wait = 1)
plot(sf::st_geometry(routes))
Oh yes, tried the first 10 lines - only 1 was generated. Wanted to understand why we calculate the st_length of the desire lines, Would prefer calculating length of the routes.
from stplanr.
But more importantly have 3715 lines to be converted to routes
from stplanr.
Update:
Finally got the code to work with a slight change (issue was the desireline was a multiline string instead of a linestring)
Apply stplanr route function with route_osrm as route function
routes = stplanr::route(l = sf, route_fun = osrmRoute, returnclass = "sf")
Plot the identified routes on a map by distance
plot(sf::st_geometry(routes))
But some of the lines are straight lines instead of routes, not sure why
from stplanr.
Hi @subha-nair that's great to hear, good work! I guess some of the route failed, for whatever reason, leading to a few straight lines. Closing this issue for now, keep us posted..
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
- Argument of segment_length in line_segment fun causes issue HOT 14
- 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.