I’ve mentioned in my earlier post that it would be nice to find a way to convert the entire track into encoded polyline. The conversion should be done from the GPX format which I mainly use. After some Internet search nothing useful came up. At least nothing automated and ready to use. I even sent an e-mail to the creator of the wonderful site GPSVisualizer, but nothing came back. So, to solve this, I decided to write the code myself.
In order not to start completely from scratch I shamelessly borrowed the Python code from gpxplot project in Google code repository. The project itself seem a bit stale with little activity. However, the provided python code can be used as a great starting point. It has all the GPX reading functionality. All I have to do is to add one more parameter to convert the tracks to the encoded polylines and then post the results, of course. I hope this won’t violate the GNU licensing.
So, the final python code is here. I ran into a couple of problems with the algorithm during the development. However, thanks to a very good source I could solve them. My Python skills need some improvement also. I still think in C/C++ and thus miss out on many Python specific optimizations that can make the code much more elegant. One major issue was with the example provided by Google. The example doesn’t show what to do if the point value is small and doesn’t need to be encoded using all 6 characters. They do show this in the table, but somehow I couldn’t find the explanation how it was achieved.
I took a track from my recent trip to Yosemite NP. The file contains one track. The first map is generated using GPSVisualizer. It is just an image.
The second is a static Google map. Note: Google static map is not perfect and at some number of points it will choke. It is a good idea to reduce the number of points to be plotted. It is not possible to see everything anyway. The image below was drawn with 1000 points.
- The code is written for Python 3.2. I haven’t tried to run it on Python 2.7.
- It would be nice to make a GUI for it. Using an interpreter or an IDE is a bit tedious. Perhaps I’ll make it time permitting.
- The next step would be to add filtering to the data. This is what I wanted to do for a very long time. Basically GPS signal is sometimes noisy and this noise is transferred to the recorded track. However, the device manufacturers don’t want to add this feature for some reason.
So, the final python code is here.