Skip to content

Commit

Permalink
use the new geometries in Placemark
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Oct 14, 2023
1 parent 100b23d commit 9c01d63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions fastkml/gx.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
class GxGeometry(Geometry):
def __init__(
self,
ns: None = None,
id: None = None,
ns: Optional[str] = None,
id: Optional[str] = None,
) -> None:
"""
gxgeometry: a read-only subclass of geometry supporting gx: features,
Expand Down
45 changes: 31 additions & 14 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
from fastkml.data import Schema
from fastkml.enums import Verbosity
from fastkml.geometry import Geometry
from fastkml.geometry import LinearRing
from fastkml.geometry import LineString
from fastkml.geometry import MultiGeometry
from fastkml.geometry import Point
from fastkml.geometry import Polygon
from fastkml.mixins import TimeMixin
from fastkml.styles import Style
from fastkml.styles import StyleMap
Expand Down Expand Up @@ -1651,37 +1656,49 @@ def geometry(self, geometry):
else:
self._geometry = Geometry(ns=self.ns, geometry=geometry)

def from_element(self, element: Element) -> None:
def from_element(self, element: Element, strict=False) -> None:
super().from_element(element)
point = element.find(f"{self.ns}Point")
if point is not None:
geom = Geometry(ns=self.ns)
geom.from_element(point)
self._geometry = geom
self._geometry = Point.class_from_element(
ns=self.ns,
element=point,
strict=strict,
)
return
line = element.find(f"{self.ns}LineString")
if line is not None:
geom = Geometry(ns=self.ns)
geom.from_element(line)
self._geometry = geom
self._geometry = LineString.class_from_element(
ns=self.ns,
element=line,
strict=strict,
)
return
polygon = element.find(f"{self.ns}Polygon")
if polygon is not None:
geom = Geometry(ns=self.ns)
geom.from_element(polygon)
self._geometry = geom
self._geometry = Polygon.class_from_element(
ns=self.ns,
element=polygon,
strict=strict,
)
return
linearring = element.find(f"{self.ns}LinearRing")
if linearring is not None:
geom = Geometry(ns=self.ns)
geom.from_element(linearring)
self._geometry = geom
self._geometry = LinearRing.class_from_element(
ns=self.ns,
element=linearring,
strict=strict,
)
return
multigeometry = element.find(f"{self.ns}MultiGeometry")
if multigeometry is not None:
geom = Geometry(ns=self.ns)
geom.from_element(multigeometry)
self._geometry = geom
self._geometry = MultiGeometry.class_from_element(
ns=self.ns,
element=multigeometry,
strict=strict,
)
return
track = element.find(f"{self.ns}Track")
if track is not None:
Expand Down

0 comments on commit 9c01d63

Please sign in to comment.