diff --git a/fastkml/geometry.py b/fastkml/geometry.py index baff7f39..45021891 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -605,10 +605,10 @@ def etree_element( ) -> Element: self.__name__ = self.__class__.__name__ element = super().etree_element(precision=precision, verbosity=verbosity) - assert isinstance(self.geometry, geo._MultiGeometry) _map_to_kml = {mg: self.__class__ for mg in self.multi_geometries} _map_to_kml.update(self.map_to_kml) - + if self.geometry is None: + return element for geometry in self.geometry.geoms: geometry_class = _map_to_kml[type(geometry)] element.append( diff --git a/tests/geometries/multigeometry_test.py b/tests/geometries/multigeometry_test.py index 02046bef..00c26437 100644 --- a/tests/geometries/multigeometry_test.py +++ b/tests/geometries/multigeometry_test.py @@ -345,6 +345,18 @@ def test_multi_geometries_read(self) -> None: ) ) + def test_empty_multi_geometries_read(self) -> None: + xml = ( + "00" + "" + ) + + mg = MultiGeometry.class_from_string(xml, ns="") + + assert mg.geometry is None + assert "MultiGeometry>" in mg.to_string() + assert "coordinates>" not in mg.to_string() + class TestMultiPointLxml(Lxml, TestMultiPointStdLibrary): """Test with lxml."""