Create kml from csv in Python

前端 未结 5 1392
名媛妹妹
名媛妹妹 2021-02-06 03:54

I am new to Python. I am working on gps files. I need to convert a CSV file having all the gps data to kml file. Below is the code in python I am using :

import          


        
5条回答
  •  情书的邮戳
    2021-02-06 04:08

    This code is well written thank you for the post. I got it to work by putting my CSV in the same directory as the .py code.

    I made a few edits to bring it to py 3.3

    import csv
    #Input the file name."JoeDupes3_forearth"
    fname = input("Enter file name WITHOUT extension: ")
    data = csv.reader(open(fname + '.csv'), delimiter = ',')
    #Skip the 1st header row.
    #data.next()
    #Open the file to be written.
    f = open('csv2kml.kml', 'w')
    
    #Writing the kml file.
    f.write("\n")
    f.write("\n")
    f.write("\n")
    f.write("   " + fname + '.kml' +"\n")
    for row in data:
        f.write("   \n")
        f.write("       " + str(row[1]) + "\n")
        f.write("       " + str(row[3]) + "\n")
        f.write("       \n")
        f.write("           " + str(row[10]) + "," + str(row[11]) + "," + str() + "\n")
        f.write("       \n")
        f.write("   \n")
    f.write("\n")
    f.write("\n")
    print ("File Created. ")
    print ("Press ENTER to exit. ")
    input()
    f.close()
    

    Hope it helps if you are trying to convert your data.

提交回复
热议问题