Is it possible to bring a sequence of matching dots using the graphhopper map-matching application?

I’ve successfully installed and sent a gpx file to graphhopper and I got the following json result:

{"hints":{},"info":{"copyrights":["GraphHopper","OpenStreetMap contributors"],"took":0},"paths":[{"distance":5339.005,"weight":9.223372036854775E12,"time":450291,"transfers":0,"points_encoded":true,"bbox":[-46.638765,-23.559783,-46.614062,-23.538809],"points":"pltnCfat{Gh@`AbPmKXY`@OxBUDG@GESaCo@mDgA`EcDDDf@j@JPmAfDmDgA`EcDDDf@j@JPbBjAf@Vp@VX]P]@IAQKQk@[}EyBg@IgB{@w@aAwA{CG_@iAuLfMb@L{ALoGh@PXRnAVjAJj@Jt@`@`BjAn@\\ZH~@D|@Gf@OfHkElA}@h@c@~@m@bA]h@GbCAfB@VAz@QhAc@ZIhAm@vBcAv@YTQV[r@kAl@gA|I}Hr@u@lA{An@cApA_Ch@oAl@cBfC_LpFyV^oAf@qA|@iB|@qA~@cA","instructions":[{"distance":40.863,"heading":235.0,"sign":0,"interval":[0,1],"text":"Continue onto Rua Aurora","time":2942,"street_name":"Rua Aurora"},{"distance":474.111,"sign":-2,"interval":[1,5],"text":"Turn left onto Rua Santa Ifigênia","time":56887,"street_name":"Rua Santa Ifigênia"},{"distance":20.083,"sign":-7,"interval":[5,8],"text":"Keep left","time":1806,"street_name":""},{"distance":180.298,"sign":-2,"interval":[8,10],"text":"Turn left onto Rua Brigadeiro Tobias","time":18542,"street_name":"Rua Brigadeiro Tobias"},{"distance":136.112,"sign":3,"interval":[10,11],"text":"Turn sharp right onto Rua Riskallah Jorge","time":13998,"street_name":"Rua Riskallah Jorge"},{"distance":4.096,"sign":2,"interval":[11,12],"text":"Turn right onto Avenida Prestes Maia","time":327,"street_name":"Avenida Prestes Maia"},{"distance":43.368,"sign":7,"interval":[12,14],"text":"Keep right onto Avenida Prestes Maia","time":2401,"street_name":"Avenida Prestes Maia"},{"distance":96.057,"sign":2,"interval":[14,15],"text":"Turn right onto Praça Pedro Lessa","time":11525,"street_name":"Praça Pedro Lessa"},{"distance":104.176,"sign":2,"interval":[15,16],"text":"Turn right onto Rua Brigadeiro Tobias","time":10713,"street_name":"Rua Brigadeiro Tobias"},{"distance":136.112,"sign":3,"interval":[16,17],"text":"Turn sharp right onto Rua Riskallah Jorge","time":13998,"street_name":"Rua Riskallah Jorge"},{"distance":4.096,"sign":2,"interval":[17,18],"text":"Turn right onto Avenida Prestes Maia","time":327,"street_name":"Avenida Prestes Maia"},{"distance":166.338,"sign":7,"interval":[18,23],"text":"Keep right onto Avenida Prestes Maia","time":9209,"street_name":"Avenida Prestes Maia"},{"distance":319.745,"sign":-2,"interval":[23,32],"text":"Turn left","time":19306,"street_name":""},{"distance":383.564,"sign":7,"interval":[32,36],"text":"Keep right onto Avenida Prestes Maia","time":43337,"street_name":"Avenida Prestes Maia"},{"distance":254.259,"sign":3,"interval":[36,37],"text":"Turn sharp right onto Rua Barão de Duprat","time":30506,"street_name":"Rua Barão de Duprat"},{"distance":186.557,"sign":-2,"interval":[37,39],"text":"Turn left onto Rua Comendador Assad Abdalla","time":22384,"street_name":"Rua Comendador Assad Abdalla"},{"distance":677.215,"sign":3,"interval":[39,54],"text":"Turn sharp right onto Avenida do Estado, BR-050","time":34823,"street_name":"Avenida do Estado, BR-050"},{"distance":180.335,"sign":7,"interval":[54,58],"text":"Keep right","time":9986,"street_name":""},{"distance":323.713,"sign":-7,"interval":[58,66],"text":"Keep left","time":18657,"street_name":""},{"distance":83.13,"sign":-7,"interval":[66,69],"text":"Keep left","time":6650,"street_name":""},{"distance":1524.777,"sign":7,"interval":[69,84],"text":"Keep right","time":121967,"street_name":""},{"distance":0.0,"sign":4,"last_heading":137.57862576681327,"interval":[84,84],"text":"Arrive at destination","time":0,"street_name":""}],"legs":[],"details":{},"ascend":0.0,"descend":0.0,"snapped_waypoints":""}],"map_matching":{"original_distance":5416.372399303108,"distance":5339.0048843159975,"time":450291}}

I’ve used the following curl command to get this result:

curl -XPOST -H "Content-Type: application/gpx+xml" -d @myfile.gpx "localhost:8989/match?vehicle=car&type=json"

I’d like to know if I can tweak this json output to different formats. For me, it’d be useful if it could return a sequence of gps points that match the lines of dots from the original file. Is there any configuration I can change to accomplish that? If not, where in the code I should be looking in order to make the necessary changes and make it work for me?

This should work when you POST it towards localhost:8989/match?vehicle=car&type=gpx.

Thanks!! With the gpx request I have the dots… I still have two doubts about what I can do with the map-matching:

1- Can I get a sequence of points in the json format instead of the gpx? Or do I need to convert it outside map-maching? If I can get these points directly in the json format, what’s the general idea of what I have to do to accomplish that?
2- I’ve attached the input file I’m using here in my answer… When I get the gpx result, even though I get the gps points to create the path the final result is still greatly reducing the amount of points that I have on my original file (myfile.gpx). Is it possible to configure it in a way that the request result will give me exactly the same amount of points that I have on my original file?

Sorry about the simple questions… I’ve found out about graphhopper yesterday and I’m still learning its functionalities… :upside_down_face:

myfile.gpx (57.0 KB)

Yes, that was what you did before with type=json. See the points array, if you use points_encoded=false. If you use the default or points_encoded=true then this is an encoded polyline string that you need to decode first:

Please use the correct decoding method. E.g. in JavaScript:

and Java:

Is it possible to configure it in a way that the request result will give me exactly the same amount of points that I have on my original file?

This is not possible. You should still be able to find the corresponding points on the resulting route with some geometric functions.

1 Like

Thanks again! I’ve managed to get the list of points directly in JSON… Is there any documentation page where I can read about the POST parameters that I can use? I didn’t manage to find it on graphhopper’s webpage… :thinking:

My last question is: Can I POST files in formats different from gpx? Like csv or json? I’ve tried sending a json with a list of points on the web application that runs on the port 8990 but it returned me an error… Also, the sample files inside map-matching/matching-web/target/test-classes are all gpx. So, is it possible to use a different file format as input?

See on github the ‘Get Started’ -> documentation -> web -> Routing API

Can I POST files in formats different from gpx?


1 Like