#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Creates KML file with station info.

    License
    Copyright 2012 Kasper D. Fischer <kasper.fischer@rub.de>

    This program is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation, either version 3 of the License, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License along
    with this program. If not, see http://www.gnu.org/licenses/.

    $Id$
"""

import simplekml

# create new empty KML file
kml = simplekml.Kml()

# create empyt folder to contain styles and stations
stations_folder = kml.newfolder(name="Stations")

# style of broad-band stations
BBstyle = simplekml.Style()
BBstyle.iconstyle.icon.href = 'https://maps.google.com/mapfiles/ms/micons/red-dot.png'
BBtcolor = '#003560'

# style of short periode stations
SPstyle = simplekml.Style()
SPstyle.iconstyle.icon.href = 'https://maps.google.com/mapfiles/ms/micons/orange-dot.png'
SPtcolor = '#003560'

# style of short periode stations
AUXstyle = simplekml.Style()
AUXstyle.iconstyle.icon.href = 'https://maps.google.com/mapfiles/ms/micons/yellow-dot.png'
AUXtcolor = '#003560'

# setting station info
stations = {
    'BUG, BKLB':   [(7.2693, 51.4406), "GRSN station BUG, STS-2 seismometer<br />RuhrNet station BKLB, GS-13 seismometer", BBstyle, 10, '#ff0000', 'BUG (Bochum University Germany), BKLB (Bochum - Klosterbusch)', BBtcolor, 1],
    'BULI':  [(7.2602, 51.4544), 'RuhrNet station BULI, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'BULI', AUXtcolor, 0],
    'BTEZ':  [(7.2790, 51.4490), 'RuhrNet station BTEZ, GS-13 seismometer', AUXstyle, 8, '#ffff00', 'BTEZ', AUXtcolor, 0],
    'BHOF':  [(7.2614, 51.4289), 'RuhrNet station BHOF, GS-13 seismometer', AUXstyle, 8, '#ffff00', 'BHOF', AUXtcolor, 0],
    'BPFI':  [(7.2276, 51.4185 ), 'RuhrNet station BBFI, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'BPFI', AUXtcolor, 0],
    'HMES':  [(7.7263, 51.6578), 'RuhrNet station HMES, Trillium 40 seismometer', BBstyle, 10, '#ff0000', 'HMES', BBtcolor, 0],
    'BRHE':  [(6.5710, 51.5155), 'RuhrNet station BRHE, Mark L-4C 3D seismometer', SPstyle, 10, '#ffa500', 'BRHE', SPtcolor, 0],
    'ZERL':  [(6.8695, 51.6207), 'RuhrNet station ZERL, Mark L-4C 3D seismometer', SPstyle, 10, '#ffa500', 'ZERL', SPtcolor, 0],
    'ZER1':  [(6.8252, 51.5948), 'RuhrNet station ZER1, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'ZER1', AUXtcolor, 0],
    'ZER2':  [(6.9062, 51.5871 ), 'RuhrNet station ZER2, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'ZER2', AUXtcolor, 0],
    'ZER3':  [(6.8384, 51.61274), 'RuhrNet station ZER3, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'ZER3', AUXtcolor, 0],
    'BAVN':  [(7.1220, 51.7380), 'RuhrNet station BAVN, STS-2 seismometer', BBstyle, 10, '#ff0000', 'BAVN', BBtcolor, 0],
    'BAVS':  [(7.13307, 51.7000), 'RuhrNet station BAVS, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'BAVS', AUXtcolor, 0],
    'IBBN':  [(7.7566, 52.3072), 'GEOFON station IBBN, STS-2 seismometer', BBstyle, 10, '#ff0000', 'IBBN', BBtcolor, 0],
    'IBBE':  [(7.7943, 52.2998), 'RuhrNet station IBBE, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'IBBE', AUXtcolor, 0],
    'IBBS':  [(7.7486, 52.2843), 'RuhrNet station IBBS, Mark L-4C 3D seismometer', AUXstyle, 8, '#ffff00', 'IBBS', AUXtcolor, 0],
    'KERA':  [(23.55769, 35.36919), 'GEOFON station KERA, STS-2 seismometer', BBstyle, 10, '#ff0000', 'KERA', BBtcolor, 0],
    'KARP':  [(27.16117, 35.54717), 'GEOFON station KARP, STS-2 seismometer', BBstyle, 10, '#ff0000', 'KARP', BBtcolor, 0]
    }
#    'BSHA':  [(7.2445, 51.4469), 'RuhrNet station BSHA, GS-13 seismometer', AUXstyle, 8, '#ffff00', '', 'black'],
#    'BKLB':  [(7.2697, 51.4401), 'RuhrNet station BKLB, GS-13 seismometer', AUXstyle, 8, '#ffff00', 'BKLB', AUXtcolor],

# adding station markers
for key, value in stations.iteritems():
    pnt = stations_folder.newpoint(
        name = key,
        coords = [(value[0][0], value[0][1])],
        description = value[1]
    )
    pnt.style = value[2]
    pnt.extendeddata.newdata('pntsize', value[3])
    pnt.extendeddata.newdata('pntcolor', value[4])
    pnt.extendeddata.newdata('text', value[5])
    pnt.extendeddata.newdata('tcolor', value[6])
    pnt.extendeddata.newdata('extrastation', value[7])

# saving the KML file
kml.save('stations.kml')