Beispiel #1
0
  def distance(self, coord1, coord2):
    """Compute the distance using the great circle."""
    sinsin_lat = coord1.lat.sin() * coord2.lat.sin()
    coscos_lat = coord1.lat.cos() * coord2.lat.cos()
    cos_deltalong = coord1.delta_long(coord2).cos()

    angle = AngleDeg().acos(sinsin_lat + coscos_lat * cos_deltalong)

    return angle.dist_from_radius(EARTH_RADIUS)
Beispiel #2
0
    def distance(self, coord1, coord2):
        """Compute the distance using the great circle."""
        sinsin_lat = coord1.lat.sin() * coord2.lat.sin()
        coscos_lat = coord1.lat.cos() * coord2.lat.cos()
        cos_deltalong = coord1.delta_long(coord2).cos()

        angle = AngleDeg().acos(sinsin_lat + coscos_lat * cos_deltalong)

        return angle.dist_from_radius(EARTH_RADIUS)
Beispiel #3
0
 def test_degtorad(self):
   self.assertAlmostEqual(AngleDeg(180.0).rad, math.pi)
   self.assertAlmostEqual(AngleDeg(450.0).rad, (math.pi / 2))
Beispiel #4
0
#!/usr/bin/env python2.7
# Copyright (C) 2013 by Ken Guyton.  All Rights Reserved.
"""Illustrate the basic usage of the geodist library."""

__author__ = 'Ken Guyton'

from kmg import geodist
from kmg.angle import AngleDeg

LAT1 = AngleDeg(37.61940)
LONG1 = AngleDeg(-122.37392)

LAT2 = AngleDeg(37.77677)
LONG2 = AngleDeg(-122.41673)


def main():
    coord1 = geodist.Coordinate(LAT1, LONG1)
    coord2 = geodist.Coordinate(LAT2, LONG2)

    dist_obj = geodist.GeoDist()
    distance = dist_obj.distance(coord1, coord2)

    print '%.2f miles' % distance


if __name__ == '__main__':
    main()
Beispiel #5
0
 def test_equal(self):
   self.assertEqual(AngleDeg(30.0), AngleDeg(30.0))
   self.assertEqual(AngleDeg(90.0), AngleDeg(90.0))
   self.assertEqual(AngleDeg(198.0), AngleDeg(198.0))
Beispiel #6
0
 def test_create(self):
   angle1 = AngleDeg()
   self.assertEqual(angle1.deg, 0.0)
   self.assertEqual(angle1.rad, 0.0)
Beispiel #7
0
 def test_cos(self):
   self.assertAlmostEqual(AngleDeg(60.0).cos(), 0.5, delta=4)
   self.assertAlmostEqual(AngleDeg(0.0).cos(), 1.0, delta=4)
   self.assertAlmostEqual(AngleDeg(90.0).cos(), 0.0, delta=4)
Beispiel #8
0
 def test_sin(self):
   self.assertAlmostEqual(AngleDeg(30.0).sin(), 0.5, delta=4)
   self.assertAlmostEqual(AngleDeg(90.0).sin(), 1.0, delta=4)
   self.assertAlmostEqual(AngleDeg(180.0).sin(), 0.0, delta=4)
Beispiel #9
0
  def test_distfromradius(self):
    """For a radius convert the angle to a distance."""

    test_angle = AngleDeg(10.0)
    dist = test_angle.dist_from_radius(100.0)
    self.assertAlmostEqual(dist, 17.4532, delta=4)
Beispiel #10
0
# Copyright (C) 2013 by Ken Guyton.  All Rights Reserved.
"""Test the geodist module."""

__author__ = 'Ken Guyton'

import math
import unittest
from kmg import geodist
from kmg.angle import AngleRad
from kmg.angle import AngleDeg

# In miles.
ONE_DEG_OF_LAT = 69.0933

# In degrees.
TEST_LAT = AngleDeg(33.0)

# In miles.
PARALLEL_RADIUS = 3320.0910
ONE_DEG_OF_LONG = 57.9465

LAT1 = AngleDeg(33.77264)
LONG1 = AngleDeg(-84.39290)

LAT2 = AngleDeg(33.94979)
LONG2 = AngleDeg(-83.37332)

ONE_DEG = AngleDeg(1.0)

# In miles.
# From Google maps 59.8288 mi, delta = 25.87 ft.
Beispiel #11
0
#!/usr/bin/env python2.7
# Copyright (C) 2013 by Ken Guyton.  All Rights Reserved.
"""Compute the distance from SFO to Twitter.

This is a test and example file for using geodist.
"""

__author__ = 'Ken Guyton'

from kmg import geodist
from kmg.angle import AngleDeg

SFO_LAT = AngleDeg(37.61940)
SFO_LONG = AngleDeg(-122.37392)

TW_LAT = AngleDeg(37.77677)
TW_LONG = AngleDeg(-122.41673)

# Distance measured with measurement tool on Google Maps.
GMAP_DIST = 11.1148


def report_error(orig_dist, a_dist):
    """Report the error given an actual dist."""

    error = orig_dist - a_dist
    error_ft = error * 5280.0
    percent_err = error / orig_dist * 100.0

    print 'Computed distance SFO to Twitter: %.4f miles.' % a_dist
    print 'Original dist: %.4f miles.' % orig_dist