Skip to content

Commit

Permalink
add Line.length property and fix docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Sep 13, 2015
1 parent 9be1ee5 commit a26a92f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions narwhal/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ def _solve_NEB(alpha0, alpha1, beta1, beta2):
return alpha2, sigma2, omega2

def solve_astroid(a, f, lambda12, phi1, phi2):
""" Used to provide an initial guess to the inverse problem by solving the
corresponding problem on a sphere.
""" Used to provide an initial guess to the inverse problem in the case of
nearly antipodal points.
Parameters
----------
Expand All @@ -401,7 +401,8 @@ def solve_astroid(a, f, lambda12, phi1, phi2):
return alpha1

def solve_vicenty(a, f, lambda12, phi1, phi2):
""" Used to provide an initial guess in the case of nearly antipodal points.
""" Used to provide an initial guess to the inverse problem by solving the
corresponding problem on a sphere.
Parameters
----------
Expand Down Expand Up @@ -496,6 +497,10 @@ class Multipoint(MultipointBase):
class Line(MultipointBase):
_geotype = "Line"

@property
def length(self):
return sum(self[i].distance(self[i+1]) for i in range(len(self)-1))

if __name__ == "__main__":
# Karney's Table 2 example for the forward problem
print("Forward problem")
Expand Down
9 changes: 9 additions & 0 deletions tests/geo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def test_distance_equatorial(self):
self.assertLess(abs(d - 445277.963), 1.0) # from geod 4.8.0
return

def test_line_length(self):
line = Line([(70.205, 40.283166666666666),
(70.00516666666667, 40.011),
(69.89966666666666, 39.86),
(69.80066666666667, 39.6955),
(69.33383333333333, 39.0145),
(69.18316666666666, 38.79)], crs=LonLatWGS84)
self.assertAlmostEqual(line.length, 187650.3233, places=2)
return

class TestGeodesy(unittest.TestCase):

Expand Down

0 comments on commit a26a92f

Please sign in to comment.