Skip to content

Commit

Permalink
Many, but not all, suggested pep8 changes. Unit tests all pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce Jasmer committed Jan 9, 2014
1 parent 4399eca commit 9d801a8
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 130 deletions.
3 changes: 3 additions & 0 deletions gpxinfo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import gpxpy as mod_gpxpy

gpx_files = mod_sys.argv[1:]


def format_time(time_s):
if not time_s:
return 'n/a'
Expand All @@ -21,6 +22,7 @@ def format_time(time_s):

return '%s:%s:%s' % (str(int(hours)).zfill(2), str(int(minutes % 60)).zfill(2), str(int(time_s % 60)).zfill(2))


def print_gpx_part_info(gpx_part, indentation=' '):
"""
gpx_part may be a track or segment.
Expand Down Expand Up @@ -58,6 +60,7 @@ def print_gpx_part_info(gpx_part, indentation=' '):

print('')


def print_gpx_info(gpx):
print('File: %s' % gpx_file)

Expand Down
1 change: 1 addition & 0 deletions gpxpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


def parse(xml_or_file, parser=None):
"""
Parse xml (string) or file object. This is just an wrapper for
Expand Down
15 changes: 14 additions & 1 deletion gpxpy/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

EARTH_RADIUS = 6371 * 1000


def to_rad(x):
return x / 180. * mod_math.pi


def haversine_distance(latitude_1, longitude_1, latitude_2, longitude_2):
"""
Haversine distance between two points, expressed in meters.
Expand All @@ -49,6 +51,7 @@ def haversine_distance(latitude_1, longitude_1, latitude_2, longitude_2):

return d


def length(locations=None, _3d=None):
locations = locations or []
if not locations:
Expand All @@ -69,16 +72,19 @@ def length(locations=None, _3d=None):
length += d
return length


def length_2d(locations=None):
""" 2-dimensional length (meters) of locations (only latitude and longitude, no elevation). """
locations = locations or []
return length(locations, False)


def length_3d(locations=None):
""" 3-dimensional length (meters) of locations (it uses latitude, longitude, and elevation). """
locations = locations or []
return length(locations, True)


def calculate_max_speed(speeds_and_distances):
"""
Compute average distance and standard deviation for distance. Extremes
Expand Down Expand Up @@ -109,7 +115,7 @@ def calculate_max_speed(speeds_and_distances):

# sort by speed:
speeds = list(map(lambda speed_and_distance: speed_and_distance[0], filtered_speeds_and_distances))
if not isinstance(speeds, list): # python3
if not isinstance(speeds, list): # python3
speeds = list(speeds)
if not speeds:
return None
Expand All @@ -122,6 +128,7 @@ def calculate_max_speed(speeds_and_distances):

return speeds[index]


def calculate_uphill_downhill(elevations):
if not elevations:
return 0, 0
Expand Down Expand Up @@ -152,6 +159,7 @@ def __filter(n):

return uphill, downhill


def distance(latitude_1, longitude_1, elevation_1, latitude_2, longitude_2, elevation_2,
haversine=None):
"""
Expand Down Expand Up @@ -180,6 +188,7 @@ def distance(latitude_1, longitude_1, elevation_1, latitude_2, longitude_2, elev

return mod_math.sqrt(distance_2d ** 2 + (elevation_1 - elevation_2) ** 2)


def elevation_angle(location1, location2, radians=False):
""" Uphill/downhill angle between two locations. """
if location1.elevation is None or location2.elevation is None:
Expand All @@ -198,6 +207,7 @@ def elevation_angle(location1, location2, radians=False):

return 180 * angle / mod_math.pi


def distance_from_line(point, line_point_1, line_point_2):
""" Distance of point from a line given with two points. """
assert point, point
Expand All @@ -216,6 +226,7 @@ def distance_from_line(point, line_point_1, line_point_2):

return 2. * mod_math.sqrt(abs(s * (s - a) * (s - b) * (s - c))) / a


def get_line_equation_coefficients(location1, location2):
"""
Get line equation coefficients for:
Expand All @@ -231,6 +242,7 @@ def get_line_equation_coefficients(location1, location2):
b = location1.latitude - location1.longitude * a
return float(1), float(-a), float(-b)


def simplify_polyline(points, max_distance):
"""Does Ramer-Douglas-Peucker algorithm for simplification of polyline """

Expand Down Expand Up @@ -266,6 +278,7 @@ def simplify_polyline(points, max_distance):
return (simplify_polyline(points[:tmp_max_distance_position + 2], max_distance) +
simplify_polyline(points[tmp_max_distance_position + 1:], max_distance)[1:])


class Location:
""" Generic geographical location """

Expand Down
Loading

0 comments on commit 9d801a8

Please sign in to comment.