I'm trying to merge a new encoded polyline with an existing polyline without decoding and reencoding the whole polyline. The new encoded polyline will be uploaded to a (linux) server where I would like to append it to the existing polyline.
The problem is, you can't just mash them together. Below is some sample data to play with. My hope is to find/create a solution in either PHP or a shell script but the problem is, I have no where near enough technical understanding to interpret the encoded polyline algorithm.
41.386692,-73.475912
41.424822,-73.375027
41.428292,-73.311173
41.426183,-73.254577
41.470168,-73.218532
41.498865,-73.155278
(Yes, 6 points are easy, but it's going to be more like 7,000 coordinate pairs)
- First 3 Coordinate Pairs Encoded:
yir{Fnwm_MimFquRuTanK
- Last 3:
s`z{Fbpb~L{qGg`FkrDkjK
- All 6:
yir{Fnwm_MimFquRuTanKdLw`J{qGg`FkrDkjK
Interactive Polyline Encoder Utility
Encoded Polyline Algorithm Format (you can get to this via Interactive Encoder)
Polyline Encoder
Edit:
I also have the original data that encoded the polylines on both ends. So I can also save the first and last coordinate pair separately.
Helpful Reads:
I ended up writing a blog post that has a lot more detail about how encoded polylines work. You can read it here: What is an Encoded Polyline?