riatelab/osrm

Problem with input data and osrmTrip()

romunov opened this issue · 3 comments

There appears to be a problem calculating routs if I use more than 8 points in my dataset.

> trips <- osrmTrip(
+   loc = xys[1:9, ],
+   overview = "full"
+ )
Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 11, 9
> traceback()
6: stop(gettextf("arguments imply differing number of rows: %s", 
       paste(unique(nrows), collapse = ", ")), domain = NA)
5: data.frame(..., check.names = FALSE)
4: cbind(deparse.level, ...)
3: cbind(data.frame(row.names = row.names), as.data.frame(x[-all_sfc_columns], 
       stringsAsFactors = stringsAsFactors, optional = TRUE))
2: st_sf(start = start, end = end, duration = res$trips[nt, ]$legs[[1]][, 
       "duration"]/60, distance = res$trips[nt, ]$legs[[1]][, "distance"]/1000, 
       geometry = st_as_sfc(wktl, crs = 4326))
1: osrmTrip(loc = xys[1:9, ], overview = "full")

To reproduce this, download this spreadsheet as a tsv and run the script below:

library(osrm)

# https://www.jurecuhalev.com/blog/optimal-route-finding/

xy <- read.table("./data/invaders..._from_space.tsv", sep = "\t", header = TRUE)
xy$lat <- sapply(strsplit(xy$Lat..Long, split = ","), FUN = "[[", 1)
xy$lon <- sapply(strsplit(xy$Lat..Long, split = ","), FUN = "[[", 2)
xy$lat <- as.numeric(xy$lat)
xy$lon <- as.numeric(xy$lon)

xys <- st_as_sf(
  x = xy,
  coords = c("lon", "lat")
)
st_crs(xys) <- "WGS84"

trips <- osrmTrip(
  loc = xys[1:9, ],
  overview = "full"
)

Any help appreciated.

This is my sessionInfo():

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 36 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.2

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] sf_1.0-8   osrm_4.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         class_7.3-20       grid_4.1.3         DBI_1.1.3          magrittr_2.0.3    
 [6] e1071_1.7-12       units_0.8-0        KernSmooth_2.23-20 mapiso_0.2.0       RcppSimdJson_0.1.8
[11] renv_0.14.0        curl_4.3.3         tools_4.1.3        proxy_0.4-27       compiler_4.1.3    
[16] classInt_0.4-8     isoband_0.2.6    

The dev version (remotes::install_github('riatelab/osrm') should be ok now.

Yepp, code works now, thanks!

My next task is to overlay the result over OSM and see why the discrepancy as some points are not visited.

image

Some points are not reachable by car. It seems that the center of the city is a pedestrian area. You can try a different OSRM profile if your OSRM server provides one.

trips <- osrmTrip(..., osrm.profile = "foot")