1

I have been using osrm package for a while and didn't ever come across this kind of issue before. It looks so weird and I have been trying to update package and reinstall R as well. But nothing is working. Can someone, guide where am I doing wrong, please.

Code:

library(sf)
data("berlin")
# Get isochones with lon/lat coordinates
iso <- osrmIsochrone(loc = c(13.43,52.47), breaks = seq(0,14,2),
                     returnclass="sf")

Error:

Error: lexical error: invalid char in json text.
                                       <!DOCTYPE HTML PUBLIC "-//IETF/
                     (right here) ------^


The OSRM server returned an error:
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE HTML PUBLIC "-//IETF/
                     (right here) ------^


The OSRM server returned an error:
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE HTML PUBLIC "-//IETF/
                     (right here) ------^


Error in UseMethod("st_as_sf") : 
  no applicable method for 'st_as_sf' applied to an object of class "NULL" ```
1
  • This happens to me too so its not your fault. The server is returning an HTML response instead of the expected data (in JSON format) so the package can't understand it. This usually happens when a server gets overloaded or decides to refuse your request for other reasons. If I can get the package to save the full response from the server it should be possible to see the whole reason, but the error is only showing the first line of the response. – Spacedman Aug 19 '20 at 7:17
0

This has been reported to the authors via an issue: https://github.com/rCarto/osrm/issues/63 (which maybe you posted?).

The lastest version on github fixes this. If you install devtools then you can get this quite easily with:

> devtools::install_github("rCarto/osrm")

but then running the example threw up another error for me, namely:

Error in st_make_valid(st_geometry(iso)) : 
  could not find function "st_make_valid"

which I fixed for me by doing library(lwgeom) which is where st_make_valid comes from. I've also reported that as another issue to github for the authors. Suggest you watch that space for developments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.