KML Line Splitting Using a Python script

Hello everyone,

I am new to python and I need your support guys in a small task.
I drew a line manually on google earth around 10 m using the feature “Draw Line” by connecting 10 points so basically by clicking 10 times to get the complete line because I need the distance between each point to be 1 m.

Now the question is, how can I do that in a python script automatically ? I need to do it for longer lines and there must be a way to do it in python.

I would be very thankful for any assistance.

1 Like

If you’re doing this in KML, you need to:

There are also some KML related modules on PyPI:

Of these, the keytree module looks promising:

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

Thanks a lot man, I appreciate your help.
I will check them out and let you know how it goes.

Have a nice day.

Hello again,
I have tried it using the script below but I didn’t know how to add more coordinates using a function, I wrote some coordinates manually.
I need to add 20 coordinates on this route for example with a specific distance of 2m.

kindly let me know how I can go from here and thank you in advance.

import simplekml
from polycircles import polycircles
import subprocess
import pandas as pd

#Germany1 52.17365048266471, 10.50326921341822
#Germany2 52.17428145858134, 10.50385051351152

lines_kml = simplekml.Kml()
lines = lines_kml.newlinestring(name=‘Path’,
description=‘Germany1 to Germany2’,
coords=[(10.50326921341822,52.17365048266471),
(10.5034325391975,52.17383047860136),
(10.50360004375343,52.17401190870262),
(10.50377233592835,52.174191086712),
(10.50385051351152,52.17428145858134)])

#change the line width and color
lines.style.linestyle.width = 5
lines.style.linestyle.color = simplekml.Color.red

Lines_kml_path = ‘/Users/alkon/PycharmProjects/Lines_kml.kml’
lines_kml.save(Lines_kml_path)