Skip to content

Commit

Permalink
Merge pull request #226 from ericmassip/develop
Browse files Browse the repository at this point in the history
Added support for nested multigeometries with test coverage
  • Loading branch information
cleder authored Apr 8, 2023
2 parents 6bb9374 + cf87477 commit 3d0a342
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]:
# MultiGeometry
geoms: List[Union[AnyGeometryType, None]] = []
if element.tag == f"{self.ns}MultiGeometry":
multigeometries = element.findall(f"{self.ns}MultiGeometry")
for multigeometry in multigeometries:
geom = Geometry(ns=self.ns)
geom.from_element(multigeometry)
geoms.append(geom.geometry)
points = element.findall(f"{self.ns}Point")
for point in points:
self._get_geometry_spec(point)
Expand Down
47 changes: 47 additions & 0 deletions tests/oldunit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,53 @@ def test_geometrycollection(self):
assert len(g.geometry) == 2
assert g.geometry.geom_type == "GeometryCollection"

def test_nested_multigeometry(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.366278,37.818844,0 -122.365248,37.819267,0 -122.365640,37.819875,0 -122.366278,37.818844,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
<Point>
<coordinates>-122.365,37.819,0</coordinates>
</Point>
<MultiGeometry>
<LineString>
<coordinates>
-122.365278,37.819000,0 -122.365248,37.819267,0
</coordinates>
</LineString>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-122.365248,37.819267,0 -122.365640,37.819875,0 -122.366278,37.818844,0 -122.365248,37.819267,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</MultiGeometry>
</Placemark></Document></kml>
"""

k = kml.KML()
k.from_string(doc)
placemark = list(list(k.features())[0].features())[0]

first_multigeometry = placemark.geometry
assert len(list(first_multigeometry.geoms)) == 3

second_multigeometry = [
g for g in first_multigeometry.geoms if g.geom_type == "GeometryCollection"
][0]
assert len(list(second_multigeometry.geoms)) == 2


class TestGetGxGeometry:
def test_track(self):
Expand Down

0 comments on commit 3d0a342

Please sign in to comment.