增加导出线路功能。
This commit is contained in:
parent
b7a88f3ebb
commit
d41c0615b2
|
|
@ -28,19 +28,15 @@ def main():
|
||||||
name_lat_lon_df = pd.DataFrame(
|
name_lat_lon_df = pd.DataFrame(
|
||||||
{"桩号": needed_df["点号"], "纬度": wgs_84_point[:, 0], "经度": wgs_84_point[:, 1]}
|
{"桩号": 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")
|
ET.register_namespace("", "http://www.opengis.net/kml/2.2")
|
||||||
root = xml_f.getroot()
|
|
||||||
ns = {
|
ns = {
|
||||||
"NS": r"http://www.opengis.net/kml/2.2",
|
"NS": r"http://www.opengis.net/kml/2.2",
|
||||||
}
|
}
|
||||||
folders_has_placemark = root.findall(r"NS:Document//NS:Folder[NS:Placemark]", ns)
|
xml_root = ET.Element("Document")
|
||||||
point_folder = None
|
ET.SubElement(xml_root, "name").text = "施工图路径"
|
||||||
for fld in folders_has_placemark:
|
point_folder = ET.SubElement(xml_root, "Folder")
|
||||||
if fld.find(r"NS:name", ns).text == "点":
|
ET.SubElement(point_folder, "name").text = "杆塔位置"
|
||||||
point_folder = fld
|
line_coordination_list = []
|
||||||
break
|
|
||||||
point_folder.clear()
|
|
||||||
for _, row in name_lat_lon_df.iterrows():
|
for _, row in name_lat_lon_df.iterrows():
|
||||||
name = row["桩号"]
|
name = row["桩号"]
|
||||||
lon = row["经度"]
|
lon = row["经度"]
|
||||||
|
|
@ -49,11 +45,21 @@ def main():
|
||||||
ele_name = ET.SubElement(ele_placemark, "name")
|
ele_name = ET.SubElement(ele_placemark, "name")
|
||||||
ele_name.text = name
|
ele_name.text = name
|
||||||
ele_point = ET.SubElement(ele_placemark, "Point")
|
ele_point = ET.SubElement(ele_placemark, "Point")
|
||||||
coordinates = ET.SubElement(ele_point, "coordinates")
|
point_coordinates = ET.SubElement(ele_point, "coordinates")
|
||||||
coordinates.text = "{lon},{lat},0".format(lon=lon, lat=lat)
|
point_coordinates.text = "{lon},{lat},0".format(lon=lon, lat=lat)
|
||||||
with open("out.kml", "w",encoding='utf-8') as f:
|
line_coordination_list.append([lat, lon, 0])
|
||||||
f.write(prettify(root).decode("utf-8"))
|
line_folder = ET.SubElement(xml_root, "Folder")
|
||||||
|
ET.SubElement(line_folder, "name").text = "线路路径"
|
||||||
# with open('84.txt','w') as f:
|
line_placemark = ET.SubElement(line_folder, "Placemark")
|
||||||
# for point in wgs_84_point:
|
ET.SubElement(line_placemark, "name").text = "线路路径"
|
||||||
# f.write('{point[1]},{point[0]},0 \n'.format(point=point))
|
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"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue