Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: InvalidQuery Query string malformed close to position 6249 #52

Closed
Christoph999 opened this issue Oct 2, 2019 · 10 comments
Closed

Comments

@Christoph999
Copy link

Christoph999 commented Oct 2, 2019

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!

@rCarto
Copy link
Member

rCarto commented Oct 3, 2019

Hello,
Thank you for raising this issue.
Are you using your own OSRM server ? With the driving profile?
Also, it would be helpful to have the values of i, lngs, lats, breaks and res.

@Christoph999
Copy link
Author

Christoph999 commented Oct 3, 2019

Hi, Thanks for your reply. Don't hestite to conatct me, in case you need further details:

the data (from RStudio)

structure(list(PLZ = NA, Stadt = "Erstfeld", Breite = 46.81236378, 
    Laenge = 8.599465297), class = "data.frame", row.names = c(NA, 
-1L))

The relevant code sequence:

library(osrm)
library(sf)
res_isochrones <- 50
breaks_isochrones <- seq(90, 120, 30)
path <- paste0(getwd(), "/rawdata/")
map_name = "switzerland-latest"
osrm_path = "C:/OSRM_API5"
filename <- paste0(path, "LagerErstfeld.csv")
datenLager <- read.csv(filename, sep = ";", stringsAsFactors = FALSE)
r <- calculate_isochones(names = datenLager$PLZ, lats = datenLager$Breite[1], 
                         lngs = datenLager$Laenge[1],
                         breaks = breaks_isochrones, 
                         res = res_isochrones, 
                         map_name = map_name,
                         osrm_path = osrm_path) 

calculate_isochones <- function(names, lats, lngs, breaks = seq(5,20,5), res = 50, 
                                map_name, osrm_path) {
  options(osrm.server = paste0(osrmr:::server_address(TRUE), "/"), osrm.profile = "driving")
  osrmr::run_server(paste0(map_name, ".osrm"), osrm_path)
  parameters <- list(Names = names, 
                     Lattitudes = lats, 
                     Longitudes = lngs,
                     Breaks = breaks, 
                     Resolution = res)
  isochrone_list <- list()
  for (i in 1:length(lats)) {
    isochrone_list[[i]] <- osrm::osrmIsochrone(c(lngs[i], lats[i]), breaks, res)
  }
  names(isochrone_list) <- names
  isochrone_list <- list(parameters, isochrone_list)
  osrmr::quit_server()
  return(isochrone_list)
}

We use R and a local version of OSRM running on Windows (API5).
The API seems find and I figured out, that in your function, everything seems to be ok until req <- tableLoc(loc = loc, gepaf = gepaf) in osrmTable().

@rCarto
Copy link
Member

rCarto commented Oct 3, 2019

Ok I see it.
Since v3.2.0, a new parameter has been added in osrmIsochrone() (exclude, between breaks and res) .
I you use explicitly named argument the function should work. Something like :

osrm::osrmIsochrone(loc = c(lngs[i], lats[i]), breaks = breaks, res = res)

Sorry for the breaking change, I should have added the new param at the end of the list...

@Christoph999
Copy link
Author

Still the same issue in

isochrone_list[[i]] <- osrm::osrmIsochrone(loc = c(lngs[i], lats[i]),
                                           breaks = breaks, res = res)

results in

The OSRM server returned an error:
Error: InvalidQuery
Query string malformed close to position 6309

8x the same message...

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

@Christoph999
Copy link
Author

Christoph999 commented Oct 3, 2019 via email

@rCarto
Copy link
Member

rCarto commented Oct 4, 2019

Using the demo server and the coordinates you sent me I get:

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.7.1, GDAL 2.4.0, PROJ 5.2.0
res <- 50
breaks <- seq(90, 120, 30)
loc <- c(8.599465297, 46.81236378)
iso <- osrmIsochrone(loc = loc, breaks = breaks, 
                     res = res, returnclass = "sf")
plot(st_geometry(iso), col = c("lightblue1", "lightblue3"))
points(loc[1], loc[2], pch = 20, col = "red")

Created on 2019-10-04 by the reprex package (v0.3.0)

But I don't know what's in the "LagerErstfeld.csv" file...

@Christoph999
Copy link
Author

Christoph999 commented Oct 4, 2019

Ok, so it is definitely related to the local OSRM:

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.6.1, GDAL 2.2.3, PROJ 4.9.3
res <- 50
breaks <- seq(90, 120, 30)
loc <- c(8.599465297, 46.81236378)
iso <- osrmIsochrone(loc = loc, breaks = breaks, 
                     res = res, returnclass = "sf")
plot(st_geometry(iso), col = c("lightblue1", "lightblue3"))
points(loc[1], loc[2], pch = 20, col = "red")

Everything works!
Then:

map_name = "switzerland-latest"
osrm_path = "C:/OSRM_API5"
options(osrm.server = paste0(osrmr:::server_address(TRUE), "/"), osrm.profile = "driving")
osrmr::run_server(paste0(map_name, ".osrm"), osrm_path)  # a wrapper for a shell command. See below...
res <- 50
breaks <- seq(90, 120, 30)
loc <- c(8.599465297, 46.81236378)
iso <- osrmIsochrone(loc = loc, breaks = breaks, 
                     res = res, returnclass = "sf")
# The OSRM server returned an error:
# Error: InvalidQuery
# Query string malformed close to position 6285
...
Error in UseMethod("st_as_sf") : 
  no applicable method for 'st_as_sf' applied to an object of class "NULL"

From our local API (Which is working, this is the command from osrmr::run_server()):

C:\OSRM_API5>osrm-routed switzerland-latest
[info] starting up engines, v5.10.0[0m
[info] Threads: 8[0m
[info] IP address: 0.0.0.0[0m
[info] IP port: 5000[0m
[info] load names from: "switzerland-latest.osrm.names"[0m
[info] set checksum: 384967193[0m
[info] http 1.1 compression handled by zlib version 1.2.8[0m
[info] Listening on: 0.0.0.0:5000[0m
[info] running and waiting for requests[0m

I hope that helps! I already checked, whether the OSRM API interfaced changed since 5.10, but I couldn't find anything.

@rCarto
Copy link
Member

rCarto commented Oct 4, 2019

So that's it, I try to keep the osrm package in line with the latest version of OSRM served via Docker (name: latest in images on Docker Cloud, https://github.com/Project-OSRM/osrm-backend#using-docker). The version announced is currently 5.22.0.

In version 5.18.0 (https://github.com/Project-OSRM/osrm-backend/blob/master/CHANGELOG.md#5180) a new param annotation has been added to the table service.
Accordingly osrmTable() gained this new parameter. Changing things around here: https://github.com/rCarto/osrm/blame/master/R/osrmTable.R#L118 would probably solve your problem.

I do not plan to modify the package to work with older version of OSRM (v.5.18.0 is from 10 May 2018, v5.10.0 is from 7 Aug 2017).

The strategy with osrm is to follow the latest version and the demo version of OSRM.

My suggestion here would be to update OSRM to the latest version (and I guess it could be bothersome in Window$ OS...). Or to use an old version of osrm (but, notably, osrmIsochrone() has improved with the last 2-3 verisons).

@Christoph999
Copy link
Author

Thanks again for your great support! I understand and I consider this issue as solved.

@rCarto
Copy link
Member

rCarto commented Oct 4, 2019

All right

@rCarto rCarto closed this as completed Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants