导出的xml带encoding
This commit is contained in:
parent
f3a1dda9a0
commit
b7a88f3ebb
3
main.py
3
main.py
|
|
@ -2,5 +2,6 @@
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# main()
|
||||
import transformer.exporter as exporter
|
||||
exporter.main()
|
||||
print("PyCharm")
|
||||
|
|
|
|||
|
|
@ -9,16 +9,15 @@ def prettify(elem):
|
|||
"""Return a pretty-printed XML string for the Element.
|
||||
"""
|
||||
rough_string = ET.tostring(
|
||||
elem, encoding="utf-8", method="xml", xml_declaration=True
|
||||
elem, encoding="unicode", method="xml", xml_declaration=True
|
||||
)
|
||||
reparsed = minidom.parseString(rough_string)
|
||||
return reparsed.toprettyxml(indent="\t")
|
||||
return reparsed.toprettyxml(indent="\t", encoding="utf-8")
|
||||
|
||||
|
||||
def main():
|
||||
df = pd.read_excel("成果表-0120.xlsx")
|
||||
needed_df = df.iloc[:120, :3]
|
||||
# print(needed_df)
|
||||
trans = transformer.Projector(
|
||||
transformer.EPSG_CGCS_2000_108E, transformer.EPSG_WGS_84
|
||||
)
|
||||
|
|
@ -41,10 +40,6 @@ def main():
|
|||
if fld.find(r"NS:name", ns).text == "点":
|
||||
point_folder = fld
|
||||
break
|
||||
# remove all placemark
|
||||
# for child in point_folder:
|
||||
# if child.tag == "{" + ns["NS"] + "}Placemark":
|
||||
# point_folder.remove(child)
|
||||
point_folder.clear()
|
||||
for _, row in name_lat_lon_df.iterrows():
|
||||
name = row["桩号"]
|
||||
|
|
@ -56,10 +51,8 @@ def main():
|
|||
ele_point = ET.SubElement(ele_placemark, "Point")
|
||||
coordinates = ET.SubElement(ele_point, "coordinates")
|
||||
coordinates.text = "{lon},{lat},0".format(lon=lon, lat=lat)
|
||||
# xml_f.write("out.kml",encoding='utf-8',method='xml',pretty_print=True)
|
||||
# print(xml_f.toString())
|
||||
with open("out.kml", "w") as f:
|
||||
f.write(prettify(root))
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue