exporting courses.kml
This commit is contained in:
@@ -227,57 +227,22 @@ def crewnerdify(polygons):
|
||||
|
||||
return polygons
|
||||
|
||||
def coursetokml(course,cn=False):
|
||||
top = Element('kml')
|
||||
for prefix, uri in xmlns_uris_dict.items():
|
||||
if prefix != '':
|
||||
top.attrib['xmlns:' + prefix] = uri
|
||||
else:
|
||||
top.attrib['xmlns'] = uri
|
||||
def removewhitespace(s):
|
||||
regels = s.split('\n')
|
||||
regels = [regel for regel in regels if regel.strip()]
|
||||
return "\n".join(regels)
|
||||
|
||||
document = SubElement(top, 'Document')
|
||||
name = SubElement(document, 'name')
|
||||
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"
|
||||
|
||||
def getcoursefolder(course, document, cn=False):
|
||||
folder2 = SubElement(document, 'Folder')
|
||||
coursename = SubElement(folder2, 'name')
|
||||
coursename.text = course.name
|
||||
openst = SubElement(folder2, 'open')
|
||||
openst.text = '1'
|
||||
coursedescription = SubElement(folder2, 'description')
|
||||
coursedescription.text = "Rowsandall.com\n" + course.notes
|
||||
if len(removewhitespace(course.notes)):
|
||||
coursedescription.text = "Rowsandall.com\n" + removewhitespace(course.notes)
|
||||
else:
|
||||
coursedescription.text = "Rowsandall.com " + course.name
|
||||
|
||||
polygons = GeoPolygon.objects.filter(
|
||||
course=course).order_by("order_in_course")
|
||||
@@ -310,6 +275,87 @@ def coursetokml(course,cn=False):
|
||||
lat=points[0].latitude,
|
||||
lon=points[0].longitude,
|
||||
)
|
||||
return folder2
|
||||
|
||||
def getstyle(document, id):
|
||||
style = SubElement(document,'Style', id=id)
|
||||
iconstyle = SubElement(style, 'IconStyle')
|
||||
scale = SubElement(iconstyle, 'scale')
|
||||
scale.text = "1.2"
|
||||
linestyle = SubElement(style, 'LineStyle')
|
||||
linestylecolor = SubElement(linestyle, 'color')
|
||||
linestylecolor.text = "ff00ffff"
|
||||
polystyle = SubElement(style, 'PolyStyle')
|
||||
polystylecolor = SubElement(polystyle, 'color')
|
||||
polystylecolor.text = "ff7fffff"
|
||||
|
||||
return style
|
||||
|
||||
def getstylemap(document, id):
|
||||
stylemap = SubElement(document, 'StyleMap', id=id)
|
||||
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"
|
||||
|
||||
return stylemap
|
||||
|
||||
def coursestokml(courseids, cn=False):
|
||||
courses = GeoCourse.objects.filter(id__in=courseids)
|
||||
top = Element('kml')
|
||||
for prefix, uri in xmlns_uris_dict.items():
|
||||
if prefix != '':
|
||||
top.attrib['xmlns:' + prefix] = uri
|
||||
else:
|
||||
top.attrib['xmlns'] = uri
|
||||
|
||||
document = SubElement(top, 'Document')
|
||||
name = SubElement(document, 'name')
|
||||
name.text = 'courses'
|
||||
|
||||
opendoc = SubElement(document,'open')
|
||||
opendoc.text = '1'
|
||||
|
||||
style = getstyle(document, "default")
|
||||
|
||||
stylemap = getstylemap(document, 'default0')
|
||||
|
||||
stylehl = getstyle(document, "hl")
|
||||
|
||||
for course in courses:
|
||||
coursefolder = getcoursefolder(course, document, cn=cn)
|
||||
|
||||
return prettify(top)
|
||||
|
||||
def coursetokml(course,cn=False):
|
||||
top = Element('kml')
|
||||
for prefix, uri in xmlns_uris_dict.items():
|
||||
if prefix != '':
|
||||
top.attrib['xmlns:' + prefix] = uri
|
||||
else:
|
||||
top.attrib['xmlns'] = uri
|
||||
|
||||
document = SubElement(top, 'Document')
|
||||
name = SubElement(document, 'name')
|
||||
name.text = 'courses'
|
||||
|
||||
opendoc = SubElement(document,'open')
|
||||
opendoc.text = '1'
|
||||
|
||||
style = getstyle(document, "default")
|
||||
|
||||
stylemap = getstylemap(document, 'default0')
|
||||
|
||||
stylehl = getstyle(document, "hl")
|
||||
|
||||
coursefolder = getcoursefolder(course, document, cn=cn)
|
||||
|
||||
|
||||
return prettify(top)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user