Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to kml with recursive Document (Sourcery refactored) #109

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 22 additions & 24 deletions fastkml/kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ def etree_element(self):
if not self.ns:
root = etree.Element('%skml' % self.ns)
root.set('xmlns', config.KMLNS[1:-1])
elif config.LXML:
root = etree.Element(
'%skml' % self.ns,
nsmap={None: self.ns[1:-1]}
)
else:
if config.LXML:
root = etree.Element(
'%skml' % self.ns,
nsmap={None: self.ns[1:-1]}
)
else:
root = etree.Element('%skml' % self.ns)
root = etree.Element('%skml' % self.ns)
for feature in self.features():
root.append(feature.etree_element())
return root
Expand Down Expand Up @@ -320,11 +319,10 @@ def begin(self):
def begin(self, dt):
if self._time_span is None:
self._time_span = TimeSpan(begin=dt)
elif self._time_span.begin is None:
self._time_span.begin = [dt, None]
else:
if self._time_span.begin is None:
self._time_span.begin = [dt, None]
else:
self._time_span.begin[0] = dt
self._time_span.begin[0] = dt
if self._time_stamp is not None:
logger.warn('Setting a TimeSpan, TimeStamp deleted')
self._time_stamp = None
Expand All @@ -338,11 +336,10 @@ def end(self):
def end(self, dt):
if self._time_span is None:
self._time_span = TimeSpan(end=dt)
elif self._time_span.end is None:
self._time_span.end = [dt, None]
else:
if self._time_span.end is None:
self._time_span.end = [dt, None]
else:
self._time_span.end[0] = dt
self._time_span.end[0] = dt
if self._time_stamp is not None:
logger.warn('Setting a TimeSpan, TimeStamp deleted')
self._time_stamp = None
Expand Down Expand Up @@ -973,6 +970,11 @@ def append_schema(self, schema):

def from_element(self, element):
super(Document, self).from_element(element)
documents = element.findall('%sDocument' % self.ns)
for document in documents:
feature = Document(self.ns)
feature.from_element(document)
self.append(feature)
folders = element.findall('%sFolder' % self.ns)
for folder in folders:
feature = Folder(self.ns)
Expand Down Expand Up @@ -1133,13 +1135,12 @@ def get_resolution(self, dt, resolution=None):
raise ValueError
else:
return resolution
elif isinstance(dt, datetime):
resolution = 'dateTime'
elif isinstance(dt, date):
resolution = 'date'
else:
if isinstance(dt, datetime):
resolution = 'dateTime'
elif isinstance(dt, date):
resolution = 'date'
else:
resolution = None
resolution = None
return resolution

def parse_str(self, datestr):
Expand Down Expand Up @@ -1337,9 +1338,6 @@ def append(self, type, name, displayName=None):
"type must be one of ""'string', 'int', 'uint', 'short', "
"'ushort', 'float', 'double', 'bool'"
)
else:
# TODO explicit type conversion to check for the right type
pass
self._simple_fields.append({'type': type, 'name': name,
'displayName': displayName})

Expand Down