1

By making Google Maps API call, I received a response JSON which contained this polyline:

ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@hATbAF~@BvB?hALjBHpCLjAVdAd@dAxCbGlA~BbBvCpAbD`AnCVpB\\hBf@nB|@tAb@f@RVXLbDj@jCl@nAf@`DbBdC`B`@b@HNN`@lA~DnAvBvB`G\\fA^p@j@z@~E`FbBpBxDfFXh@|@pD`@bB^fANd@\\`Bl@rBb@fATj@v@bBjBwCd@w@NB^B\\@\\K\\Q|AWZGXOPIRBb@K\\Kl@_@VOZWVI^Eh@Ov@KxCJ\\@\\K^@RMh@QhAMXKXY`@Q^SLK`@]fBc@n@M\\OlB_@n@KNMRUZQZGh@Ht@Lx@F`@BTANDRNTPNDDHLXN`@LRTJx@?RBJFFLV\\Zs@TQ`@MVIhAYp@YPc@VgALk@Hk@d@eA\\cAHq@Eo@J}@@q@DItAgAv@i@|@e@v@k@bAaAdDuB|@c@?I?]?{@Ms@COFWJODYEcABOTU^e@H_@Km@Ci@BU?e@Ca@Ie@e@oBKk@Eu@M{@CoAC}@Km@Iy@IaA?{@Ci@Ms@UgA]y@Mm@GQICe@QKMGi@Gi@GSI[Ym@[{@@_AK]SMo@i@OCg@EOEMMYSi@IUO]Ko@KSIWUWMU_@I]Kw@WoACY@a@CWQWe@[QIOYMYW]SMQUQu@OWWSUWU[SsAEg@Ic@Mc@?a@Ai@Em@AUOa@M_@e@g@MSGYOY_@YIQSR[Pa@mBQaAI[@QDyACq@Iu@o@k@e@Y]IcAAmBC]Ee@IgAUWAw@Ae@GWSaAeAYk@Si@a@k@YAc@O{@]a@MnAqA~@mCVaAHk@YmCIQSQOS

(See https://developers.google.com/maps/documentation/utilities/polylineutility )

I am able decode polyline and obtain lat long array in Python using polyline package (github link).

>>> import polyline
>>> l = polyline.decode('ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@hATbAF~@BvB?hALjBHpCLjAVdAd@dAxCbGlA~BbBvCpAbD`AnCVpB\\hBf@nB|@tAb@f@RVXLbDj@jCl@nAf@`DbBdC`B`@b@HNN`@lA~DnAvBvB`G\\fA^p@j@z@~E`FbBpBxDfFXh@|@pD`@bB^fANd@\\`Bl@rBb@fATj@v@bBjBwCd@w@NB^B\\@\\K\\Q|AWZGXOPIRBb@K\\Kl@_@VOZWVI^Eh@Ov@KxCJ\\@\\K^@RMh@QhAMXKXY`@Q^SLK`@]fBc@n@M\\OlB_@n@KNMRUZQZGh@Ht@Lx@F`@BTANDRNTPNDDHLXN`@LRTJx@?RBJFFLV\\Zs@TQ`@MVIhAYp@YPc@VgALk@Hk@d@eA\\cAHq@Eo@J}@@q@DItAgAv@i@|@e@v@k@bAaAdDuB|@c@?I?]?{@Ms@COFWJODYEcABOTU^e@H_@Km@Ci@BU?e@Ca@Ie@e@oBKk@Eu@M{@CoAC}@Km@Iy@IaA?{@Ci@Ms@UgA]y@Mm@GQICe@QKMGi@Gi@GSI[Ym@[{@@_AK]SMo@i@OCg@EOEMMYSi@IUO]Ko@KSIWUWMU_@I]Kw@WoACY@a@CWQWe@[QIOYMYW]SMQUQu@OWWSUWU[SsAEg@Ic@Mc@?a@Ai@Em@AUOa@M_@e@g@MSGYOY_@YIQSR[Pa@mBQaAI[@QDyACq@Iu@o@k@e@Y]IcAAmBC]Ee@IgAUWAw@Ae@GWSaAeAYk@Si@a@k@YAc@O{@]a@MnAqA~@mCVaAHk@YmCIQSQOS')
>>> l[:5]
[(19.52691, 73.17778), (19.52664, 73.1779), (19.52663, 73.17786), (19.52662, 73.17784), (19.5265, 73.1779)]
>>> len(l)
293

How should I store polyline, either in encoded format or as lat long array in postgres / postGIS (or some other format), so that when I connect to this postgres instance from QGIS, it will be able to visually render the polyline?

1 Answer 1

3

You could store it as a geometry and make use of the function ST_LineFromEncodedPolyline

ex:

select st_asText(ST_LineFromEncodedPolyline('ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@hATbAF~@BvB?hALjBHpCLjAVdAd@dAxCbGlA~BbBvCpAbD`AnCVpB\\hBf@nB|@tAb@f@RVXLbDj@jCl@nAf@`DbBdC`B`@b@HNN`@lA~DnAvBvB`G\\fA^p@j@z@~E`FbBpBxDfFXh@|@pD`@bB^fANd@\\`Bl@rBb@fATj@v@bBjBwCd@w@NB^B\\@\\K\\Q|AWZGXOPIRBb@K\\Kl@_@VOZWVI^Eh@Ov@KxCJ\\@\\K^@RMh@QhAMXKXY`@Q^SLK`@]fBc@n@M\\OlB_@n@KNMRUZQZGh@Ht@Lx@F`@BTANDRNTPNDDHLXN`@LRTJx@?RBJFFLV\\Zs@TQ`@MVIhAYp@YPc@VgALk@Hk@d@eA\\cAHq@Eo@J}@@q@DItAgAv@i@|@e@v@k@bAaAdDuB|@c@?I?]?{@Ms@COFWJODYEcABOTU^e@H_@Km@Ci@BU?e@Ca@Ie@e@oBKk@Eu@M{@CoAC}@Km@Iy@IaA?{@Ci@Ms@UgA]y@Mm@GQICe@QKMGi@Gi@GSI[Ym@[{@@_AK]SMo@i@OCg@EOEMMYSi@IUO]Ko@KSIWUWMU_@I]Kw@WoACY@a@CWQWe@[QIOYMYW]SMQUQu@OWWSUWU[SsAEg@Ic@Mc@?a@Ai@Em@AUOa@M_@e@g@MSGYOY_@YIQSR[Pa@mBQaAI[@QDyACq@Iu@o@k@e@Y]IcAAmBC]Ee@IgAUWAw@Ae@GWSaAeAYk@Si@a@k@YAc@O{@]a@MnAqA~@mCVaAHk@YmCIQSQOS'));

 LINESTRING(73.17778 19.52691,73.1779 19.52664,73.17786 19.52663,73.17784 19.52662,73.1779 19.5265,73.17801 19.52627,73.17816 19.52633,73.17834 19.52645,73.17872 19.52676,73.17878 19.52684,73.17881 19.52682,73.17943 19.52636,73.1799 19.52601,73.18016 19.52583,73.18014 19.52576,73.18004 19.52556,73.17994 19.52518,73.17992 19.52504,73.17992 19.52476,73.17993 19.52434,73.17998 19.52382,73.17998 19.52369,73.17994 19.52349,73.17992 19.52342,73.17976 19.52322,73.17939 19.52304,73.17905 19.52293,73.17873 19.52289,73.17813 19.52287,73.17776 19.52287,73.17722 19.5228,73.17649 19.52275,73.17611 19.52268,73.17576 19.52256,73.17541 19.52237,73.17411 19.5216,73.17347 19.52121,73.17271 19.52071,73.17189 19.5203,73.17117 19.51997,73.1706 19.51985,73.17045 19.5197,73.17025 19.51917,73.16994 19.51861,73.16976 19.51818,73.16966 19.51798,73.16953 19.51786,73.16871 19.51779,73.16801 19.51757,73.16761 19.51734,73.1668 19.51714,73.16613 19.51664,73.16596 19.51615,73.16591 19.51597,73.16583 19.51589,73.16544 19.51572,73.16504 19.51476,73.16444 19.51416,73.16429 19.51287,73.16393 19.51272,73.16368 19.51256,73.16338 19.51234,73.16225 19.51122,73.16168 19.51072,73.16052 19.50979,73.16031 19.50966,73.15942 19.50935,73.15892 19.50918,73.15856 19.50902,73.15837 19.50894,73.15822 19.50879,73.15799 19.5083,73.15781 19.50772,73.1577 19.50736,73.15742 19.50714,73.15688 19.50664,73.15669 19.5074,73.15661 19.50768,73.15645 19.50766,73.1563 19.50764,73.15629 19.50749,73.15614 19.50734,73.15599 19.5074,73.15608 19.50725,73.1562 19.50678,73.15624 19.50664,73.15632 19.50651,73.15637 19.50642,73.15635 19.50632,73.15641 19.50614,73.15626 19.50599,73.15603 19.50605,73.15591 19.50621,73.15577 19.50629,73.15565 19.50641,73.15549 19.50646,73.15528 19.50649,73.155 19.50657,73.15423 19.50663,73.15408 19.50657,73.15407 19.50642,73.15392 19.50627,73.15376 19.50633,73.15366 19.50632,73.15345 19.50639,73.15308 19.50648,73.15295 19.50655,73.15282 19.50661,73.15265 19.50674,73.15249 19.50683,73.15242 19.50693,73.15225 19.50699,73.15173 19.50714,73.15149 19.50732,73.15134 19.50739,73.15142 19.50724,73.15158 19.50669,73.15164 19.50645,73.15171 19.50637,73.15182 19.50627,73.15191 19.50613,73.15195 19.50599,73.1519 19.50578,73.15183 19.50551,73.15179 19.50522,73.15177 19.50505,73.15178 19.50494,73.15175 19.50486,73.15167 19.50476,73.15158 19.50465,73.15155 19.50457,73.1515 19.50454,73.15137 19.50447,73.1512 19.50439,73.1511 19.50432,73.15104 19.50421,73.15104 19.50392,73.15102 19.50382,73.15098 19.50376,73.15091 19.50372,73.15076 19.5036,73.15062 19.50345,73.15051 19.50371,73.15034 19.5038,73.15022 19.50387,73.14985 19.50392,73.1496 19.50405,73.14951 19.50418,73.14939 19.50436,73.14932 19.50472,73.14927 19.50494,73.14908 19.50516,73.14893 19.50551,73.14927 19.50536,73.14952 19.50531,73.14976 19.50534,73.15007 19.50528,73.15032 19.50527,73.15037 19.50524,73.15073 19.50481,73.15094 19.50453,73.15113 19.50422,73.15135 19.50394,73.15168 19.5036,73.15227 19.50277,73.15245 19.50246,73.1525 19.50246,73.15265 19.50246,73.15295 19.50246,73.15321 19.50253,73.15329 19.50255,73.15341 19.50251,73.15349 19.50245,73.15362 19.50242,73.15396 19.50245,73.15404 19.50243,73.15415 19.50232,73.15434 19.50216,73.1545 19.50211,73.15473 19.50217,73.15494 19.50219,73.15505 19.50217,73.15524 19.50217,73.15541 19.50219,73.1556 19.50224,73.15616 19.50243,73.15638 19.50249,73.15665 19.50252,73.15695 19.50259,73.15735 19.50261,73.15766 19.50263,73.15789 19.50269,73.15818 19.50274,73.15851 19.50279,73.15881 19.50279,73.15902 19.50281,73.15928 19.50288,73.15964 19.50299,73.15993 19.50314,73.16016 19.50321,73.16025 19.50325,73.16027 19.5033,73.16036 19.50349,73.16043 19.50355,73.16064 19.50359,73.16085 19.50363,73.16095 19.50367,73.16109 19.50372,73.16132 19.50385,73.16162 19.50399,73.16194 19.50398,73.16209 19.50404,73.16216 19.50414,73.16237 19.50438,73.16239 19.50446,73.16242 19.50466,73.16245 19.50474,73.16252 19.50481,73.16262 19.50494,73.16267 19.50515,73.16275 19.50526,73.16281 19.50541,73.16287 19.50565,73.16292 19.50575,73.16303 19.50587,73.1631 19.50599,73.16326 19.5061,73.16341 19.50615,73.16369 19.50621,73.16409 19.50633,73.16422 19.50635,73.16439 19.50634,73.16451 19.50636,73.16463 19.50645,73.16477 19.50664,73.16482 19.50673,73.16495 19.50681,73.16508 19.50688,73.16523 19.507,73.1653 19.5071,73.16541 19.50719,73.16568 19.50728,73.1658 19.50736,73.1659 19.50748,73.16602 19.50759,73.16616 19.5077,73.16658 19.5078,73.16678 19.50783,73.16696 19.50788,73.16714 19.50795,73.16731 19.50795,73.16752 19.50796,73.16775 19.50799,73.16786 19.508,73.16803 19.50808,73.16819 19.50815,73.16839 19.50834,73.16849 19.50841,73.16862 19.50845,73.16875 19.50853,73.16888 19.50869,73.16897 19.50874,73.16887 19.50884,73.16878 19.50898,73.16933 19.50915,73.16966 19.50924,73.1698 19.50929,73.16989 19.50928,73.17034 19.50925,73.17059 19.50927,73.17086 19.50932,73.17108 19.50956,73.17121 19.50975,73.17126 19.5099,73.17127 19.51024,73.17129 19.51079,73.17132 19.51094,73.17137 19.51113,73.17148 19.51149,73.17149 19.51161,73.1715 19.51189,73.17154 19.51208,73.17164 19.5122,73.17199 19.51253,73.17221 19.51266,73.17242 19.51276,73.17264 19.51293,73.17265 19.51306,73.17273 19.51324,73.17288 19.51354,73.17295 19.51371,73.17336 19.51331,73.17407 19.51299,73.1744 19.51287,73.17462 19.51282,73.17533 19.51295,73.17542 19.513,73.17551 19.5131,73.17561 19.51318)
(1 row)

If you want to save the encoded line, you can then create a view calling ST_LineFromEncodedPolyline and display this view in Qgis

PS: I was under the impression that Google's geometries shouldn't be stored, you may want to double check their terms of service

2
  • So you mean to say QGIS will be able to render polyline from the table with a single geometry column? Also am quite new to the whole spatial data world. Are you saying something like this: CREATE TABLE roads(geom geometry(LINESTRING,3005)); Or there are any other mandatory columns required which I miss here?
    – Mahesha999
    Jan 17, 2022 at 21:00
  • yes, exactly! You will want a primary key too (of course you are free to add as many other columns as you wish)
    – JGH
    Jan 17, 2022 at 22:04

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.