Create a ** kml file ** that is 3D geospatial information using Python and display it on Google Earth.
Since simplekml is required, install the simplekml library according to the OS.
To create a kml file from a csv file that summarizes latitude, longitude, and altitude. Since it is xml-based, ElementTree was fine, but when I looked it up, there was a simplekml that could create a kml, so I created a kml file using simplekml.
gpsdata_to_kml.py
#!/usr/bin/python2.7
#-*- coding: utf-8 -*-
import simplekml
#Display in point format
## [Place name,longitude,latitude]
sample_points = [["Tokyo Station", 139.766389, 35.681340],
["Yurakucho Station", 139.763360, 35.675056],
["Shinjuku station", 139.700432, 35.690938],
["Ikebukuro Station", 139.711570, 35.730235],
["Akihabara Station", 139.774091, 35.698704],
["Ueno Station", 139.777195, 35.713714]]
kml = simplekml.Kml()
for point in sample_points:
kml.newpoint(name=unicode(point[0], 'utf-8'), coords=[(point[1], point[2])])
kml.save('yamanote_line.kml')
#Display in LINE STRING format including altitude
## [Object name,longitude,latitude,Altitude,color]
sample_linestrings = [["Sky tree", 139.810657, 35.710089, 634.000000, simplekml.Color.grey],
["○ Dam", 139.810557, 35.710089, 18.000000 , simplekml.Color.white],
["○ Lutraman", 139.810657, 35.709989, 40.000000, simplekml.Color.red],
["○ Itan 3", 139.810757, 35.710089, 120.000000, simplekml.Color.yellow],
["○ Nbuster", 139.810657, 35.710189, 200.000000, simplekml.Color.black]]
kml = simplekml.Kml()
for linestring in sample_linestrings:
ls = kml.newlinestring(name=unicode(linestring[0], 'utf-8'))
ls.style.linestyle.color = linestring[4]
ls.style.linestyle.width = 8
ls.extrude = 1
ls.altitudemode = simplekml.AltitudeMode.absolute
ls.coords = [(float(linestring[1]), float(linestring[2]), float(linestring[3]))]
kml.save('skytree.kml')
Recommended Posts