fastkml icon indicating copy to clipboard operation
fastkml copied to clipboard

staticmethod for from_string

Open s-celles opened this issue 6 years ago • 1 comments

Hello,

I'm new to fastkml and was quite surprised to see its API usage.

>>> from fastkml import kml

# Setup the string which contains the KML file we want to read
>>> doc = """<?xml version="1.0" encoding="UTF-8"?>
... <kml xmlns="http://www.opengis.net/kml/2.2">
... <Document>
...   <name>Document.kml</name>
...   <open>1</open>
...   <Style id="exampleStyleDocument">
...     <LabelStyle>
...       <color>ff0000cc</color>
...     </LabelStyle>
...   </Style>
...   <Placemark>
...     <name>Document Feature 1</name>
...     <styleUrl>#exampleStyleDocument</styleUrl>
...     <Point>
...       <coordinates>-122.371,37.816,0</coordinates>
...     </Point>
...   </Placemark>
...   <Placemark>
...     <name>Document Feature 2</name>
...     <styleUrl>#exampleStyleDocument</styleUrl>
...     <Point>
...       <coordinates>-122.370,37.817,0</coordinates>
...     </Point>
...   </Placemark>
... </Document>
... </kml>"""

# Create the KML object to store the parsed result
>>> k = kml.KML()

# Read in the KML string
>>> k.from_string(doc)

why not using a static method instead

So it will be possible to simply do

k = kml.KML.from_string(doc)

using such API, it would make it possible open file

k = kml.KML.read_kml_file(filename)

using a simpler approach.

What is your opinion?

Kind regards

s-celles avatar Nov 05 '19 20:11 s-celles

Yes that looks good to me. As this is implementes in base._BaseObject this may have a knock on effect

cleder avatar Nov 06 '19 15:11 cleder