From 9dc9f7446be8dd1a6a2f8f4987684ab97f6accb0 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Wed, 2 Oct 2024 13:21:52 +0100 Subject: [PATCH] Add test case for #355 --- docs/HISTORY.rst | 2 +- tests/kml_test.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index e5e3255c..4d742416 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -80,7 +80,7 @@ Changelog ----------------- - specify minor python versions tested with Travis CI -- add support for tesselation, altitudeMode and extrude to Geometries +- add support for tessellation, altitudeMode and extrude to Geometries - move implementation of geometry from kml.Placemark to geometry.Geometry - add support for heterogenous GeometryCollection - python 3 compatible diff --git a/tests/kml_test.py b/tests/kml_test.py index 42c06b28..e9f73188 100644 --- a/tests/kml_test.py +++ b/tests/kml_test.py @@ -20,6 +20,7 @@ import pygeoif as geo +from fastkml import containers from fastkml import features from fastkml import kml from fastkml.containers import Document @@ -58,6 +59,49 @@ def test_kml(self) -> None: k2 = kml.KML.class_from_string(k.to_string(), ns="") assert k.to_string() == k2.to_string() + def test_kml_with_document(self) -> None: + """Kml file with document/folder/placemark/polygon.""" + doc = ( + '' + '' + "test" + "" + "" + "" + "" + "-93.7426720226024,57.4519411370713 -93.6051809086549,49.4316261567984 " + "-80.8643376828499,49.5232868994301 -81.2309806533767,57.4519411370713 " + "-81.2309806533767,57.4519411370713 -93.7426720226024,57.4519411370713" + "" + "" + "" + "" + "-91.8663227028478,56.050879726904 -91.7704563496718,53.9897531336206 " + "-90.1407283456804,54.0856194867966 -90.0927951690924,56.002946550316 " + "-91.8663227028478,56.050879726904" + "" + "" + "" + "" + "-85.4912102166459,55.90708019714 -85.4912102166459,54.0376863102086 " + "-83.8135490360665,54.0856194867966 -83.9094153892425,55.90708019714 " + "-85.4912102166459,55.90708019714" + "" + "" + "" + "" + "" + ) + k = kml.KML.class_from_string(doc) + assert len(k.features) == 1 + assert isinstance(k.features[0], Document) + assert len(k.features[0].features) == 1 + assert isinstance(k.features[0].features[0], containers.Folder) + assert len(k.features[0].features[0].features) == 1 + assert isinstance(k.features[0].features[0].features[0], features.Placemark) + assert isinstance(k.features[0].features[0].features[0].geometry, geo.Polygon) + assert len(list(k.features[0].features[0].features[0].geometry.interiors)) == 2 + class TestParseKML(StdLibrary): def test_parse_kml(self) -> None: