Last active
January 3, 2020 17:59
-
-
Save azlekov/50ecd2f08d2fbc83a3ad361fdb93b6dc to your computer and use it in GitHub Desktop.
Convert KML coordinates of Placemark to polyline encoded format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# pip install polyline | |
import polyline | |
def rreplace(s, old, new, count): | |
return (s[::-1].replace(old[::-1], new[::-1], count))[::-1] | |
coordinates = """ | |
24.738547,42.157153 | |
24.739296,42.157267 | |
24.739258,42.157899 | |
24.739416,42.157919 | |
24.739312,42.158654 | |
24.738180,42.158447 | |
""" | |
coordinates = coordinates.replace("\n", ",0") | |
coordinates = coordinates.replace(",0", ",") | |
coordinates = rreplace(coordinates, ",", "", 1) | |
coordinates = filter(None, coordinates.strip().split(',')) | |
print(coordinates) | |
array = [float(f) for f in coordinates] | |
points = zip(array[::2], array[1::2]) | |
reversed = [tuple(reversed(x)) for x in points] | |
print(polyline.encode(list(reversed), 5)) | |
print("\nHEX\n") | |
print(polyline.encode(list(reversed), 5).encode("utf-8").hex()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stara Zagora Green: