[GIS] Decode encoded polylines to usable format for QGIS

encodelineqgis

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@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}PdIeDhG{BbE{AjD_AzDw@pFq@zJiA|@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?

Best Answer

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/

Related Question