3

Beginner alert.

I was given a set of encoded polylines that I need to import into a QGIS project. I understand what encoded polylines are but now I am stuck with how to decode them into some usable formats (I assume csv files?) in order to import into QGIS.

I did some research but have only found resources around encoding the data but not the other way around.

https://developers.google.com/maps/documentation/utilities/polylineutility

^seems to do what I want but I need to download the polylines in a format that can be imported into QGIS.

Here's an example: "_{reFxmjVpAeBn@{@w@aAc@m@yAsBJuAC}BIeAO_Ak@sBCQOg@g@aAk@}@qAwAs@s@}I{JgCqCsC_D}DeEyDgEsA}AwB{BcCwCoGyGqBwByEwFgHqHgDqDkIaJyFuGeEsEeEcEcGkGkEaFyDyDgBqBcAgAm@y@w@gAuCcCmFeHk@i@eAgAaDaDcC_CoBaCeBkCwAiCkCuFoPy]eAkCy@eC{@eDq@kDk@cEwAyQiBsVkAsN}Egn@q@sJ_@iGWgFg@mMcAuWQcCg@yFkBkRc@{EiAmKuBiT]sDWiEy@kPg@_Gg@_E{AuOkAgKo@gFe@oDq@oEe@qBmAeEWkAOaAKoAC}ADiBPeBFc@\wA~@oC@sAh@CVgBJoA@c@EWBkAAcBGgB[yC}AuNu@iHG}B@uBJcBJmAjEeZbAuGz@uFh@}DV]H[RkAfAqGJe@l@mBl@eAv@w@n@]TIj@Ml@In@?Df@n@Fh@@|H|AzDj@zDl@l@F^KhAZhCp@pAXnCr@bBh@nBbAfCdB|@z@vCfDPTjAvAhArAjBjBlBdBlEnC\TCzAtEpCtDtBrEdCdExB~DpBnAj@z@XdAPtBLr@CH?pAQZKfBs@t@e@x@s@|@cAt@mAh@gA@mAlAmEFELSpAyD|A_GfAeC|B}HT_At@gDjCaJZq@dB{F~AeFmCuAgCyAv@mCd@}AfA}C~@oBr@iA|BcDn@gA~@iBTo@~@qCh@gCXoB??P{AP_BU_@e@w@d@v@nArBl@v@ClBlBtAdATnAXLCFAXiALc@Ng@X}A^eCvB{T\qDZsBSeATmBr@mE?@ASVkAv@iDlBqHvA_FhAcDv@qBtBaFbIyQpBsDrAoBdAiAp@k@r@g@v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@MxAKbNcBfJaAtOkBbKiA~TwCzFo@nC]bKaAhGm@~Hi@d@AbPaA~AOpCe@pEkAdA]zEkBj@UfB}@|Aw@xBs@|Ac@xJ_Cf@Dr@GrBa@fBYdBQvDQv@MlA]pG{BrAc@xCu@~Cm@zCg@|@WSqAOeA_@oDMqDT}`@JaC^qBZcAZw@xD}HvAsCpBiE~BkGJYg@c@eCaBO^i@tAc@dAo@~A"

Which lead my other question: most of the examples I found online were definitely not as long as the above. is there something wrong with it?

2
  • An example of what you have would be great. If the file is text (CSV, XML, GML, KML etc) a few lines would show how they are encoded. Without this information we would only be guessing. Commented May 17, 2016 at 23:48
  • Sorry for neglecting to include examples. I have made the edits above!
    – zero4case
    Commented May 18, 2016 at 4:58

1 Answer 1

3

There's some python code to do it here:

https://gist.github.com/signed0/2031157

You've not told us you have any python skills, but the way this works is to take a string and return a list of coordinate pairs:

>>> import gistfile
>>> gistfile1.decode("_{reFxmjVpAeBn@{@w@aAc@m@yAsBJ  .... etc... ")

which returns:

[(-3.82701, 37.78496), (-3.8265, 37.78455), 
 (-3.8262, 37.78431), (-3.82587, 37.78459),
  (-3.82564, 37.78477) .... etc ....

I'm not certain if that's lat-long or long-lat - if you know where you expect the points then you can tell.

Discovering it is so simple made me think I should write a QGIS plugin for it. The only related thing I could find is one that writes these formats from existing geometry:

https://github.com/pvinton/QGIS-EncodedPolylineExporter-plugin

so probably doesn't help you. You want an importer...

So I hacked one together, in javascript, from parts. This web page will convert a file containing that gobble-de-gook encoding string into a link to a GeoJSON file that will load into QGIS:

http://barryrowlingson.github.io/polyline-to-geojson/

4
  • Thank you for your help! No, I am super new to coding/CS so no skills in python or JS or any CS languages. I used your tool and was able to generate a geojson file for the encoded polyline I included above. I imported the file on geojson.io and got a straight line. What did I do wrong?
    – zero4case
    Commented May 18, 2016 at 18:22
  • Try the web converter again - I've changed the geoJSON format and now I can load it into QGIS. Its a wiggly line roughly diagonal across.
    – Spacedman
    Commented May 18, 2016 at 20:30
  • Thanks for getting back to me! I actually just posted another follow-up question to this here: gis.stackexchange.com/questions/194093/… But let me try the converter again!!
    – zero4case
    Commented May 18, 2016 at 20:37
  • I think I didn't flip the coordinates when I should have. If you can give us a sample string and tell us where it should go I'll make sure I get it the right way round.
    – Spacedman
    Commented May 18, 2016 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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