Giter VIP home page Giter VIP logo

Comments (9)

Robinlovelace avatar Robinlovelace commented on August 22, 2024

That does seem to be from your screenshots @subha-nair. Can you share a reproducible example?

from stplanr.

subha-nair avatar subha-nair commented on August 22, 2024

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))

Desirelines.zip

from stplanr.

Robinlovelace avatar Robinlovelace commented on August 22, 2024

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.

Robinlovelace avatar Robinlovelace commented on August 22, 2024

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.

Robinlovelace avatar Robinlovelace commented on August 22, 2024

Only the first route is being returned for some reason.

from stplanr.

subha-nair avatar subha-nair commented on August 22, 2024

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.

subha-nair avatar subha-nair commented on August 22, 2024

But more importantly have 3715 lines to be converted to routes

from stplanr.

subha-nair avatar subha-nair commented on August 22, 2024

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

routes

routes.zip

from stplanr.

Robinlovelace avatar Robinlovelace commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.