I have a kml file with list of destinations along with coordinates. Theres about 40+ destinations in this file. I am trying to parse the coordinates from it, when you look in the file you see "coordinates"..."/coordinates" so finding them won't be the hard part, but I can't see to get a full result. What I mean is, it will cut out -94. or any negative float from the beginning, and print the rest of it.
#!/usr/bin/python3.5
import re
def main():
results = []
with open("file.kml","r") as f:
contents = f.readlines()
if f.mode == 'r':
print("reading file...")
for line in contents:
coords_match = re.search(r"(<coordinates>)[+-]?\d+\.\d+|\d+\,\-?\d+\.\d+|\d+(?=</coordinates)",line)
if coords_match:
coords_matchh = coords_match.group()
print(coords_matchh)
here is some of the results I get
3502969,38.8555497
7662462,38.8583916
6280323,38.8866337
3655059,39.3983001
This is how the is format in the file, if it makes a difference
<coordinates>
-94.5944738,39.031411,0
</coordinates>
If I modify this line, and remove coordinates from the beginning
coords_match = re.search(r"[+-]?\d+\.\d+|\d+\,\-?\d+\.\d+|\d+(?=</coordinates)",line)
this is the results I get instead.
-94.7662462
-94.6280323
-94.3655059
This is essentially the desired result I want.
-94.7662462,38.8583916
-94.6280323,38.8866337
-94.3655059,39.3983001