You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I extended the KML class so I could add a from_geojson function. Ideally this concept can be taken further to include other types such as shape files. The raw data formats dont have kml specific logic like xml doc type and namespaces. It would be very helpful if the to_string or constructor method had optional args that allow you to pass on the doctype and a dictionary of namespaces. The namespaces would also need to be passed along to the etree_element function. I had good results with this in my case.
In the below example I used inheritance to overwrite the parent. It assumes use of LXML.
def to_string(self, prettyprint=False, namespaces=None, doctype='<?xml version="1.0" encoding="UTF-8"?>') -> str:
"""Returns the KML object as a string."""
return etree.tostring(
self.etree_element(namespaces=namespaces),
encoding="utf-8",
pretty_print=prettyprint,
doctype=doctype,
).decode("UTF-8")
The text was updated successfully, but these errors were encountered:
I think instead of adding it to the to_string method, it would be better to add a save method to fastkml.kml.KML like the parse method, taking the file or filename to write to. I don't think you will need to pass the namespaces as @wesley-murray suggested, they are already present on the object.
I extended the KML class so I could add a from_geojson function. Ideally this concept can be taken further to include other types such as shape files. The raw data formats dont have kml specific logic like xml doc type and namespaces. It would be very helpful if the to_string or constructor method had optional args that allow you to pass on the doctype and a dictionary of namespaces. The namespaces would also need to be passed along to the etree_element function. I had good results with this in my case.
In the below example I used inheritance to overwrite the parent. It assumes use of LXML.
The text was updated successfully, but these errors were encountered: