I will try to explain the problem as best as possible.
The code below is used to create a Kml file for Google Earth from a csv file (points recorded by a drone).
Each line of the "csv" file includes the time, longitude, latitude and altitude of a point.
00:06,9.166118371854222,42.48375034483273,2.58 00:07,9.166119054009813,42.48374920008085,4.354 00:07,9.16612011321665,42.48374788423119,5.601 00:08,9.166121409787642,42.483747507145594,5.765 00:08,9.166121049499995,42.48374617693683,5.973
The code creates 2 folders: one for the flight track, the other for the list of all points.
My code is:
'''
the command line :
python test_kml.py
'''
import csv
import simplekml
kml = simplekml.Kml()
# read csv file
inputfile = csv.reader(open("csv_file.csv", 'r'))
# list where to store coords
points = []
# create folder for points
fol_points = kml.newfolder(name="The points")
# create points
for row in inputfile:
#lon_value = float(row[1]) # get lon
#lat_value = float(row[2]) # get lat
#alt_value = float(row[3]) # get alt
#name_value = row[0] # get name
coord = (float(row[1]), float(row[2]), float(row[3])) # Tuple with lon, lat, alt order
pnt = fol_points.newpoint(name=row[0], coords=[coord]) # create a new point whith coord value
points.append(coord) # add coord to points list
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png' # the icon shape
pnt.altitudemode = simplekml.AltitudeMode.relativetoground # set altitude option to show points at their own elevations
# create folder for linestring
fol_line = kml.newfolder(name="The line")
#create line
ls = fol_line.newlinestring(name='the LineString') # create a new line
ls.coords = points # set points values of new linestring with points values
ls.style.linestyle.width = 3 #set line width
ls.altitudemode = simplekml.AltitudeMode.relativetoground # set altitude option to show points at their own elevations
ls.extrude = 0 # option to avoid vertical line between ground and points
#try to put radiobutton on folder
fol_line.style.liststyle.listitemtype = simplekml.ListItemType.radiofolder
fol_points.style.liststyle.listitemtype = simplekml.ListItemType.radiofolder
#save kml file
kml.save("csv_file.kml")
The 2 problematic lines are:
fol_line.style.liststyle.listitemtype = simplekml.ListItemType.radiofolder fol_points.style.liststyle.listitemtype = simplekml.ListItemType.radiofolder
which create radio buttons for folders but also for items inside folders, as shown in the image below.
By deleting the 2 lines, we get the following result:
With Google Earth, it is possible to change this so that the radio buttons are only on folders and not on items inside folders, as shown in the image below.
I did not find in the documentation of the Python simplekml package, the option(s) which would make it possible to obtain the result obtained by Google Earth.
Could someone help me to achieve this last result using simplekml or with another Python package?
Thanks