Commit 400f6c68 authored by Aaron Culich's avatar Aaron Culich

handle coordinates tuples which contain spaces

Coordinates can be any number of tuples separated by a
space (potentially any number of whitespace characters).
Values in tuples should be separated by commas with no
spaces. Clean up badly formatted tuples by stripping
space following commas.

See reference: https://developers.google.com/kml/documentation/kmlreference#coordinates
parent 8e243962
...@@ -41,6 +41,7 @@ except ImportError: ...@@ -41,6 +41,7 @@ except ImportError:
from pygeoif.geometry import GeometryCollection from pygeoif.geometry import GeometryCollection
from pygeoif.geometry import as_shape as asShape from pygeoif.geometry import as_shape as asShape
import re
import fastkml.config as config import fastkml.config as config
from .config import etree from .config import etree
...@@ -314,7 +315,13 @@ class Geometry(_BaseObject): ...@@ -314,7 +315,13 @@ class Geometry(_BaseObject):
def _get_coordinates(self, element): def _get_coordinates(self, element):
coordinates = element.find('%scoordinates' % self.ns) coordinates = element.find('%scoordinates' % self.ns)
if coordinates is not None: if coordinates is not None:
latlons = coordinates.text.strip().split() # https://developers.google.com/kml/documentation/kmlreference#coordinates
# Coordinates can be any number of tuples separated by a
# space (potentially any number of whitespace characters).
# Values in tuples should be separated by commas with no
# spaces. Clean up badly formatted tuples by stripping
# space following commas.
latlons = re.sub(r', +', ',', coordinates.text.strip()).split()
coords = [] coords = []
for latlon in latlons: for latlon in latlons:
coords.append([float(c) for c in latlon.split(',')]) coords.append([float(c) for c in latlon.split(',')])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment