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

plugin fails to transform clicked coordinates #2

Closed
caido160 opened this issue Jan 25, 2021 · 12 comments
Closed

plugin fails to transform clicked coordinates #2

caido160 opened this issue Jan 25, 2021 · 12 comments

Comments

@caido160
Copy link

When using your own localhost valhalla the access_token parameter gives http 400 error. Is it possible to make key parameter optional for easier use?

ApiError: (400 (Error transferring http://localhost:8002/route/route?access_token= - server replied: Bad Request))
http://localhost:8002/route/route?access_token=
Parameters:
{ "costing": "auto", "narrative": false, "id": 1, "locations": [ { "lon": 544290.101836, "lat": 6586980.218267 }, { "lon": 658140.446643, "lat": 6472558.717883 } ] }
timing: 0.030 secs

@nilsnolde
Copy link
Owner

It’s not the token. You have some weird coordinate system.. Is it defined in qgis? The built in map tool should transform that to wgs84 when you click in the canvas, which only works if the CRS is known to qgis.

@nilsnolde
Copy link
Owner

It did happen to me too before (the plugin not transforming my coords when I click) and I'm not sure why that happens and don't have the time right now to look into it, but will fairly soon.. For me it's solved when I reload QGIS.

@nilsnolde nilsnolde changed the title access token parameter on local valhalla server plugin fails to transform clicked coordinates Jan 26, 2021
@caido160
Copy link
Author

these are lest97 (3301) coordinates. I didn't realise it was converting until now :).
But the problem is with access-token paramter that the tool is puting to get parameter.
When I modified valhalla/common/client.py file and changed url construction then it worked perfectly :)
I changed from this:

 # Define the request
        params = {'access_token': self.key}
        authed_url = self._generate_auth_url(url,
                                             params,
                                             )
        url_object = QUrl(self.base_url + authed_url)
        self.url = url_object.url()
        body = QJsonDocument.fromJson(json.dumps(post_json).encode())
        request = QNetworkRequest(url_object)
        request.setHeader(QNetworkRequest.ContentTypeHeader, 'application/json')

to this (just changed url_object - just a hack not a fix :) ):

 # Define the request
        params = {'access_token': self.key}
        authed_url = self._generate_auth_url(url,
                                             params,
                                             )
        url_object = QUrl(self.base_url)
        self.url = url_object.url()
        body = QJsonDocument.fromJson(json.dumps(post_json).encode())
        request = QNetworkRequest(url_object)
        request.setHeader(QNetworkRequest.ContentTypeHeader, 'application/json')

@nilsnolde
Copy link
Owner

huh, really? I use the tool almost every day on localhost and it has never been a problem. And it really shouldn't be, Valhalla ignores query parameters for POST. I'll do the fix though, it's just cleaner anyways.

Can you please have a look into the (docker) logs for Valhalla? It should tell what the problem is. Because your request coordinates are definitely not right (valhalla only accepts geodesic).

I should find a way to get back the real error message for 400, didn't figure out how to do yet back then.

@nilsnolde
Copy link
Owner

BTW, it also prints the coordinates it "transformed" (or not) to the GUI. Or are you using the processing algos?

@caido160
Copy link
Author

I tried again and found that it will transform input point coodrinates when I open tool after I add my wms basemap (and opening my wms map sets map projection to 3301)
image

But if open valhalla tool before and wms after that (seting map projection after opeing tool) then it won't trasform my coordinates.
image

@caido160
Copy link
Author

And I found out why I had problems at first. My bad :)
When i copied my url to Base URL under settings I copied too much
instead of http://localhost:8002 I used http://localhost:8002/route wich means in the end that path "/route" was double)

It is even in my original post:
"
ApiError: (400 (Error transferring http://localhost:8002/route/route?access_token= - server replied: Bad Request))
http://localhost:8002/route/route?access_token=
"

@nilsnolde
Copy link
Owner

aah:) yeah totally overlooked that part of the URL as well..

I experienced that as well, but it felt much more random than that (qgis crashes sooo often for me on arch linux, I thought it might just be another of those individual failures only I experience;)), so your insight proves super valuable! I could reproduce here. Must be in the initialization then, apparently I don't grab the CRS dynamically, which I should of course! Thanks for the input!

@sanderpukk
Copy link

sanderpukk commented Jan 29, 2021

I had the same problem when first firing up the Valhalla plugin. Changed the project SRID to 3301 and then loaded a WMS background. Opened Valhalla plugin and the same url. The error was the same. Token = -.

It would still be better if that token is not hard-coded and would be optional.

@nilsnolde
Copy link
Owner

@sanderpukk can you update the plugin pls and try again (version 2.2.0)? The fix was approved yesterday night.

Again, it really shouldn't be a problem with query parameters.

@sanderpukk
Copy link

I installed it today minutes before posting. After reinstalling the query worked again, but it didnt on the first try.

@nilsnolde
Copy link
Owner

so weird.. I really can't reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants