#elif point[1] > self.max[1]:
# self.max = (self.max[0], point[1])
+ def reverse(self):
+ '''
+ Invert the area
+ From clockwise to counter-clockwise
+ Or from counter-clockwise to clockwise
+ '''
+ self.points.reverse()
+
def check(self):
"""
Area library self-test:
return False
return True
-def load_area_from_kml_polygon(filename):
+def load_area_from_kml_polygon(filename, reverse=False):
"""
Loads a kml file into an Area structure.
The kml must contains exacly 1 polyline structure.
The first and last points must be the same.
It must also be counter-clockwise and convex.
+ Actually, it may be clockwise, but then you need reverse=True.
FIXME: This makes a lot of assumption about the way GoogleEarth output the
XML file.
coordinates_lines = [ line for line in kmlfile.readlines() if '</coordinates>' in line ]
assert len(coordinates_lines) == 1, \
'There should be exactly one line with coordinates in %s' % filename
- coordinates = coordinates_lines[0].replace('</coordinates>', '').replace('\n', '').replace('\r', '')
+ coordinates = coordinates_lines[0].replace('</coordinates>', '').replace('\n', '').replace('\r', '').replace('\t', '')
coordinates = [ xyz for xyz in coordinates.split(' ') if xyz ]
assert coordinates[0] == coordinates[-1], \
'First and last coordinates of %s should be the same: %s, %s' % \
for xyz in coordinates[0:-1]:
x, y, z = xyz.split(',')
area.addpoint((float(y), float(x)))
+ if reverse:
+ area.reverse()
assert area.check(), 'Polygon should be counter-clockwise and convex.'
return area