Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not self.points:
return None
sum_lat = 0.
sum_lon = 0.
n = 0.
for point in self.points:
n += 1.
sum_lat += point.latitude
sum_lon += point.longitude
if not n:
return mod_geo.Location(float(0), float(0))
return mod_geo.Location(latitude=sum_lat / n, longitude=sum_lon / n)
def simplify(self, max_distance=None):
"""
Simplify using the Ramer-Douglas-Peucker algorithm: http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
"""
if not max_distance:
max_distance = 10
self.points = mod_geo.simplify_polyline(self.points, max_distance)
segment. If elevation for some points is not found those are simply
ignored.
Returns
-------
uphill_downhill: UphillDownhill named tuple
uphill: float
Uphill elevation climbs in meters
downhill: float
Downhill elevation descent in meters
"""
if not self.points:
return UphillDownhill(0, 0)
elevations = list(map(lambda point: point.elevation, self.points))
uphill, downhill = mod_geo.calculate_uphill_downhill(elevations)
return UphillDownhill(uphill, downhill)
def _find_next_simplified_point(self, pos, max_distance):
for candidate in range(pos + 1, len(self.points) - 1):
for i in range(pos + 1, candidate):
d = mod_geo.distance_from_line(self.points[i],
self.points[pos],
self.points[candidate])
if d > max_distance:
return candidate - 1
return None
def length(self):
"""
Computes length (2-dimensional) of route.
Returns:
-----------
length: float
Length returned in meters
"""
return mod_geo.length_2d(self.points)
def getDistance(*coords):
return gpxpy.geo.haversine_distance(*coords)
speed_kmh = (distance / 1000.) / (mod_utils.total_seconds(timedelta) / 60. ** 2)
#print speed, stopped_speed_threshold
if speed_kmh <= stopped_speed_threshold:
stopped_time += mod_utils.total_seconds(timedelta)
stopped_distance += distance
else:
moving_time += mod_utils.total_seconds(timedelta)
moving_distance += distance
if distance and moving_time:
speeds_and_distances.append((distance / mod_utils.total_seconds(timedelta), distance, ))
max_speed = None
if speeds_and_distances:
max_speed = mod_geo.calculate_max_speed(speeds_and_distances)
return MovingData(moving_time, stopped_time, moving_distance, stopped_distance, max_speed)
def __init__(self, latitude=None, longitude=None, elevation=None, time=None,
name=None, description=None, symbol=None, type=None,
comment=None, horizontal_dilution=None, vertical_dilution=None,
position_dilution=None):
mod_geo.Location.__init__(self, latitude, longitude, elevation)
self.latitude = latitude
self.longitude = longitude
self.elevation = elevation
self.time = time
self.magnetic_variation = None
self.geoid_height = None
self.name = name
self.comment = comment
self.description = description
self.source = None
self.link = None
self.link_text = None
self.link_type = None
self.symbol = symbol
self.type = type
def length_3d(self):
"""
Computes 3-dimensional length of segment (latitude, longitude, and
elevation).
Returns
----------
length : float
Length returned in meters
"""
return mod_geo.length_3d(self.points)