我有一个matlab图形,我想将其转换为kml/kmz,但似乎无法弄清楚,我目前有一个.csv,我使用它将每个点排序为十六进制值,我只是无法将其转换为一个 kml/kmz 代表我的一生。
这就是我到目前为止尝试做的,
import pandas as pd
import simplekml
def create_kml(data):
kml = simplekml.Kml()
for _, row in data.iterrows():
latitude, longitude, altitude, rsrp, color_hex = row
point = kml.newpoint(name=f'RSRP: {rsrp}', coords=[(longitude, latitude, altitude)])
point.style.iconstyle.color = simplekml.Color.changealphaint(255, color_hex)
point.style.iconstyle.scale = 1.0
return kml
def write_kmz(kml, output_file):
kml.savekmz(output_file)
if __name__ == "__main__":
# Load data from CSV
csv_file = "C:/Users/djtil/Desktop/EE598/all_data.csv"
data = pd.read_csv(csv_file)
# Output KMZ file
output_file = "output.kmz"
# Create KML object
kml = create_kml(data)
# Write to KMZ file
write_kmz(kml, output_file)
print(f"KMZ file '{output_file}' created successfully.")
CSV 文件 https://drive.google.com/file/d/1Fm51NNlxdb5wCYTr8Zg9dZfx9__l6YGt/view?usp=sharing
这里发生了几个问题。
import pandas as pd
import simplekml
styles = {}
def create_kml(data):
kml = simplekml.Kml()
for _, row in data.iterrows():
latitude, longitude, altitude, rsrp, color_hex = row
style = styles.get(color_hex)
if style is None:
style = simplekml.Style()
style.iconstyle.color = "ff" + color_hex[::-1]
style.iconstyle.scale = 1.0
styles[color_hex] = style
point = kml.newpoint(description=f'RSRP: {rsrp}', coords=[(longitude, latitude, altitude)])
point.style = style
return kml
def write_kmz(kml, output_file):
kml.savekmz(output_file)
if __name__ == "__main__":
# Load data from CSV
csv_file = "all_data.csv"
data = pd.read_csv(csv_file)
# Output KMZ file
output_file = "output.kmz"
# Create KML object
kml = create_kml(data)
# Write to KMZ file
write_kmz(kml, output_file)
print(f"KMZ file '{output_file}' created successfully.")