Coder Social home page Coder Social logo

Comments (2)

rCarto avatar rCarto commented on June 22, 2024

Hi,
I first thought this problem was already solved in the dev version of the pkg.
See

remotes::install_github('riatelab/osrm')`

then

library(osrm)
#> Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
#> Routing: OSRM - http://project-osrm.org/
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE

point_1 <- c(25086.15, 194501.7)
point_2 <- c(25032.33, 195725.5)
point_3 <- c(24140.32, 193718.8)
point_4 <- c(24217, 194746)
point_5 <- c(24445.09, 195494.1)
point_6 <- c(24368.93, 194250.5)
point_7 <- c(25521.03, 195911.1)
point_8 <- c(25830.59, 195202.3)
point_9 <- c(25235.08, 194137.3)

# Create data frame
point_df <- do.call(rbind.data.frame, 
                    lapply(paste("point", 1:9, sep = "_"), get))
names(point_df) <- c("X", "Y")


# Create sf object
point_sf <- point_df |>
  st_as_sf(coords = c("X", "Y"), crs = st_crs(31370))

# Calculate trip
mytrip_car <- osrmTrip(point_sf)
mytrip_foot <- osrmTrip(point_sf, osrm.profile = "foot")

(mytrip_car[[1]]$trip)
#> Simple feature collection with 9 features and 4 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 23624.07 ymin: 193204.7 xmax: 25996.78 ymax: 195831.9
#> Projected CRS: Belge 1972 / Belgian Lambert 72
#>   start end  duration distance                       geometry
#> 1     1   3  6.970000   1.5851 LINESTRING (25159.03 194109...
#> 2     3   6 10.055000   2.6630 LINESTRING (25159.03 194109...
#> 3     6   4  6.096667   1.3394 LINESTRING (24374.11 193425...
#> 4     4   5  1.160000   0.4828 LINESTRING (23958.38 194241...
#> 5     5   7  3.550000   1.3431 LINESTRING (24511.62 195110...
#> 6     7   2  1.270000   0.4323 LINESTRING (24133.11 194961...
#> 7     2   8  1.161667   0.7748 LINESTRING (25381.3 195646....
#> 8     8   9  8.516667   3.1316 LINESTRING (25381.3 195646....
#> 9     9   1  0.000000   0.0000 LINESTRING (25309.59 195831...
(mytrip_foot[[1]]$trip)
#> Simple feature collection with 9 features and 4 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 23624.07 ymin: 193204.7 xmax: 25996.78 ymax: 195831.9
#> Projected CRS: Belge 1972 / Belgian Lambert 72
#>   start end duration distance                       geometry
#> 1     1   3 21.13833   1.5851 LINESTRING (25159.03 194109...
#> 2     3   6 35.50833   2.6630 LINESTRING (25159.03 194109...
#> 3     6   4 17.85667   1.3394 LINESTRING (24374.11 193425...
#> 4     4   5  6.43500   0.4828 LINESTRING (23958.38 194241...
#> 5     5   2 17.45833   1.3092 LINESTRING (24511.62 195110...
#> 6     2   7  5.76500   0.4323 LINESTRING (24133.11 194961...
#> 7     7   8 10.78167   0.8087 LINESTRING (25446.87 195476...
#> 8     8   9 41.79167   3.1316 LINESTRING (25381.3 195646....
#> 9     9   1  0.00000   0.0000 LINESTRING (25381.3 195646....

Created on 2023-03-23 with reprex v2.0.2

But inspecting more in details actual road lengths, I see there is still a problem, geometries do not match trip segments. There is a kind of offset. I'll look into it asap. Thank you for the bug report.

trip <- mytrip_car[[1]]$trip
trip$length <- st_length(trip)

(trip)
#> Simple feature collection with 9 features and 5 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 23624.07 ymin: 193204.7 xmax: 25996.78 ymax: 195831.9
#> Projected CRS: Belge 1972 / Belgian Lambert 72
#>   start end  duration distance                       geometry        length
#> 1     1   3  6.970000   1.5851 LINESTRING (25159.03 194109...    0.0000 [m]
#> 2     3   6 10.055000   2.6630 LINESTRING (25159.03 194109... 1224.1767 [m]
#> 3     6   4  6.096667   1.3394 LINESTRING (24374.11 193425... 2692.4443 [m]
#> 4     4   5  1.160000   0.4828 LINESTRING (23958.38 194241... 1250.3470 [m]
#> 5     5   7  3.550000   1.3431 LINESTRING (24511.62 195110...  407.1056 [m]
#> 6     7   2  1.270000   0.4323 LINESTRING (24133.11 194961... 1593.2942 [m]
#> 7     2   8  1.161667   0.7748 LINESTRING (25381.3 195646....  466.3010 [m]
#> 8     8   9  8.516667   3.1316 LINESTRING (25381.3 195646....  199.2373 [m]
#> 9     9   1  0.000000   0.0000 LINESTRING (25309.59 195831... 3905.0552 [m]

Created on 2023-03-23 with reprex v2.0.2

from osrm.

wlangera avatar wlangera commented on June 22, 2024

Ok, thank you for your fast reply.
I installed the package from CRAN, not the dev version.

Kind regards,
Ward

from osrm.

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.