Create points in Google Earth with Python

First we need to import the library to create point in the Google Earth using simplekml module.

After importing the module simplekml, we create the kml python object kml by the method kml in simplekml with the syntax: kml=simplekml.Kml() (note that it should be simplekml.Kml() instead of simplekml.kml() cause python is case sensitive)

Now we have the empty kml file need to fulfill with the points.

Create some points in the kml file which can be read in Google Earth by method newpoint.

Syntax: kml.newpoint(name=”name of the point in GE”,coords=[(longitude,latitude)])

For example: in the code above i picked the place Gangnam in Seoul, S.Korea with the coordinates as above (see below how to find the coordinates of the place in Google Map).

Now we already created a Kml file with the point of Gangnam there. We nee to have the app of Google Earth to open the file. We need to save the file to the place you want to save, i save the place with the path above.

objectname.save(“path”)

Mac user you need to do some more to show python the path to save.

import os

kml.save(os.path.expanduser(“~/desktop/scripts/point.kml”))

See the path in the file to open the kml file.

Open the file by Google Earth and you will see the point Kangnam we just made in Google Earth.

HOW TO FIND THE COORDINATES OF THE PLACE IN GOOGLE MAP

  • open google map, and search the place you want to know the coordinates.
  • pin or save the place.
  • right click on that place and choose: WHAT IS HERE?
  • the coordinates will be showed at the below
  • click on the coordinates to see it more clearly.

p/s: here is the personal blog i write to archive my studying, only open-minded discussions are welcome here. English is not my mother tongue, please forgive my mistakes. Happy coding!

Show your support

Clapping shows how much you appreciated Nhu Phan’s story.