Coder Social home page Coder Social logo

riatelab / osrm Goto Github PK

View Code? Open in Web Editor NEW
226.0 8.0 29.0 21.67 MB

Interface between R and the OpenStreetMap-based routing service OSRM

Home Page: https://doi.org/10.21105/joss.04574

License: GNU General Public License v3.0

R 88.32% TeX 11.68%
osrm travel openstreetmap r cran shortest-paths r-package

osrm's Introduction

osrm

CRAN downloads R build status codecov Project Status: Active – The project has reached a stable, usable state and is being actively developed. DOI

Interface Between R and the OpenStreetMap-Based Routing Service OSRM

Description

OSRM is a routing service based on OpenStreetMap data. See http://project-osrm.org/ for more information. This package enables the computation of routes, trips, isochrones and travel distances matrices (travel time and kilometric distance).

This package relies on the usage of a running OSRM service (tested with v5.27.0 of OSRM).

You can run your own instance of OSRM following guidelines provided here. The simplest solution is probably the one based on docker containers.

⚠️ You must be careful using the OSRM demo server and read the about page of the service:

One request per second max. No scraping, no heavy usage.

Features

  • osrmTable() uses the table service to query time/distance matrices,
  • osrmRoute() uses the route service to query routes,
  • osrmTrip() uses the trip service to query trips,
  • osrmNearest() uses the nearest service to query the nearest point on the street network,
  • osrmIsochrone() and osrmIsodistance() use multiple osrmTable() calls to create isochrones or isodistances polygons.

Demo

This is a short overview of the main features of osrm. The dataset used here is shipped with the package, it is a sample of 100 random pharmacies in Berlin (© OpenStreetMap contributors) stored in a geopackage file.

  • osrmTable() gives access to the table OSRM service. In this example we use this function to get the median time needed to access any pharmacy from any other pharmacy.
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
pharmacy <- st_read(system.file("gpkg/apotheke.gpkg", package = "osrm"), 
                    quiet = TRUE)
travel_time <- osrmTable(loc = pharmacy)
travel_time$durations[1:5,1:5]
##      1    2    3    4    5
## 1  0.0 21.1 33.4 21.2 12.6
## 2 22.1  0.0 42.3 16.1 20.2
## 3 33.0 43.0  0.0 30.5 27.4
## 4 20.1 15.3 29.7  0.0 12.7
## 5 10.2 20.3 26.8 12.3  0.0
diag(travel_time$durations) <- NA
median(travel_time$durations, na.rm = TRUE)
## [1] 21.4

The median time needed to access any pharmacy from any other pharmacy is 21.4 minutes.

  • osrmRoute() is used to compute the shortest route between two points. Here we compute the shortest route between the two first pharmacies.
(route <- osrmRoute(src = pharmacy[1, ], dst = pharmacy[2, ]))
## Simple feature collection with 1 feature and 4 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: -13170.51 ymin: 5837172 xmax: -3875.771 ymax: 5841047
## Projected CRS: WGS 84 / UTM zone 34N
##     src dst duration distance                       geometry
## 1_2   1   2 21.11667   12.348 LINESTRING (-13170.51 58410...

This route is 12.3 kilometers long and it takes 21.1 minutes to drive through it.

plot(st_geometry(route))
plot(st_geometry(pharmacy[1:2,]), pch = 20, add = T, cex = 1.5)

  • osrmTrip() can be used to resolve the travelling salesman problem, it gives the shortest trip between a set of unordered points. In this example we want to obtain the shortest trip between the first five pharmacies.
(trips <- osrmTrip(loc = pharmacy[1:5, ], overview = "full"))
## [[1]]
## [[1]]$trip
## Simple feature collection with 5 features and 4 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: -13431.24 ymin: 5837172 xmax: -3875.582 ymax: 5856332
## Projected CRS: WGS 84 / UTM zone 34N
##   start end duration distance                       geometry
## 1     1   2 21.11667  12.3480 LINESTRING (-13170.77 58410...
## 2     2   4 16.10833   8.4273 LINESTRING (-3875.582 58379...
## 3     4   3 29.69000  18.1448 LINESTRING (-7444.513 58427...
## 4     3   5 27.39833  16.4265 LINESTRING (-8027.41 585621...
## 5     5   1 10.15333   4.2289 LINESTRING (-11716.36 58435...
## 
## [[1]]$summary
## [[1]]$summary$duration
## [1] 104.4667
## 
## [[1]]$summary$distance
## [1] 59.5755

The shortest trip between these pharmacies takes 104.5 minutes and is 59.6 kilometers long. The steps of the trip are described in the “trip” sf object (point 1 > point 2 > point 4 > point 3 > point 5 > point 1).

mytrip <- trips[[1]]$trip
# Display the trip
plot(st_geometry(mytrip), col = c("black", "grey"), lwd = 2)
plot(st_geometry(pharmacy[1:5, ]), cex = 1.5, pch = 21, add = TRUE)
text(st_coordinates(pharmacy[1:5,]), labels = row.names(pharmacy[1:5,]), 
     pos = 2)

  • osrmNearest() gives access to the nearest OSRM service. It returns the nearest point on the street network from any point. Here we will get the nearest point on the network from a couple of coordinates.
pt_not_on_street_network <- c(13.40, 52.47)
(pt_on_street_network <- osrmNearest(loc = pt_not_on_street_network))
## Simple feature collection with 1 feature and 2 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 13.39671 ymin: 52.46661 xmax: 13.39671 ymax: 52.46661
## Geodetic CRS:  WGS 84
##      id distance                  geometry
## loc loc      439 POINT (13.39671 52.46661)

The distance from the input point to the nearest point on the street network is of 439 meters

  • osrmIsochrone() computes areas that are reachable within a given time span from a point and returns the reachable regions as polygons. These areas of equal travel time are called isochrones. Here we compute the isochrones from a specific point defined by its longitude and latitude.
(iso <- osrmIsochrone(loc = c(13.43,52.47), breaks = seq(0,12,2)))
## Simple feature collection with 5 features and 3 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 13.34397 ymin: 52.41642 xmax: 13.50187 ymax: 52.51548
## Geodetic CRS:  WGS 84
##   id isomin isomax                       geometry
## 1  1      0      4 MULTIPOLYGON (((13.43743 52...
## 2  2      4      6 MULTIPOLYGON (((13.42356 52...
## 3  3      6      8 MULTIPOLYGON (((13.40345 52...
## 4  4      8     10 MULTIPOLYGON (((13.4077 52....
## 5  5     10     12 MULTIPOLYGON (((13.42257 52...
bks <-  sort(unique(c(iso$isomin, iso$isomax)))
pals <- hcl.colors(n = length(bks) - 1, palette = "Light Grays", rev = TRUE)
plot(iso["isomax"], breaks = bks, pal = pals, 
     main = "Isochrones (in minutes)", reset = FALSE)
points(x = 13.43, y = 52.47, pch = 4, lwd = 2, cex = 1.5)

Installation

  • Development version on GitHub
remotes::install_github("riatelab/osrm")
  • Stable version on CRAN
install.packages("osrm")

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here. See the CONTRIBUTING.md file for detailed instructions.

Acknowledgements

Many thanks to the editor (@elbeejay) and reviewers (@JosiahParry, @mikemahoney218 and @wcjochem) of the JOSS article.
This publication has led to a significant improvement in the code base and documentation of the package.

osrm's People

Contributors

kirel avatar mbask avatar metanoid avatar pasipasi123 avatar rcarto avatar rcura avatar robinlovelace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osrm's Issues

osrmRoute with via points

Hello.
How do I add location along the path of travel so that I can get my route plotted at those points as well.
I'd appreciate a solution to this question. Thanks'

Originally posted by @Anyaoha in #33 (comment)

Allow src and dst to take lon/lat vectors

Great package, very impressed, planning to use this as a backend in stplanr. One thing that would help that is if src and dst could take vectors, not just spatial object. Demo of what I mean below. cc @richardellison who may be up for helping with this:

library(osrm)
#> Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
#> Routing: OSRM - http://project-osrm.org/
    library(stplanr)
#> Registered S3 method overwritten by 'R.oo':
#>   method        from       
#>   throw.default R.methodsS3
    options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")
    
    l = pct::wight_lines_30
    p = line2points(l)
    r = osrm::osrmRoute(src = p[1, ], dst = p[2, ], returnclass = "sf")
    plot(r)

    
    
    route_osrm2 = function(l) {
        p = line2points(l)
        s = (1:nrow(l)) * 2 - 1
        list_out = lapply(s, function(i) osrm::osrmRoute(p[i, ], dst = p[i + 1, ], returnclass = "sf"))
        do.call(rbind, list_out)
    }
    routes_osrm = route_osrm2(l)
    plot(routes_osrm)

    
    # with coordinates
    c1 = as.numeric(sf::st_coordinates(p[1, ]))
    c2 = as.numeric(sf::st_coordinates(p[2, ]))
    osrm::osrmRoute(src = c1, dst = c2, returnclass = "sf")
#> The OSRM server returned an error:
#> Error: InvalidQuery
#> Query string malformed close to position 27
#> NULL

Created on 2019-09-20 by the reprex package (v0.3.0)

Error with osrmTable

Hi,

when i'm using osrmTable I have this error :
"osrmTable function returns an error:
Error in function (type, msg, asError = TRUE) : Failed to connect to router.project-osrm.org port 80: Timed out"
Could you help me or explain why ?

Furthermore, I would know if it is still possible to have a road distance matrix between points ? (as the osrmTableOD did)

Thanks

osrmViarouteGeom()

Hi, thanks for the great package!

I'm curious if you know if it is possible to get the route object back with an associated time at each point from 'osrm'. Something like this:

library(osrm)
df <- osrmViarouteGeom(17.743773, 59.740056,17.757533, 59.739084)
df$time <- osrmTable(a, id = NULL, x = "lon", y = "lat")[1,]
df

Of course the above code works but it seems like the times should already be available from the route calculation and that the calculation of the times is somehow repeating what was already done?

different isochrones generated for same parameters

Hi Timothée,

I realised that I am getting different isochrones for the same coordinates and parameters that I input. For example, the code below gave me 2 different isochrones. One query was done last month at night and the second query was done today afternoon.

iso <- osrmIsochrone(loc = c(-1.3583549, 50.91489), 
                      breaks = seq(from = 0,to=8,by=8),
                      returnclass = "sf")

Why is this? Is the formation of the isochrones time-dependent? Meaning that it depends on the time of the day that I query it? Couldn't find the answer to this on the official documentation.

Would appreciate your help!

Thank you!!

I get an error when using osrmIsoChrone

I executed following R codes.

library(osrm)

data("com")

iso <- osrmIsochrone(loc = src[6,], breaks = seq(from = 0,to = 30, by = 5))

but I got a following error when using osrmIsoChrone function

osrmTable function returns an error: 
Error: Something went wrong. It could be that the URL sent to the OSRM public API is too long. 
         Try to enter less sources or destinations.

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘coordinates’ for signature ‘"NULL"’

My sessionInfo is as follows.

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Japanese_Japan.932  LC_CTYPE=Japanese_Japan.932    LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C                  
[5] LC_TIME=Japanese_Japan.932    

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

other attached packages:
[1] osrm_3.0.1

loaded via a namespace (and not attached):
[1] compiler_3.4.0  rgdal_1.2-7     tools_3.4.0     RCurl_1.95-4.8  sp_1.2-4        grid_3.4.0      bitops_1.0-6    gepaf_0.1.0    
[9] lattice_0.20-35

Could you tell me what I should?

Option to set speed in the osrmIsochrone function

Would it be possible to include an option for users to set the speed in the osrmIsochrone function (to not be limited to using the defaults)?

The reason I ask is that when I ran the code for a 10 minute walk time and plotted the result (see below), the resulting Isochrone extends to the edges of the grid, which makes me question whether the grid is capturing the whole 10 minute walk time area or just what fits in the grid. I hypothesize that the walk speed is too slow and therefore the resulting grid is too small to capture the whole walk time.

A related question, are the units for speed in feet per minute? If so, for walk time that equates to about 1.9 mph, whereas (from the quick internet search I did) an average walk speed is about 3 mph.

options(osrm.profile = "walk")
iso <- osrmIsochrone(loc = c(28.307913, -15.396259), breaks = seq(from = 0, to = 10, by = 10), res = 100)

fig

osrmIsochrone throws error

Do you understand the following error:

> options(osrm.server = "http://router.project-osrm.org/")
> iso <- osrm::osrmIsochrone(loc = c(5.936036, 49.24882), breaks = seq(from = 0, to = 15, length.out = 3))

Error in rbind2(..1, r) :  no method for coercing this S4 class to a vector

or

> options(osrm.server = "http://router.project-osrm.org/")
> iso <- osrm::osrmIsochrone(loc = c(5.936036, 49.24882), breaks = seq(from = 0, to = 15, length.out = 3))

Error in rbind2(..1, r) :  no method for coercing this S4 class to a vector

Thank you very much for your support,

Christoph

Multiple distances with osrmRoute?

Hello,
I'm a new user of the package and love it so far, thank you!!
I do have a question if I can use osrmRoute to get multiple distances? I have a table of a couple of 100 coordinates from -> to. So a Matrix is out.
Data structure of a is ID, x, y, Long, lat (with x and y being the source coordinates and Long, lat being the Destination coordinates). The function works perfectly with just one row, but as soon as I ask for 2 rows I get an error message

route <- osrmRoute (src = a[1:2, c("id","x","y")],

  •                 dst = a[1:2, c("id","long","lat")], overview="simplified", sp="TRUE")
    

osrmRoute function returns an error:
Error: URL string malformed close to position 32: "23, 13"

since I only Need the distance(and maybe minutes, but not neccessarily), is there a way get those for multiple lines?
Thank you!
Lina

Using "distance" measure is not possible in osrmIsochrone()

Hi,

I'm running my own OSRM server.

I'd like to get travel distance isochrones from osrmIsochrone(). Looking at the code I see that osrmTable has a measure argument, but osrmIsochrone() has a lot of hard coded variable names for the "duration" run, and most likely a variety of other hard coded duration based features.

Would it be possible to add "distance" to osrmIsochrone()? If it's a matter of rewriting some parts of the function, I can offer my help. I did try the rewrite some parts to allow for "distance", but I didn't get it to work.

still uncertain if osrm.profile = "walk" in osrmIsochrone works.

hi, similar topic may be discussed before.
To be able to use osrm.profile = "walk", I rebuilt the osrm instance using foot.lua. I did this after I finished building the default car.lua instance, which worked fine.
However, when I tried to build the instance using foot.lua in a totally new environment, I got an error
[error] Input file "/data/sweden-latest.osrm.ebg" not found!
I noticed this .ebg file was created in the previous step if using car.lua, but not foot.lua.
So I used car.lua first and then foot.lua later. It looked like the instance was built okay, and I can set osrm.profile = "walk" in options. But the results of osrmIsochrone was not reassuring. I gave two extreme time intervals to compare.

iso <- osrmIsochrone(loc,
                     breaks = seq(from = 0, to = 120, by = 60),
                     res = 400, returnclass = "sf")

and the results, according to my eyes, were very much similar, if not identical.
I guess .ebg file is where the problem is. Could anybody give some suggestions?
Thanks a lot.

Error invalid char in json text.

I used the following
osrmIsochrone(c(-95.9345,41.2565), breaks = 10)
and received this error

The OSRM server returned an error:
Error: lexical error: invalid char in json text.
                                       <HTML><HEAD>  <TITLE>Request Er
                     (right here) ------^


The OSRM server returned an error:
Error: lexical error: invalid char in json text.
                                       <HTML><HEAD>  <TITLE>Request Er
                     (right here) ------^


The OSRM server returned an error:
Error: lexical error: invalid char in json text.
                                       <HTML><HEAD>  <TITLE>Request Er
                     (right here) ------^


Error in UseMethod("st_as_sf") : 
  no applicable method for 'st_as_sf' applied to an object of class "NULL"```

url malformed

I'm trying to use rCarto/osrm with my local osrm server, but the url looks malformed:
OSRM returned an error:
Error: InvalidUrl
URL string malformed close to position 4: "v1/dri"

the osrm log output:
15-12-2017 23:05:02 5.59688ms 172.17.0.1 - 'osrm' R package 400 /v1/driving/

according to https://github.com/Project-OSRM/osrm-backend//docs/http.md
the {service} should come first.

graph-based isochrones / isodistances

Hi,

I have been working for awhile with various isochrone generation tools and techniques and tumbled upon this blog post:
http://kuanbutts.com/2017/12/16/osmnx-isochrones/

Do you think it is viable to try doing the isochrone generation in the osrm package for R using the igraph package ( https://github.com/igraph/rigraph ) ? The end result seems very precise and professional. Current isochrone maps produced by osrm and galton ( https://github.com/urbica/galton ) look very nice, but the lie a little bit about the real reachability of places.

Errors for osrmTrip

Hello,

When running osrmTrip, I am receiving two errors that I am having difficulty interpreting.

The first is:
"OSRM returned an error:
Error: "

The second is:
"OSRM returned an error:
Error: Unable to parse: GEOMETRYCOLLECTION(LINESTRING"...(followed by coordinate pairs)
"GEOS reported: "IllegalArgumentException: point array must contain 0 or >1 elements"

Any help interpreting these errors would be much appreciated.

Error: InvalidQuery Query string malformed close to position 6249

After an update from

sessionInfo("osrm")$otherPkgs
$`osrm`
Version: 3.1.1
Date: 2018-03-12

to

$`osrm`
Version: 3.3.2

we receive the following error:
Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
Routing: OSRM - http://project-osrm.org/
Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
The OSRM server returned an error:
Error: InvalidQuery
Query string malformed close to position 6249

Do you have any idea? Our call (as before the update) is of the type
osrm::osrmIsochrone(c(lngs[i], lats[i]), breaks, res)
The same code runs through without any error.

Please let me know, if you need anything else. Thanks a lot!

Replicating osrmIsochrone vignette script

I am assuming some other package change has caused the problem I am running into. The vignette for osrmIsochrone was working for me previously. But running the script now throws up an error on the line executing:

osm <- getTiles(spdf = iso, crop = TRUE, type = "osmtransport")

The function results in:
Error in { : task 2 failed - "arg 'X2' has dims=256, 256, 4; but need dims=X, 256, 3"

I can step through the code and create the isochrones, but the underlying tiles are the issue. I can create other maps with the cartography package. So I suspect there is something with the spdf created with:

iso <- osrmIsochrone(loc = src[6,], breaks = seq(from = 0,to = 30, by = 5))

Thanks

Impossible isochrones

When I run osrmIsochrone for a set of points in Alaska, it returns some impossible results. I'm running a local osrm server based on https://download.geofabrik.de/north-america/us/alaska-latest.osm.pbf

options(osrm.server = "http://localhost:5000/") #this works sort of
isochrone <- map2(latlon$lon, latlon$lat, 
                  ~ osrmIsochrone(loc = c(.x, .y),
                                  breaks = seq(0, 60, 60))) %>%
  do.call(what = rbind)

At first, the results look plausible:
large
But on closer inspection, they don't make any sense. Here, for example, is Sitka, Alaska:
sitka
What I'm doing here is plotting the service area (60 minutes' driving time) for a facility (orange dot) as compared with the census tracts for the area. The isochrone for the service area is blue; the different census tracts are in purple/green. I have confirmed that the proj4strings for both the census tract polygons and the isochrones are exactly the same.

What doesn't make sense about the isochrone plotted in the image above is that the roads around Sitka, Alaska, don't extend for more than 10 miles. There's no way that you could traverse Baranof Island and reach the next island to the east simply by driving for an hour. There's no roads. Also, there's a mountain range and a sea strait in the way. The inaccuracy of the isochrone affects my analysis, because it would suggest that I include a census tract in the Sitka facility's service area which, in fact, is not reachable within a 60 minute drive.

mt
sat
So I used the osrm-frontend to look up what osrm-backend is doing. Here's the route it gives me when I try to plot a course from Sitka to the eastern side of Baranof Island:
route
It would take three days to hike from the end of the road, as pictured above, to the eastern side of Baranof Island. But the directions given above don't mention that — and osrmIsochrone, for a reason I can't determine, believes you can drive all the way to the next island within 60 minutes.

Additionally, the isochrones for Anchorage suggest that most of Anchorage Bay is driveable. It is not, even in winter. Here's a plot of the facilities without isochrones:
wo
Here's the facilities' 60-minute isochrones, suggesting a drive into the bay:
anch

I still have isochrones for facilities in 49 other states to plot, so I don't know if the issue is with the map, or with osrmIsochrone, or with osrm-backend, but this is not an auspicious start. I have some doubts that isochrones produced for the facilities in the other 49 states would be analytically valid.

Can osrm handle multiple transports?

Hello,

Given that osrm interfaces OSM, is that possible with osrm to specify the mean of transportation and to get the details of the trip? (ex: walk 2min, then bus 4 during 15min, then walk 1 min) ?

Thanks,

Xavier

osrmTable/osrmTrip Issue with number of Inputs

I'll admit I could be doing something wrong and not realize it, but if so, I am having trouble seeing my mistake.

I am having the same issue with the osrmTable and osrmTrip functions, but I have no problem with osrmRoute. For example, I can run this with no issues:

route <- osrmRoute(src = center[1, c("cbsa", "Longitude","Latitude")],
                   dst = center[2, c("cbsa", "Longitude","Latitude")])

but when I run
distCom <- osrmTable(loc = center[1:5,c("cbsa","Longitude","Latitude")])

I get

osrmTable function returns an error:
Error: Not enough input coordinates given; minimum number of coordinates is 2.

and I get the exact same error with osrmTrip. This doesn't appear to be related to my data since the demo code in the documentation has this same problem:

data("com")
# Travel path between points
route <- osrmRoute(src = com[1, c("comm_id", "lon","lat")],
                   dst = com[15, c("comm_id", "lon","lat")])

works just fine but I get the same error when I run

data("com")
# Travel time matrix
distCom <- osrmTable(loc = com[1:50, c("comm_id","lon","lat")])

osrmIsochrone incorrect result

i have for example, loc = c(2.7353, 46.9514), duration = 45, res = 10 gives incorrect result coords 5 points
but when we change de res = 45 we get the correct result between 15 and 20 points

Cannot install package

Cannot install package on Ubunutu 18

install.packages('osrm', dependencies=TRUE)
Installing package into ‘/home/grosati/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/osrm_3.3.2.tar.gz'
Content type 'application/x-gzip' length 24411 bytes (23 KB)
==================================================
downloaded 23 KB

  • installing source package ‘osrm’ ...
    ** package ‘osrm’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** byte-compile and prepare package for lazy loading
    double free or corruption (out)
    Aborted (core dumped)
    ERROR: lazy loading failed for package ‘osrm’
  • removing ‘/home/grosati/R/x86_64-pc-linux-gnu-library/3.6/osrm’
    Warning in install.packages :
    installation of package ‘osrm’ had non-zero exit status

The downloaded source packages are in
‘/tmp/Rtmp4cvRTD/downloaded_packages’

`> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=es_AR.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=es_AR.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=es_AR.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=es_AR.UTF-8 LC_IDENTIFICATION=C

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

loaded via a namespace (and not attached):
[1] compiler_3.6.3 tools_3.6.3 `

osrmTrip returns (non-numeric argument to binary operator

In package osrm version 3.0.0
try:

data("com")
trips <- osrmTrip(loc = com[1101:1150, c(1,3,4)])

Error is on line 134-136 of file osrmTrip.R:

df <- data.frame(start, end,  
                       duration = res$trips[nt,]$legs[[1]][,3] / 60,  
                       distance = res$trips[nt,]$legs[[1]][,4] / 1000)

The distance column in the returned seems to have changed order in the json
Potential solution, replace 134-136 with

df <- data.frame(start, end, 
                       duration = res$trips[nt,]$legs[[1]][,3] / 60, 
                       distance = res$trips[nt,]$legs[[1]][,2] / 1000)

or alternatively

df <- data.frame(start, end, 
                       duration = res$trips[nt,]$legs[[1]][,"duration"] / 60, 
                       distance = res$trips[nt,]$legs[[1]][,"distance"] / 1000)

No route found

No routes are returning for my points. The below is an example of two points I'm trying to map.

> route <- osrmRoute(src = c(1, 40.39956, -79.98636 ), dst = c(2, 40.38693, -79.98355), overview = F) The OSRM server returned an error: Error: NoRoute No route found

Any assistance would be appreciated.

Sending large requests to local server

I've increased the maximum table size on my local server as
osrm-routed china-latest.osrm --max-table-size=1000
but I still cannot use osrmTable() for more than ~200 locations (it fails somewhere between 201 and 250). The error I get is:
osrmTable function returns an error: Error: lexical error: invalid char in json text. <html> <head><title>414 Reques (right here) ------^
The test example I've used:

library(osrm)

max_lat <- 40
min_lat <- 30

max_long <- 117
min_long <- 104

n <- 201

long <- runif(n,min=min_long,max=max_long)
lat <- runif(n,min=min_lat,max=max_lat)
names <- as.character(n)

china_mat <- data.frame(names,long,lat,stringsAsFactors = FALSE)
results <- osrmTable(china_mat,locId = "names",locLat = "lat",locLon = "long")

I can see from the server, that when osrmTable fails, the server does not get any request.

What could be causing this issue? This question is somewhat related to the older issue #4.

sf to sp problem in osrmIsochrones()

Hi there,

Thank you! This solved the error.

However, I ran into another problem with this set of coordinates, also in London:

test <- osrmIsochrone(loc = c(-2.4529553,52.71386), 
                           breaks = seq(from = 0,to=8,by=8))

For this, the error is:

Error in .as_Spatial(from, cast, IDs) : 
  conversion from feature type sfc_GEOMETRY to sp is not supported

This same error occurs for other few sets of coordinates that I have too.

Not sure what this means. Would appreciate your help, thank you!!

Originally posted by @jiaweniscute in #44 (comment)

Are there any way to get a bulk of distances?

Hello, I am a happy user of osrm's R package.
I am trying to get a matrix of distances and a matrix of durations between 4000 points.
The matrix of duration is easy to get. I can use the osrmTable function to get the duration of multiple start points and multiple destinations.
However, for the distance, I can only get one value of distance between two points every execution of osrmRoute() function. It will take weeks for me to get the entire matrix.
Could you please tell me if there's a better way to get the matrix of distances?

Routing with my points

Just trying this out and getting an error:

origin = tmap::geocode_OSM("Bradford")
destination = tmap::geocode_OSM("Leeds")
ro = osrmRoute(origin, destination)
osrmRoute function returns an error: 
Error: URL string malformed close to position 31: "73, 51"

Any ideas?

specific invalid coordinate issue with osrmIsochrone

Hi There,

Thank you for the awesome package first of all! Really helpful!

I am trying to obtain an area around this particular coordinate in London with the following code:

test <- osrmIsochrone(loc = c(0.0370781,51.48189), breaks = seq(from = 0,to=8,by=8))

I am not sure why but this is giving the following error:

The OSRM server returned an error:
Error: InvalidInput
Coordinate is invalid: -9.4e-05,51.407237

The OSRM server returned an error:
Error: InvalidInput
Coordinate is invalid: -9.4e-05,51.458735

The OSRM server returned an error:
Error: InvalidInput
Coordinate is invalid: -9.4e-05,51.510175

Error in UseMethod("st_as_sf") : 
  no applicable method for 'st_as_sf' applied to an object of class "NULL"

Any advice would be appreciated!

Thank you so much!

osrmIsochrone is breaking

The code is breaking

If I run the osrmIsochrone() function then the code breaks. See below:

suppressPackageStartupMessages(library(osrm))

# Load data
data("com")

# Get isochones with a SpatialPointsDataFrame, custom breaks
iso <- osrmIsochrone(loc = src[6,], breaks = seq(from = 0,to = 30, by = 5))
## Error in rbind2(..1, r): no method for coercing this S4 class to a vector

Here is my session info

sessionInfo()
## R version 3.3.3 (2017-03-06)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.2 LTS
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] osrm_3.0.1
## 
## loaded via a namespace (and not attached):
##  [1] gepaf_0.1.0     Rcpp_0.12.10    lattice_0.20-35 digest_0.6.12  
##  [5] rprojroot_1.2   bitops_1.0-6    grid_3.3.3      jsonlite_1.3   
##  [9] backports_1.0.5 magrittr_1.5    evaluate_0.10   stringi_1.1.2  
## [13] raster_2.5-8    sp_1.2-4        rmarkdown_1.3   rgdal_1.2-5    
## [17] tools_3.3.3     stringr_1.2.0   RCurl_1.95-4.8  yaml_2.1.14    
## [21] rgeos_0.3-23    htmltools_0.3.5 knitr_1.15.1

Paths along waterways

Hi, I am a fish biologist tracking fish species via detection stations in various waterways such as rivers, canals and ditches. I would like to calculate the swim distance between the subsequent detection stations in the waterways. Is there any way to do it with this package?

Isometric map

Hey! Is there any possibility of getting an isometric map, with diriving distance rings instead of driving time?

Immediate error message

Immediate error message

Thanks for this awesome package, I use it a lot to get road distances for my current project. I used to get error messages like this usually if I sent many coordinate pairs (approx. 10000) but since a week ago I immediately get the following message, without any distances/duration returned:
OSRM returned an error:
Error in if (res$code != "Ok") {: argument is of length zero

Error in osrm@data :
trying to get slot "data" from an object of a basic class ("NULL") with no slots

I think it was a API thing before but since it doesn’t work at all anymore, maybe you have any advice how to deal with it?
If it helps, here’s the code I send (to get all IDs I need I write all results into a dataframe, didn't use to be a problem before either):

dist <- data.frame(CID=distdat$CID, zipstart=distdat$zip, ptend=distdat$id, duration=NA, length=NA)
for (i in 1:15000)
{ osrm <- osrmRoute (src = distdat[i, c("zip","x","y")],
dst = distdat[i, c("id","long","lat")], sp="TRUE")
dist[i,4] <- osrm@data[1,3]
dist[i,5] <- osrm@data[1,4]
}

THANK YOU!!

Multiple polygons created with Isochrone

Hi,
I am trying to create some isochrones with the package, but the resulting map always includes more than 1 polygons for a single point. Is there a reason why multiple polygons rather than just one are created?

The code I am using looks similar to the package sample:
iso <- osrmIsochrone(loc = c(36.8032934, -1.2567891), breaks = seq(from = 0, to = 10, by = 10), res = 100)

rplot

Large requests to local server

The osrmTable() and osrmTableOD() commands to my local server are still limited to 100, even when using the limit function to increase the limit:

table2 <- osrmTable(distance[1:100,], id = "URN", x = "Long", y = "Lat")
table3 <- osrmTable(distance[1:101,], id = "URN", x = "Long", y = "Lat")
osrmTable function returns an error: 
Error in dimnames(mat) <- list(df[, id], df[, id]): attempt to set an attribute on NULL

With the limit function to increase the limit:

travel.times <- osrmTableOD(dfo = distance[1:520,], ido = "URN", xo = "Long", yo = "Lat", dfd =     distance[1:520,], idd = "nid", xd = "NLong", yd = "NLat", limit = 3257)
osrmTable function returns an error: 
Error in dimnames(mat) <- list(df[, id], df[, id]): attempt to set an attribute on NULL

Is there something else that I need to change to get around this limit?

Receiving this error- osrmTable function returns an error: Error: The URL sent to the OSRM public API is too long. Enter less sources or destinations

Hi, first off, thanks for the awesome package!

I'm new to this package and have been experimenting with osrm . I tried the example code for osrmTable(). Namely:

data("com")
distCom2 <- osrmTable(src = com[1:10,c("comm_id","lon","lat")],
dst = com[11:20,c("comm_id","lon","lat")])

This exact code worked just fine yesterday, however, when I try now, it is giving me this error:

osrmTable function returns an error:
Error: The URL sent to the OSRM public API is too long. Enter less
sources or destinations.

I tried reducing the number of sources & destinations to one:

home = data.frame(001, -118.454642, 34.069432)
work = data.frame(002, -118.260938, 34.049268)
test = osrmTable(src=home, dst=work)

however, I am still receiving the same error. Trying all the other example codes within osrmTable() such as:
distCom <- osrmTable(loc = com[1:50, c("comm_id","lon","lat")])

also gives me the same error. I was hoping you could help me figure out a solution to this error and hopefully explain why this error did not appear before. Thanks in advance!

Error in if (any(idx)) { : missing value where TRUE/FALSE needed

I get the following error message when I try to generate isochrones for the point given below (in Bethel, Alaska):

iso <- osrmIsochrone(loc = c(-161.8703202,60.76931), breaks = seq(from = 0,to = 60, by = 20))
Error in if (any(idx)) { : missing value where TRUE/FALSE needed

When I try adjusting the to and by values to less than 10 minutes (e.g. to = 60, by = 20) ), the command works. I suspect this is because the roads in Bethel, Alaska, don't extend much beyond 10 minutes of travel time. Can you confirm that this is the reason for the error message?

If this is so, I would have expected that osrmIsochrone would at least return the isochrones for which there were non-missing, valid travel times. Or an option so that I could set osrmIsochrone to return the maximum travel time within a closed road network, given certain min/max/break parameters.
And perhaps a more descriptive error message.

If I have to plot 1,000 isochrones within Alaska, Hawaii, or other isolated areas for analysis, this is an error that's going to come up a lot — without a clear or systematic way of resolving it yet.

Requests for distance & time

How many requests can be made? I have about 500 points and I would like to check the time and distance between each point, is there a problem if I make the request? It will be about 500*499/2 single requests.

Travel time equals zero using osrmTable() in R

Hello, I try to use the osrm package in R to get the travel time matrix. I tried with both my own dataset and the example in README. Both time I got a travel time matrix (duration) equal zero
`data("com")

distCom <- osrmTable(loc = com[1:50, c("comm_id","lon","lat")])
distCom$durations[1:5,1:5]
FR3162292119 FR3162212035 BE241011 BE241024 FR3162270520
FR3162292119 0 0 0 0 0
FR3162212035 0 0 0 0 0
BE241011 0 0 0 0 0
BE241024 0 0 0 0 0
FR3162270520 0 0 0 0 0`

Then I check distcom$destinations and distcom$sources, found they all have the same coordination.

` distCom$destinations[1:5,]
lon lat
FR3162292119 -114.1306 34.27882
FR3162212035 -114.1306 34.27882
BE241011 -114.1306 34.27882
BE241024 -114.1306 34.27882
FR3162270520 -114.1306 34.27882
distCom$sources[1:5,]
lon lat
FR3162292119 -114.1306 34.27882
FR3162212035 -114.1306 34.27882
BE241011 -114.1306 34.27882

BE241024 -114.1306 34.27882

FR3162270520 -114.1306 34.27882
com[1:5,]
comm_id name lon lat
1 FR3162292119 Bethune 2.647810 50.51990
2 FR3162212035 Annezin 2.619300 50.54150
3 BE241011 Denderleeuw 4.071241 50.88721
4 BE241024 Haaltert 4.005772 50.90225
5 FR3162270520 Locon 2.666170 50.57050`

can you please tell me what went wrong?

The OSRM Demo Server is down

Since the OSRM Demo Server is down and the Mapbox API is used as the official OSRM demo instead. It is not clear for me how can I use this API through the osrm-package?

Error on example code

When I run the code :
# Load data
data("com")
# Travel path between points
route <- osrmRoute(src = com[1, c("comm_id", "lon","lat")],
dst = com[15, c("comm_id", "lon","lat")])

I get the following error:

osrmRoute function returns an error:
Error: parse error: premature EOF

(right here) ------^

I looked around and found that it could be the OSM server - perhaps this is indeed it. You refer to this site: https://github.com/Project-OSRM/osrm-backend/wiki/Building-OSRM

But you don't say how to use it, once I have the repo cloned, then what? How do I "link" R to this?

I am sorry, I am not a full stack coder, this goes beyond my skill level and would really appreciate some help.

Thanks!

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.