Most people probably have the same image in their heads when you say the word volcano. Nevertheless, there are different types of volcanoes. Technically, a volcano is an opening in the earth's surface where molten rock, gas and fragments of bedrock come out. Around such openings a mountain is often formed.

Volcanoes are often found in areas on adjacent tectonic plates, so the areas where earthquakes occur. Exceptions are hotspots. These are areas where hot material from the mantle comes up through the crust.

In this exercise, we will create a file in Keyhole Markup Language (KML). KML is an XML-based standard markup language for geographical data, with the following structure.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>

<Placemark>
    <name>name</name>
    <Point><coordinates>longitude,latitude,0</coordinates></Point>
    <description><![CDATA[description]]></description>
</Placemark>

</Document>
</kml>

Furthermore, we also use CSV files with data on volcanoes. These files will always start with a header and contain the following columns (in this order):

Assignment

Write a function makeVolcanoKml that has two obligatory and three optional argument.

The first obligatory argument indicates the file name of the CSV file from which the data is to be retrieved. The second obligatory argument indicates the file name of the KML file that has to be written away. Your function should produce a KML file according to the template that was presented above. The part from <Placemark> to </Placemark> should be repeated for every volcano. The red parts are to be replaced by the data of the volcano:

The remaining three arguments allow you to determine which volcanoes are written to the KML file. These three arguments are respectively called country, state and volcanicType. For each of these arguments applies that, if they are given, only volcanoes with the given value in the corresponding column are written to the KML file. These comparisons are always made case sensitive.

Extra

You can see a KML file using Google Maps. To do this, the file must be online. Try to place this file on your webspace from the university. More information can be found on the helpdesk1. If the file is online, go to Google Maps and enter the address of the KML file into the search field.

If you have a Google account, it can be even easier:

Example

The following examples use the file volcanoes.csv3

>>> makeVolcanoKml('volcanoes.csv', 'greece.kml', country='Greece')
>>> print(open('greece.kml', 'r').read())
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Placemark>
    <name>Methana</name>
    <Point><coordinates>23.34,37.615,0</coordinates></Point>
    <description><![CDATA[volcano of type Lava dome with state Historical]]></description>
</Placemark>
<Placemark>
    <name>Mí­los</name>
    <Point><coordinates>24.44,36.699,0</coordinates></Point>
    <description><![CDATA[volcano of type Stratovolcano with state Radiocarbon]]></description>
</Placemark>
<Placemark>
    <name>Santorini</name>
    <Point><coordinates>25.40,36.404,0</coordinates></Point>
    <description><![CDATA[volcano of type Shield volcano with state Historical]]></description>
</Placemark>
<Placemark>
    <name>Yali</name>
    <Point><coordinates>27.14,36.671,0</coordinates></Point>
    <description><![CDATA[volcano of type Lava dome with state Holocene]]></description>
</Placemark>
<Placemark>
    <name>Nisyros</name>
    <Point><coordinates>27.16,36.586,0</coordinates></Point>
    <description><![CDATA[volcano of type Stratovolcano with state Historical]]></description>
</Placemark>
<Placemark>
    <name>Kos</name>
    <Point><coordinates>27.25,36.852,0</coordinates></Point>
    <description><![CDATA[volcano of type Caldera with state Pleistocene-Fumarolic]]></description>
</Placemark>

</Document>
</kml>