Created
February 19, 2019 03:43
-
-
Save ivder/c11fc2564c7b1caeb3853b5ece0529b4 to your computer and use it in GitHub Desktop.
Convert GPS information from text to KML format that can be viewed with Google Earth (1 KML file for each coordinate point)
This file contains 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
# -*- coding: utf-8 -*- | |
import simplekml | |
import os | |
def kml_converter(inputfile,dirlist,filelist): | |
f = open(inputfile,"r") | |
kml=simplekml.Kml() | |
for row in f: | |
data=row.split(",") | |
splitdata=data[0].split("\\") | |
kml.newpoint(name=splitdata[6], coords=[(data[2],data[1])]) | |
if not os.path.exists(dirlist): | |
os.makedirs(dirlist) | |
filelistsplit=filelist.split(".jpg.txt") | |
kml.save(dirlist+"/"+filelistsplit[0]+'.kml') | |
f.close() | |
#main | |
for root, dirs, files in os.walk("C:\\DeepEye\\Data\\Result\\resources\\20180601"): | |
for filelist in files: | |
if filelist.endswith(".txt"): | |
inputfile=os.path.join(root, filelist) | |
dirlist=os.path.basename(os.path.normpath(root)) | |
kml_converter(inputfile,dirlist,filelist) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment