Private
Public Access
1
0

courses functionality

This commit is contained in:
Sander Roosendaal
2018-02-21 12:57:46 +01:00
parent d3e3925625
commit 289d3fc2cc
13 changed files with 322 additions and 62 deletions

View File

@@ -9,7 +9,6 @@ from django.db import IntegrityError
import uuid
from django.conf import settings
from utils import myqueue
from matplotlib import path
import xml.etree.ElementTree as et
@@ -18,10 +17,6 @@ import pandas as pd
ns = {'opengis': 'http://www.opengis.net/kml/2.2'}
import django_rq
queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
from rowers.models import (
Rower, Workout,
@@ -128,10 +123,27 @@ def time_in_polygon(df,polygon,maxmin='max'):
return time
def crewnerdcourse(doc):
courses = []
for course in doc:
name = course.findall('.//opengis:name',ns)[0].text
try:
description = course.findall('.//opengis:description',ns)[0].text
except IndexError:
description = ''
polygonpms = course.findall('.//opengis:Placemark[opengis:Polygon]',ns)
polygons = get_polygons(polygonpms)
def kmltocourse(f):
doc = et.parse(f)
polygonpms = doc.findall('.//opengis:Placemark[opengis:Polygon]',ns)
courses.append({
'name':name,
'description':description,
'polygons':polygons
})
return courses
def get_polygons(polygonpms):
polygons = []
for pm in polygonpms:
name = pm.findall('.//opengis:name',ns)[0].text
@@ -157,6 +169,19 @@ def kmltocourse(f):
})
return polygons
def kmltocourse(f):
doc = et.parse(f)
courses = doc.findall('.//opengis:Folder[opengis:Placemark]',ns)
if courses:
return crewnerdcourse(courses)
polygonpms = doc.findall('.//opengis:Placemark[opengis:Polygon]',ns)
return get_polygons(polygonpms)
from geopy.geocoders import Nominatim
geolocator = Nominatim()