Reading KML files from google maps

This project should be relatively short. The goal is to make sight edits to a KML file from google maps.  A KML is a file used to display information of google maps or google maps. Geolocations, directions etc.

The file I’m using looks like this:

image001.png

This file consists of outdoor locations around London. To export the file from must choose the “Export KML/KMZ” like below:

image003.png

Then choose the KML option:

image005.png

Now we have the file in are project folder we must get the third-party package that will parse through the file.

Using this package called FastKML installed via pip. Reading the docs we can turn the file into a string so it can be read.

 

The code I used below:

from fastkml import kml

with open('Outdoor London.kml', 'rt', encoding="utf-8") as myfile:
    doc = myfile.read()

print(doc)

The file printed on the command line below:

image007.png

Now we have the file parse we want to start editing. I want to edit the current icon and also create a new icon with its own location.

So first to edit the current icons we need to scroll down to were the names of the place markers are shown:

image009.png

In this example, I will shorten the of the place marker to meanwhile Gardens.

image011.png


Simply done by deleting the text:

image013.png

Now we want to add a new place marker into the file. Likely I will make a placemark tag with other children tags like above.

 Copying and pasting this example to use:

image015.png


Now I must choose custom coordinates of the location. Using google maps picked a location to decide on:

image017.png

When adding the coordinates to the file, is that the order of the numbers when copying is the wrong way around. So when paste you must change the order.

image019.png

Now, with the edited code, we should open the file on google maps

To do that we head to google maps them navigate to your places tabs:

image022.png

After that we click on the maps tabs then we head to “create new map”:

image024.png

After we get moved into a new page called google myMaps. Now we can import are KML file:

image026.png

After uploading the loading the file, we can see the map. Below we can we the custom example I added:

image028.png

Also, the example edited the text is also changed:

image030.png

Now we have successfully edited the KML file. From coding this project while writing I noticed that if your KML file does not have much data points then the fastKML library is not needed as you can just directly edit the KML file itself.

$\setCounter{0}$
Previous
Previous

Machine Learning and GANs Part 1

Next
Next

Graphs with flask