better kml export
This commit is contained in:
@@ -4,6 +4,7 @@ from rowers.models import (
|
||||
Rower, Workout,
|
||||
GeoPoint, GeoPolygon, GeoCourse,
|
||||
course_length, course_coord_center, course_coord_maxmin,
|
||||
course_coord_crewnerd_navigation,
|
||||
polygon_coord_center, PlannedSession,
|
||||
polygon_to_path, coordinate_in_path
|
||||
)
|
||||
@@ -216,8 +217,17 @@ def get_polygons(polygonpms):
|
||||
|
||||
return polygons
|
||||
|
||||
def crewnerdify(polygons):
|
||||
polygons[0].name = "Start"
|
||||
polygons[len(polygons)-1].name = "Finish"
|
||||
|
||||
def coursetokml(course):
|
||||
if len(polygons) > 2:
|
||||
for i in range(1,len(polygons)-1):
|
||||
polygons[i].name = 'WP{n}'.format(n=polygons[i].order_in_course)
|
||||
|
||||
return polygons
|
||||
|
||||
def coursetokml(course,cn=False):
|
||||
top = Element('kml')
|
||||
for prefix, uri in xmlns_uris_dict.items():
|
||||
if prefix != '':
|
||||
@@ -227,23 +237,60 @@ def coursetokml(course):
|
||||
|
||||
document = SubElement(top, 'Document')
|
||||
name = SubElement(document, 'name')
|
||||
name.text = 'Courses.kml'
|
||||
folder = SubElement(document, 'Folder')
|
||||
foldername = SubElement(folder, 'name')
|
||||
foldername.text = 'Courses'
|
||||
folder2 = SubElement(folder, 'Folder')
|
||||
name.text = 'courses'
|
||||
opendoc = SubElement(document,'open')
|
||||
opendoc.text = '1'
|
||||
style = SubElement(document,'Style', id="default")
|
||||
linestyle = SubElement(style, 'LineStyle')
|
||||
linestylecolor = SubElement(linestyle, 'color')
|
||||
linestylecolor.text = "ff00ffff"
|
||||
polystyle = SubElement(style, 'PolyStyle')
|
||||
polystylecolor = SubElement(polystyle, 'color')
|
||||
polystylecolor.text = "ff7fffff"
|
||||
|
||||
stylemap = SubElement(document, 'StyleMap', id="default0")
|
||||
pair1 = SubElement(stylemap, 'Pair')
|
||||
pair1key = SubElement(pair1, 'key')
|
||||
pair1key.text = "normal"
|
||||
pair1styleurl = SubElement(pair1, 'styleUrl')
|
||||
pair1styleurl.text = "#default"
|
||||
pair2 = SubElement(stylemap, 'Pair')
|
||||
pair2key = SubElement(pair2, 'key')
|
||||
pair2key.text = "highlight"
|
||||
pair2styleurl = SubElement(pair2, 'styleUrl')
|
||||
pair2styleurl.text = "#hl"
|
||||
|
||||
stylehl = SubElement(document, 'Style', id="hl")
|
||||
iconstyle = SubElement(stylehl, 'IconStyle')
|
||||
scale = SubElement(iconstyle, 'scale')
|
||||
scale.text = "1.2"
|
||||
linestyle = SubElement(stylehl, 'LineStyle')
|
||||
linestylecolor = SubElement(linestyle, 'color')
|
||||
linestylecolor.text = "ff00ffff"
|
||||
polystyle = SubElement(stylehl, 'PolyStyle')
|
||||
polystylecolor = SubElement(polystyle, 'color')
|
||||
polystylecolor.text = "ff7fffff"
|
||||
|
||||
folder2 = SubElement(document, 'Folder')
|
||||
coursename = SubElement(folder2, 'name')
|
||||
coursename.text = course.name
|
||||
open = SubElement(folder2, 'open')
|
||||
open.text = '1'
|
||||
openst = SubElement(folder2, 'open')
|
||||
openst.text = '1'
|
||||
coursedescription = SubElement(folder2, 'description')
|
||||
coursedescription.text = "Rowsandall.com\n" + course.notes
|
||||
|
||||
polygons = GeoPolygon.objects.filter(
|
||||
course=course).order_by("order_in_course")
|
||||
|
||||
if cn:
|
||||
polygons = crewnerdify(polygons)
|
||||
|
||||
for polygon in polygons:
|
||||
placemark = SubElement(folder2, 'Placemark')
|
||||
polygonname = SubElement(placemark, 'name')
|
||||
polygonname.text = polygon.name
|
||||
polygonstyle = SubElement(placemark, 'styleUrl')
|
||||
polygonstyle.text = "#default0"
|
||||
p = SubElement(placemark, 'Polygon')
|
||||
tessellate = SubElement(p, 'tessellate')
|
||||
tessellate.text = '1'
|
||||
|
||||
Reference in New Issue
Block a user