This is working but is SLOW. for a small .gpx of 477k, it is writing a .kml of 207k that takes 198 seconds to complete. my hunch is that it is the stringIO.stringIO(x)
that's so slow. any ideas how to speed it up would be fantastic.
Here are the key snips ONLY of what i have done:
f = open(fileName, "r")
x = f.read()
x = re.sub(r'\n', '', x, re.S) #remove any newline returns
name = re.search('<name>(.*)</name>', x, re.S)
print "Attachment name (as recorded from GPS device): " + name.group(1)
x = re.sub(r'<(.*)<trkseg>', '', x, re.S) #strip header
x = x.replace("</trkseg></trk></gpx>",""); #strip footer
x = x.replace("<trkpt","\n<trkpt"); #make the file in lines
x = re.sub(r'<speed>(.*?)</speed>', '', x, re.S) #strip speed
x = re.sub(r'<extensions>(.*?)</extensions>', '', x, re.S) # strip out extensions
then
#.kml header goes here
kmlTrack = """<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.ope......etc etc
then
buf = StringIO.StringIO(x)
for line in buf:
if line is not None:
timm = re.search('time>(.*?)</time', line, re.S)
if timm is not None:
kmlTrack += (" <when>"+ timm.group(1)+"</when>\n")
checkSumA =+ 1
buf = StringIO.StringIO(x)
for line in buf:
if line is not None:
lat = re.search('lat="(.*?)" lo', line, re.S)
lon = re.search('lon="(.*?)"><ele>', line, re.S)
ele = re.search('<ele>(.*?)</ele>', line, re.S)
if lat is not None:
kmlTrack += (" <gx:coord>"+ lon.group(1) + " " + lat.group(1) + " " + ele.group(1) + "</gx:coord>\n")
checkSumB =+ 1
if checkSumA == checkSumB:
#put a footer on
kmlTrack += """ </gx:Track></Placemark></Document></kml>"""
else:
print ("checksum error")
return None
with open("Realbush2.kml", "a") as myfile:
myfile.write(kmlTrack)
return ("succsesful .kml file-write completed in :" + str(c.seconds) + " seconds.")
Once again, this is working but it is very slow. If anyone can see how to speed this up, please let me know! Thanks