Saturday, June 3, 2017

generate marble bookmarks kml file

******generator.py **********
import xml.etree.ElementTree as ET
calist = [["point1", "13.3", "103.3","103.3,13.3"]\
    ["point2", "13.2", "103.2","103.2,13.2"]]
a = ET.Element('kml')
a.set("xmlns", 'http://www.opengis.net/kml/2.2')
a.set("xmlns:gx", "http://www.google.com/kml/ext/2.2")
b = ET.SubElement(a, 'Document')
c = ET.SubElement(b, 'name')
c.text = "Bookmarks"
# visible = ET.SubElement(b,"visibility")
# visible.text = "0"
folder = ET.SubElement(b, "Folder")
fname = ET.SubElement(folder,"name")
fname.text = "Default"
for j in calist:
    # print j
    sname = j[0]
    lat = j[1]
    lng = j[2]
    longlat = lng + "," + lat
    pmark = ET.SubElement(folder,"Placemark")
    pname = ET.SubElement(pmark,"name")
    pname.text =sname
    d = ET.SubElement(pmark, 'LookAt')
    dlong = ET.SubElement(d, "longitude")
    dlat = ET.SubElement(d, "latitude")
    dalti = ET.SubElement(d, "altitude")
    drange = ET.SubElement(d,"range")
    dlong.text = lng
    dlat.text =lat
    dalti.text = "0.0000000000"
    drange.text = "6814.6051134251"

    style = ET.SubElement(pmark,"Style")
    iconstyle = ET.SubElement(style,"IconStyle")
    icon =ET.SubElement(iconstyle,"Icon")
    iconhref = ET.SubElement(icon,"href")
    iconhref.text = "/usr/share/marble/data/bitmaps/bookmark.png"
    linestyle = ET.SubElement(style,"LineStyle")
    Linecolor = ET.SubElement(linestyle,"color")
    Linecolor.text = "ff000000"

    polystyle = ET.SubElement(style, "PolyStyle")
    polycolor = ET.SubElement(polystyle, "color")
    polycolor.text = "ff000000"
    point = ET.SubElement(pmark,"Point")
    coordinates = ET.SubElement(point, "coordinates")
    coordinates.text = j[3]
    extdata = ET.SubElement(pmark,"ExtendedData")
    extdata.set('xmlns:mx', 'http://marble.kde.org')
    extdatachild = ET.SubElement(extdata, "mx:OsmPlacemarkData")
    extdatachild.set("id","0")



print '<?xml version="1.0" encoding="UTF-8"?>'
# print a
ET.dump(a)



****usage*****
$ python generator.py  |   xmllint --format - > bookmarks.kml

No comments:

Post a Comment