more precise course length
This commit is contained in:
@@ -28,7 +28,8 @@ from rowers.models import (
|
||||
Rower, Workout,
|
||||
GeoPoint,GeoPolygon, GeoCourse,
|
||||
course_length,course_coord_center,course_coord_maxmin,
|
||||
polygon_coord_center,PlannedSession
|
||||
polygon_coord_center,PlannedSession,
|
||||
polygon_to_path,coordinate_in_path
|
||||
)
|
||||
|
||||
from utils import geo_distance
|
||||
@@ -41,56 +42,6 @@ class InvalidTrajectoryError(Exception):
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
def get_dir_vector(polygon1,polygon2):
|
||||
lat1,lon1 = polygon_coord_center(polygon1)
|
||||
lat2,lon2 = polygon_coord_center(polygon2)
|
||||
|
||||
return [lat2-lat1,lon2-lon1]
|
||||
|
||||
def get_delta(vector,polygon):
|
||||
x = pd.Series(range(10000))/9999.
|
||||
vlat = vector[0]
|
||||
vlon = vector[1]
|
||||
|
||||
lat1,lon1 = polygon_coord_center(polygon)
|
||||
|
||||
lat = x.apply(lambda x:lat1+x*vlat)
|
||||
lon = x.apply(lambda x:lon1+x*vlon)
|
||||
|
||||
totdist,bearing = geo_distance(lat1,lon1,lat1+vlat,lon1+vlat)
|
||||
print totdist
|
||||
|
||||
dist = x*totdist
|
||||
|
||||
p = polygon_to_path(polygon)
|
||||
|
||||
f = lambda x: coordinate_in_path(x['lat'],x['lon'],p)
|
||||
|
||||
df = pd.DataFrame({'x':x,
|
||||
'lat':lat,
|
||||
'lon':lon,
|
||||
'dist':dist,
|
||||
})
|
||||
|
||||
df['inpolygon'] = df.apply(f,axis=1)
|
||||
|
||||
|
||||
b = (~df['inpolygon']).shift(-1)+df['inpolygon']
|
||||
|
||||
|
||||
if len(df[b==2]):
|
||||
return 1.0e3*df[b==2]['dist'].min()
|
||||
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def get_delta_start(course):
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
vector = get_dir_vector(polygons[0],polygons[1])
|
||||
delta = get_delta(vector,polygons[0])
|
||||
|
||||
return delta
|
||||
|
||||
def get_course_timezone(course):
|
||||
polygons = GeoPolygon.objects.filter(course = course)
|
||||
@@ -111,19 +62,6 @@ def get_course_timezone(course):
|
||||
|
||||
return timezone_str
|
||||
|
||||
def polygon_to_path(polygon):
|
||||
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||
s = []
|
||||
for point in points:
|
||||
s.append([point.latitude,point.longitude])
|
||||
|
||||
p = path.Path(s[:-1])
|
||||
|
||||
return p
|
||||
|
||||
def coordinate_in_path(latitude,longitude, p):
|
||||
|
||||
return p.contains_points([(latitude,longitude)])[0]
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user