Skip to content

Commit d466ca3

Browse files
committed
kml: return objects rather than tuples for KML elements
1 parent c71ac6a commit d466ca3

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

MAVProxy/modules/lib/kmlread.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
namespaces = {'kml': 'http://www.opengis.net/kml/2.2'}
1414

1515

16+
class Polygon():
17+
def __init__(self, name, latlon):
18+
self.name = name
19+
self.vertexes = latlon
20+
21+
22+
class Point():
23+
def __init__(self, name, latlon):
24+
self.name = name
25+
self.latlon = latlon
26+
27+
1628
def readkmz(filename):
1729
'''reads in a kmz file and returns xml nodes'''
1830
# Strip quotation marks if neccessary
@@ -72,15 +84,15 @@ def readObject(innode):
7284
if coordinates is None:
7385
return None
7486
s = coordinates.text.split(',')
75-
return ("Point", name.text, [(float(s[1]), float(s[0]))])
87+
return Point(name.text, (float(s[1]), float(s[0])))
7688

7789
coordinates = find_tag_recursive(innode, 'coordinates')
7890
if coordinates is not None:
7991
latlon = []
8092
for c in coordinates.text.split():
8193
s = c.split(',')
8294
latlon.append((float(s[1]), float(s[0])))
83-
return ("Polygon", name.text, latlon)
95+
return Polygon(name.text, latlon)
8496

8597
return ('Unknown', None, None)
8698

MAVProxy/modules/mavproxy_kmlread.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -354,34 +354,33 @@ def loadkml(self, filename):
354354
continue
355355

356356
# and place any polygons on the map
357-
(pointtype, name, coords) = point
358-
if pointtype == 'Polygon':
359-
self.add_polygon(name, coords)
357+
if isinstance(point, kmlread.Polygon):
358+
self.add_polygon(point.name, point.vertexes)
360359

361360
# and points - barrell image and text
362-
if pointtype == 'Point':
363-
# print("Adding " + point[1])
361+
if isinstance(point, kmlread.Point):
362+
# print("Adding " + point.name)
364363
curpoint = mp_slipmap.SlipIcon(
365-
point[1],
366-
latlon=(point[2][0][0], point[2][0][1]),
364+
point.name,
365+
latlon=point.latlon,
367366
layer=3,
368367
img='barrell.png',
369368
rotation=0,
370369
follow=False,
371370
)
372371
curtext = mp_slipmap.SlipLabel(
373-
point[1],
374-
point=(point[2][0][0], point[2][0][1]),
372+
point.name,
373+
point=point.latlon,
375374
layer=4,
376-
label=point[1],
375+
label=point.name,
377376
colour=(0, 255, 255),
378377
)
379378
self.add_map_object(curpoint)
380379
self.add_map_object(curtext)
381380
self.allayers.append(curpoint)
382381
self.alltextlayers.append(curtext)
383-
self.curlayers.append(point[1])
384-
self.curtextlayers.append(point[1])
382+
self.curlayers.append(point.name)
383+
self.curtextlayers.append(point.name)
385384
self.menu_needs_refreshing = True
386385

387386
def idle_task(self):

MAVProxy/tools/mavflightview.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -680,27 +680,27 @@ def load_kml(kml):
680680
except Exception:
681681
continue
682682

683-
if point[0] == 'Polygon':
683+
if isinstance(point, kmlread.Polygon):
684684
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
685-
curpoly = mp_slipmap.SlipPolygon(point[1], point[2],
685+
curpoly = mp_slipmap.SlipPolygon(point.name, point.vertexes,
686686
layer=2, linewidth=2, colour=newcolour)
687687
ret.append(curpoly)
688688

689-
if point[0] == 'Point':
689+
if isinstance(point, kmlread.Point):
690690
icon = mp_tile.mp_icon('barrell.png')
691691
curpoint = mp_slipmap.SlipIcon(
692-
point[1],
693-
latlon=(point[2][0][0], point[2][0][1]),
692+
point.name,
693+
latlon=point.latlon,
694694
layer=3,
695695
img=icon,
696696
rotation=0,
697697
follow=False,
698698
)
699699
curtext = mp_slipmap.SlipLabel(
700-
point[1],
701-
point=(point[2][0][0], point[2][0][1]),
700+
point.name,
701+
point=point.latlon,
702702
layer=4,
703-
label=point[1],
703+
label=point.name,
704704
colour=(0, 255, 255),
705705
)
706706
ret.append(curpoint)

0 commit comments

Comments
 (0)