fastkml
fastkml copied to clipboard
abstractmethod for etree_element and from_element?
@abstractmethod
def from_element(self, element, subelements):
# subelements = ["altitude", "altitudeMode", {LatLonBox: ["north", "south", "east", "west", "rotation"]}]
super().from_element(element)
for subelement in subelements:
if isinstance(subelement, dict):
self.from_element(element, subelement.values()[0])
else:
value = element.find(f"{self.ns}{subelement}")
if value:
setattr(self, subelement, value.text)
Just an idea to reduce code duplication, of course this sketch doesn't deal with class specifics like instantiating Geometry
objects (Placemark
), parsing dates (_TimePrimitive
s) or iterating through multiple child objects (_Container
s), but I believe the general search-and-set behaviour could be abstracted throughout the project
Hey Martim @martimpassos Now would be a good time to have a second look at this
Hi @cleder, its been a while so I don't recall precisely how fastkml operates and why exactly I proposed the method above. I'll look into re-familiarizing myself with the code.
The code has changed quite a bit since you last looked at. There is still quite some clean-up to do before V1.0. You don't have to get involved in contributing code if you do not have the time, but I'd appreciate your feedback, criticism, thoughts and pointers ;-)
Implementation (WIP) in https://github.com/cleder/fastkml/tree/registry
In https://github.com/cleder/fastkml/tree/registry I introduce a 'registry'
which takes care of the most common use cases, some work is still to be done for some of the remaining occurrences of etree_element
and _get_kwargs