增加导出线路功能。

This commit is contained in:
facat 2021-01-17 23:34:10 +08:00
parent b7a88f3ebb
commit d41c0615b2
1 changed files with 23 additions and 17 deletions

View File

@ -28,19 +28,15 @@ def main():
name_lat_lon_df = pd.DataFrame(
{"桩号": needed_df["点号"], "纬度": wgs_84_point[:, 0], "经度": wgs_84_point[:, 1]}
)
xml_f = ET.parse("sgt.kml")
ET.register_namespace("", "http://www.opengis.net/kml/2.2")
root = xml_f.getroot()
ns = {
"NS": r"http://www.opengis.net/kml/2.2",
}
folders_has_placemark = root.findall(r"NS:Document//NS:Folder[NS:Placemark]", ns)
point_folder = None
for fld in folders_has_placemark:
if fld.find(r"NS:name", ns).text == "":
point_folder = fld
break
point_folder.clear()
xml_root = ET.Element("Document")
ET.SubElement(xml_root, "name").text = "施工图路径"
point_folder = ET.SubElement(xml_root, "Folder")
ET.SubElement(point_folder, "name").text = "杆塔位置"
line_coordination_list = []
for _, row in name_lat_lon_df.iterrows():
name = row["桩号"]
lon = row["经度"]
@ -49,11 +45,21 @@ def main():
ele_name = ET.SubElement(ele_placemark, "name")
ele_name.text = name
ele_point = ET.SubElement(ele_placemark, "Point")
coordinates = ET.SubElement(ele_point, "coordinates")
coordinates.text = "{lon},{lat},0".format(lon=lon, lat=lat)
with open("out.kml", "w",encoding='utf-8') as f:
f.write(prettify(root).decode("utf-8"))
# with open('84.txt','w') as f:
# for point in wgs_84_point:
# f.write('{point[1]},{point[0]},0 \n'.format(point=point))
point_coordinates = ET.SubElement(ele_point, "coordinates")
point_coordinates.text = "{lon},{lat},0".format(lon=lon, lat=lat)
line_coordination_list.append([lat, lon, 0])
line_folder = ET.SubElement(xml_root, "Folder")
ET.SubElement(line_folder, "name").text = "线路路径"
line_placemark = ET.SubElement(line_folder, "Placemark")
ET.SubElement(line_placemark, "name").text = "线路路径"
line_style = ET.SubElement(ET.SubElement(line_placemark, "Style"), "LineStyle")
ET.SubElement(line_style, "color").text = "ff0000ff"
ET.SubElement(line_style, "width").text = "2"
line_string = ET.SubElement(line_placemark, "LineString")
line_coordinates = ET.SubElement(line_string, "coordinates")
line_coordinates.text = " ".join(
"{lon},{lat},{elevation}".format(lon=foo[1], lat=foo[0], elevation=foo[2])
for foo in line_coordination_list
)
with open("out.kml", "w", encoding="utf-8") as f:
f.write(prettify(xml_root).decode("utf-8"))