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
One answer mentions the "etree", one advantage that you do not have to hardcode the xml format:
Below one of my examples, of course you have to adjust it to your case, but you may get the principle idea of how etree works:
to get something like this
G:\AMSR\GW1AM2_201301010834_032D_L1SGRTBR_1110110_channel89H.csv
wkbPoint
you can use this code:
import xml.etree.cElementTree as ET
[....]
root = ET.Element("OGRVRTDataSource")
OGRVRTLayer = ET.SubElement(root, "OGRVRTLayer")
OGRVRTLayer.set("name", AMSRcsv_shortname)
SrcDataSource = ET.SubElement(OGRVRTLayer, "SrcDataSource")
SrcDataSource.text = AMSRcsv
GeometryType = ET.SubElement(OGRVRTLayer, "GeometryType")
GeometryType.text = "wkbPoint"
GeometryField = ET.SubElement(OGRVRTLayer,"GeometryField")
GeometryField.set("encoding", "PointFromColumns")
GeometryField.set("x", "lon")
GeometryField.set("y", "lat")
GeometryField.set("z", "brightness")
tree = ET.ElementTree(root)
tree.write(AMSRcsv_vrt)
also some more info here