Problem with self-hosted server connection
asitemade4u opened this issue · 11 comments
Hi,
I have issues executing osrm::osrmNearest
with my self-hosted OSRM server.
Here are the details:
- I self host an OSRM server using docker.
- I just changed the port to
5111
as it was colliding with another of my self-hosted servers.
Nevertheless, it works fine and responds to acurl
to its local IP address (192.168.1.16:5111
) such as:
curl "192.168.1.16:5111/route/v1/foot/40.6476940,-73.9803640;40.6551440,-74.0035490?steps=true"
I assume the OSRM API responds well then.
- I also did not turn on the GUI of the OSRM server in my
docker-compose.yml
file.
- I installed the
osrm
plugin in R. My R installation is also served by a self-hosted server using CodeServer -- and works just fine. - I followed your instructions on how to connect the plugin with the server (notably the trailing
/
). - I executed the above
curl
instruction from thebash
terminal of my R coding environment and it returned a correct result. So I assume I can connect to the API from my development environment, from where the below code is executed. - The R code I am using is straightforward:
- I define the server and the profile:
options(osrm.server = "192.168.1.16:5111/")
options(osrm.profile = "foot")
- I load trackpoint coordinates (lat/lon) from a Postgis database, among other relevant data columns, into a dataframe,
thetmp
- I transform
thetmp
into asf
geometry usingsf::st_as_sf
: the columnthetmp$geometry
replaces the two coordinate columns, as a result. - Lastly, I loop all the rows of
thetmp
dataframe and add nearest coordinates of each trackpoint into a new column to the dataframe,thetmp$new
:
thetmp$new[i] <- osrm::osrmNearest(loc = thetmp$geometry[i], osrm.server = getOption("osrm.server"), osrm.profile = getOption("osrm.profile")
- I get no error while executing but the outcome of each cell in the
new
dataframe column is always the same, and obviously not what I was expecting:
[[1]]
[1] "loc"
What am I doing wrong?
S.
PS1. I also tried to prefix the server address with http://
but it yields the same result.
PS2. Nous pouvons communiquer en Français si cela est plus facile pour vous, car je suis un compatriote vivant aux US. ;o))
Hello, I'm AFK right now, I'll have a look at it in early September.
Do other functions work (e.g. osrmRoute() or osrmTable())?
Hi,
Are you back to the keyboard?
And to answer your question belatedly, yes, I get results when I call OSRM from curl like so:
curl "<server-ip>:5111/route/v1/foot/40.6476940,-73.9803640;40.6551440,-74.0035490?steps=true"
Thank you for your help,
S.
Ok thanks,
Does this snippet work ?
library(osrm)
osrmRoute(src = c(-73.9803640, 40.6476940), dst = c(-74.0035490, 40.6551440),
osrm.server = "http://192.168.1.16:5111/",
osrm.profile = "foot")
That said, when I input http://192.168.1.16:5111/
in my browser, I get this error message from OSRM:
{"message":"URL string malformed close to position 1: \"\/\"","code":"InvalidUrl"}
And yet I am positive that is the address on which OSRM is published. Here is the docker-compose.yml
file:
version: "3"
services:
osrm-backend:
image: osrm/osrm-backend:latest
container_name: rte
restart: unless-stopped
command: "osrm-routed --algorithm mld /data/nyc.osrm"
volumes:
- "/mnt/sam/cch/rte:/data"
ports:
- 5111:5000
labels:
- com.centurylinklabs.watchtower.enable=true
And the container's log shows no error.
That said, when I input
http://192.168.1.16:5111/
in my browser, I get this error message from OSRM:{"message":"URL string malformed close to position 1: \"\/\"","code":"InvalidUrl"}
This message is returned by OSRM, so it's OK. OSRM is published and accessible at this address...
Anyway the problem does not seem to be linked specifically to osrmNearest()
. I'll change the label of the issue.
hey there,
i have exactly the same problem. when I run your example I get
> travel_time$durations[1:5,1:5]
1 2 3 4 5
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0
each time. what's weird is this:
> travel_time$sources[1:5,]
lon lat
1 0.337306 51.54285
2 0.337306 51.54285
3 0.337306 51.54285
4 0.337306 51.54285
5 0.337306 51.54285
> travel_time$destinations[1:5,]
lon lat
1 0.337306 51.54285
2 0.337306 51.54285
3 0.337306 51.54285
4 0.337306 51.54285
5 0.337306 51.54285
when in reality those should be (when I use the online routing server)
> travel_time$sources
lon lat
1 13.43857 52.47726
2 13.57897 52.45815
3 13.49047 52.61726
4 13.51960 52.49760
5 13.45592 52.50109
6 13.33849 52.49470
similarly:
> osrmRoute(src = c(-73.9803640, 40.6476940), dst = c(-74.0035490, 40.6551440),
+ osrm.server = "http://127.0.0.1:5001/",
+ osrm.profile = "foot")
Simple feature collection with 1 feature and 4 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -0.5152 ymin: 51.46248 xmax: -0.5152 ymax: 51.46248
Geodetic CRS: WGS 84
src dst duration distance geometry
src_dst src dst 0 0 LINESTRING (-0.5152 51.4624...
always returns zero distance.
the API seems to run correctly:
floswald@PTL11077 ~/D/r/B/D/shapefiles> curl "http://127.0.0.1:5001/route/v1/driving/51.462,-0.038;51.55,-0.097?steps=true" (base)
{"code":"Ok","routes":[{"geometry":"cb`xHqqQ??","legs":[{"steps":[{"geometry":"cb`xHqqQ??","maneuver":{"bearing_after":133,"bearing_before":0,"location":[0.09513,51.287537],"type":"depart"},"mode":"driving","driving_side":"right","name":"Hogtrough Hill","intersections":[{"out":0,"entry":[true],"bearings":[133],"location":[0.09513,51.287537]}],"weight":0,"duration":0,"distance":0},{"geometry":"cb`xHqqQ","maneuver":{"bearing_after":0,"bearing_before":133,"location":[0.09513,51.287537],"type":"arrive"},"mode":"driving","driving_side":"right","name":"Hogtrough Hill","intersections":[{"in":0,"entry":[true],"bearings":[313],"location":[0.09513,51.287537]}],"weight":0,"duration":0,"distance":0}],"summary":"Hogtrough Hill","weight":0,"duration":0,"distance":0}],"weight_name":"routability","weight":0,"duration":0,"distance":0}],"waypoints":[{"hint":"_GQCgCNlAoAJAAAAAAAAALEGAAAAAAAAVyxQQAAAAACuoxREAAAAAAUAAAAAAAAAVwMAAAAAAACbAQAAmnMBAPGVDgNwPxEDkGv__xMAXwiiZDlw","distance":7677559.389826364,"name":"Hogtrough Hill","location":[0.09513,51.287537]},{"hint":"_GQCgCNlAoAJAAAAAAAAALEGAAAAAAAAVyxQQAAAAACuoxREAAAAAAUAAAAAAAAAVwMAAAAAAACbAQAAmnMBAPGVDgMwlxIDGIX-_xMAXwiiZDlw","distance":7689755.214539866,"name":"Hogtrough Hill","location":[0.09513,51.287537]}]}⏎
oh no, just realised that the API is returning zero distance all the time! so that's the problem here...
nevermind, I reconfigured the package in a new location and on a new openstreetmap, now it works. strangely only the R package works, the curl calls always return zero distance...
Hi @asitemade4u ,
Have you solved the problem?
Hi,
As I am now using several other RiateLab tools with success, I gave osrm
a new try.
And, yes, to answer your question, it works now.
Case closed.