exports valid kml
This commit is contained in:
@@ -14,6 +14,16 @@ import geocoder
|
|||||||
from matplotlib import path
|
from matplotlib import path
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
|
|
||||||
|
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
||||||
|
from xml.dom import minidom
|
||||||
|
|
||||||
|
def prettify(elem):
|
||||||
|
"""Return a pretty-printed XML string for the Element.
|
||||||
|
"""
|
||||||
|
rough_string = tostring(elem, 'utf-8')
|
||||||
|
reparsed = minidom.parseString(rough_string)
|
||||||
|
return reparsed.toprettyxml(indent=" ")
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from timezonefinder import TimezoneFinder
|
from timezonefinder import TimezoneFinder
|
||||||
@@ -108,6 +118,48 @@ def get_polygons(polygonpms):
|
|||||||
return polygons
|
return polygons
|
||||||
|
|
||||||
|
|
||||||
|
def coursetokml(course):
|
||||||
|
top = Element('kml')
|
||||||
|
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')
|
||||||
|
coursename = SubElement(folder2,'name')
|
||||||
|
coursename.text = course.name
|
||||||
|
open = SubElement(folder2,'open')
|
||||||
|
open.text = '1'
|
||||||
|
|
||||||
|
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||||
|
|
||||||
|
polygonsxml = []
|
||||||
|
|
||||||
|
for polygon in polygons:
|
||||||
|
placemark = SubElement(folder2,'Placemark')
|
||||||
|
polygonname = SubElement(placemark,'name')
|
||||||
|
polygonname.text = polygon.name
|
||||||
|
p = SubElement(placemark,'Polygon')
|
||||||
|
tessellate = SubElement(p,'tessellate')
|
||||||
|
tessellate.text = '1'
|
||||||
|
boundary = SubElement(p,'outerBoundaryIs')
|
||||||
|
ring = SubElement(boundary,'LinearRing')
|
||||||
|
coordinates = SubElement(ring,'coordinates')
|
||||||
|
coordinates.text = ''
|
||||||
|
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||||
|
for point in points:
|
||||||
|
coordinates.text += '{lon},{lat},0 '.format(
|
||||||
|
lat = point.latitude,
|
||||||
|
lon = point.longitude,
|
||||||
|
)
|
||||||
|
coordinates.text += '{lon},{lat},0'.format(
|
||||||
|
lat = points[0].latitude,
|
||||||
|
lon = points[0].longitude,
|
||||||
|
)
|
||||||
|
|
||||||
|
return prettify(top)
|
||||||
|
|
||||||
def kmltocourse(f):
|
def kmltocourse(f):
|
||||||
doc = et.parse(f)
|
doc = et.parse(f)
|
||||||
courses = doc.findall('.//opengis:Folder[opengis:Placemark]',ns)
|
courses = doc.findall('.//opengis:Folder[opengis:Placemark]',ns)
|
||||||
|
|||||||
Reference in New Issue
Block a user