diff --git a/fastkml/kml.py b/fastkml/kml.py index 4ade8ce2..b3db3621 100644 --- a/fastkml/kml.py +++ b/fastkml/kml.py @@ -27,7 +27,6 @@ """ import logging -import os from pathlib import Path from typing import IO from typing import Any @@ -257,7 +256,7 @@ def write( Write KML to a file Args: ---- - file_name: The file name where to save the file. + file_path: The file name where to save the file. Can be any string value prettyprint : bool, default=True Whether to pretty print the XML. @@ -288,9 +287,9 @@ def write( if file_path.suffix == ".kmz": with zipfile.ZipFile(file_path, 'w', zipfile.ZIP_DEFLATED) as kmz: - kmz.write(file_path, arcname=os.path.basename(file_path)) + kmz.writestr('doc.kml', tree) else: - with open(file_path, "w") as file: + with open(file_path, "w", encoding="UTF-8") as file: file.write(tree) diff --git a/tests/kml_test.py b/tests/kml_test.py index e5daeea7..f449a360 100644 --- a/tests/kml_test.py +++ b/tests/kml_test.py @@ -209,7 +209,7 @@ def test_write_kml_file(self) -> None: ) file_path = KMLFILEDIR / "output.kml" - kml.KML.write(doc, file_path=file_path, prettyprint=True, xml_declaration=True) + doc.write(file_path=file_path, prettyprint=True, xml_declaration=True) assert file_path.is_file(), "KML file was not created." @@ -236,7 +236,7 @@ def test_write_kmz_file(self) -> None: file_path = KMLFILEDIR / "output.kmz" - kml.KML.write(doc, file_path=file_path, prettyprint=True, xml_declaration=True) + doc.write(file_path=file_path, prettyprint=True, xml_declaration=True) assert file_path.is_file(), "KMZ file was not created." diff --git a/tests/ogc_conformance/data/kml/output.kmz b/tests/ogc_conformance/data/kml/output.kmz index a71b613e..bc737f2d 100644 Binary files a/tests/ogc_conformance/data/kml/output.kmz and b/tests/ogc_conformance/data/kml/output.kmz differ