Skip to main content
added 728 characters in body
Source Link
cleder
  • 126
  • 3

This is possible with fastkml >= 1.1

>>> from fastkml import Point
>>> p = Point.from_string('<Point><coordinates>2.34880,48.85341</coordinates></Point>')
>>> p
fastkml.geometry.Point(ns='{http://www.opengis.net/kml/2.2}', name_spaces={'kml': '{http://www.opengis.net/kml/2.2}', 'atom': '{http://www.w3.org/2005/Atom}', 'gx': '{http://www.google.com/kml/ext/2.2}'}, id='', target_id='', extrude=None, altitude_mode=None, kml_coordinates=fastkml.geometry.Coordinates(ns='', name_spaces={'kml': '{http://www.opengis.net/kml/2.2}', 'atom': '{http://www.w3.org/2005/Atom}', 'gx': '{http://www.google.com/kml/ext/2.2}'}, coords=[(2.3488, 48.85341)], **{},), **{},)
>>> p.geometry
Point(2.3488, 48.85341)
>>> print(p)
<kml:Point xmlns:kml="http://www.opengis.net/kml/2.2">
  <coordinates>2.3488,48.85341</coordinates>
</kml:Point>

Fastkml 1.0.0 needs the namespace to be declared, e.g:

from fastkml import Point
p='<Point xmlns="http://www.opengis.net/kml/2.2"><coordinates>2.34880,48.85341</coordinates></Point>'
Point.from_string(p)
Point.from_string(p).validate()

or you can wrap it into a Placemark with the namespace:

from fastkml import Placemark
p="<Point><coordinates>2.34880,48.85341</coordinates></Point>"
pm=f'<Placemark xmlns="http://www.opengis.net/kml/2.2">{p}</Placemark>'
Placemark.from_string(pm)
Placemark.from_string(pm).validate()

Fastkml needs the namespace to be declared, e.g:

from fastkml import Point
p='<Point xmlns="http://www.opengis.net/kml/2.2"><coordinates>2.34880,48.85341</coordinates></Point>'
Point.from_string(p)
Point.from_string(p).validate()

or you can wrap it into a Placemark with the namespace:

from fastkml import Placemark
p="<Point><coordinates>2.34880,48.85341</coordinates></Point>"
pm=f'<Placemark xmlns="http://www.opengis.net/kml/2.2">{p}</Placemark>'
Placemark.from_string(pm)
Placemark.from_string(pm).validate()

This is possible with fastkml >= 1.1

>>> from fastkml import Point
>>> p = Point.from_string('<Point><coordinates>2.34880,48.85341</coordinates></Point>')
>>> p
fastkml.geometry.Point(ns='{http://www.opengis.net/kml/2.2}', name_spaces={'kml': '{http://www.opengis.net/kml/2.2}', 'atom': '{http://www.w3.org/2005/Atom}', 'gx': '{http://www.google.com/kml/ext/2.2}'}, id='', target_id='', extrude=None, altitude_mode=None, kml_coordinates=fastkml.geometry.Coordinates(ns='', name_spaces={'kml': '{http://www.opengis.net/kml/2.2}', 'atom': '{http://www.w3.org/2005/Atom}', 'gx': '{http://www.google.com/kml/ext/2.2}'}, coords=[(2.3488, 48.85341)], **{},), **{},)
>>> p.geometry
Point(2.3488, 48.85341)
>>> print(p)
<kml:Point xmlns:kml="http://www.opengis.net/kml/2.2">
  <coordinates>2.3488,48.85341</coordinates>
</kml:Point>

Fastkml 1.0.0 needs the namespace to be declared, e.g:

from fastkml import Point
p='<Point xmlns="http://www.opengis.net/kml/2.2"><coordinates>2.34880,48.85341</coordinates></Point>'
Point.from_string(p)
Point.from_string(p).validate()

or you can wrap it into a Placemark with the namespace:

from fastkml import Placemark
p="<Point><coordinates>2.34880,48.85341</coordinates></Point>"
pm=f'<Placemark xmlns="http://www.opengis.net/kml/2.2">{p}</Placemark>'
Placemark.from_string(pm)
Placemark.from_string(pm).validate()
Source Link
cleder
  • 126
  • 3

Fastkml needs the namespace to be declared, e.g:

from fastkml import Point
p='<Point xmlns="http://www.opengis.net/kml/2.2"><coordinates>2.34880,48.85341</coordinates></Point>'
Point.from_string(p)
Point.from_string(p).validate()

or you can wrap it into a Placemark with the namespace:

from fastkml import Placemark
p="<Point><coordinates>2.34880,48.85341</coordinates></Point>"
pm=f'<Placemark xmlns="http://www.opengis.net/kml/2.2">{p}</Placemark>'
Placemark.from_string(pm)
Placemark.from_string(pm).validate()