Skip to content

Commit

Permalink
Add test case for #355
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Oct 2, 2024
1 parent 181e2fe commit 9dc9f74
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/kml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = (
'<kml xmlns="http://www.opengis.net/kml/2.2">'
'<Document id="root_doc">'
"<Folder><name>test</name>"
"<Placemark>"
"<Polygon>"
"<outerBoundaryIs>"
"<LinearRing><coordinates>"
"-93.7426720226024,57.4519411370713 -93.6051809086549,49.4316261567984 "
"-80.8643376828499,49.5232868994301 -81.2309806533767,57.4519411370713 "
"-81.2309806533767,57.4519411370713 -93.7426720226024,57.4519411370713"
"</coordinates></LinearRing>"
"</outerBoundaryIs>"
"<innerBoundaryIs>"
"<LinearRing><coordinates>"
"-91.8663227028478,56.050879726904 -91.7704563496718,53.9897531336206 "
"-90.1407283456804,54.0856194867966 -90.0927951690924,56.002946550316 "
"-91.8663227028478,56.050879726904"
"</coordinates></LinearRing>"
"</innerBoundaryIs>"
"<innerBoundaryIs>"
"<LinearRing><coordinates>"
"-85.4912102166459,55.90708019714 -85.4912102166459,54.0376863102086 "
"-83.8135490360665,54.0856194867966 -83.9094153892425,55.90708019714 "
"-85.4912102166459,55.90708019714</coordinates></LinearRing>"
"</innerBoundaryIs>"
"</Polygon>"
"</Placemark>"
"</Folder>"
"</Document></kml>"
)
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:
Expand Down

0 comments on commit 9dc9f74

Please sign in to comment.