Exemplo n.º 1
0
    def testErrors(self, InvalidError, IsnotError):

        e = InvalidError(zero=1)
        self.test(InvalidError.__name__, e, 'zero (1): invalid')
        self.test(InvalidError.__name__,
                  repr(e).replace(',)', ')'),
                  "ValueError('zero (1): invalid')")
        e = InvalidError(zero=1, one=2, txt='outside')
        self.test(InvalidError.__name__, e, 'one (2) or zero (1): outside')
        self.test(InvalidError.__name__,
                  repr(e).replace(',)', ')'),
                  "ValueError('one (2) or zero (1): outside')")
        e = InvalidError(zero=1, Error=RangeError, one=2, txt='outside')
        self.test(InvalidError.__name__, e, 'one (2) or zero (1): outside')
        self.test(InvalidError.__name__,
                  repr(e).replace(',)', ')'),
                  "RangeError('one (2) or zero (1): outside')")
        e = InvalidError(two=2, Error=ValueError)  # coverage

        e = IsnotError(int.__name__, float.__name__, _None=None)
        self.test(IsnotError.__name__, e, '_None (None) not an int or float')
        self.test(IsnotError.__name__,
                  repr(e).replace(',)', ')'),
                  "TypeError('_None (None) not an int or float')")

        e = IsnotError('scalar', _None=None)
        self.test(IsnotError.__name__, e, '_None (None) not scalar')
        self.test(IsnotError.__name__,
                  repr(e).replace(',)', ')'),
                  "TypeError('_None (None) not scalar')")
        e = IsnotError('scalar', Error=LimitError, _None=None)
        self.test(IsnotError.__name__, e, '_None (None) not scalar: invalid')
        self.test(IsnotError.__name__,
                  repr(e).replace(',)', ')'),
                  "LimitError('_None (None) not scalar: invalid')")

        try:
            raise LenError(LenError, a=1, b=2, c=3, d=4)
            self.test(LenError.__name__, None, LenError.__name__)
        except ValueError as x:
            self.test(LenError.__name__, str(x),
                      'LenError(a, b, c, d) len 1 vs 2 vs 3 vs 4: invalid')

        self.test(crosserrors.__name__, crosserrors(False), True)
        self.test(crosserrors.__name__, crosserrors(True), False)
        self.test(limiterrors.__name__, limiterrors(False), True)
        self.test(limiterrors.__name__, limiterrors(True), False)
        self.test(rangerrors.__name__, rangerrors(False), True)
        self.test(rangerrors.__name__, rangerrors(True), False)

        x = True if environ.get('PYGEODESY_EXCEPTION_CHAINING',
                                None) else False
        self.test(exception_chaining.__name__, exception_chaining(),
                  x if isPython3 else None)
        self.test(exception_chaining.__name__,
                  exception_chaining(RangeError()), None)
        self.test(exception_chaining.__name__, exception_chaining(TypeError()),
                  None)
Exemplo n.º 2
0
    def testGreatCircle(self, module):  # spherical only

        self.subtitle(module, 'GreatCircle')

        LatLon = module.LatLon

        # Indian Pond, in Piermond, NH.  My old Boy Scout Camp
        IndianPond = LatLon(43.930912, -72.053811)
        Eiffel = LatLon(48.858158, 2.294825)
        Versailles = LatLon(48.804766, 2.120339)
        StGermain = LatLon(48.897728, 2.094977)
        Orly = LatLon(48.747114, 2.400526)

        # distance between the Eiffel Tower and Versailles in meter
        dEiffelToVersailles = 14084.280704919687
        xEiffelToVersailles = '%.6f'  # '%.8f'

        # initial and final bearings between Eiffel tower and Versailles
        ibEiffelToVersailles = 245.13460296861962
        fbEiffelToVersailles = 245.00325395138532
        xbEiffelToVersailles = '%.8f'  # '%.14f'

        # initial and final bearing between Versailles and Eiffel tower
        ibVersaillesToEiffel = 65.003253951385318
        fbVersaillesToEiffel = 65.134602968619618
        xbVersaillesToEiffel = '%.9f'  # '%.15f'

        xMidpoint = '%.8f'

        c = crosserrors(False)  # no CrossErrors

        # initial bearing for two locations that are the same
        b = IndianPond.initialBearingTo(IndianPond)
        self.test('InitialBearingSameLocations', b, 0.0, '%.1f')

        # initial bearing for two locations that are the equal
        b = IndianPond.initialBearingTo(IndianPond.copy())
        self.test('InitialBearingEqualLocations', b, 0.0, '%.1f')

        # final bearing for two locations that are the same
        b = IndianPond.finalBearingTo(IndianPond)
        self.test('FinalBearingSameLocations', b, 180.0, '%.1f')  # 0.0

        # final bearing for two locations that are the equal
        b = IndianPond.finalBearingTo(IndianPond.copy())
        self.test('FinalBearingEqualLocations', b, 180.0, '%.1f')  # 0.0

        c = crosserrors(c)

        try:  # should raise CrossError
            b = IndianPond.initialBearingTo(IndianPond)
        except CrossError as x:
            self.test(
                'FinalBearingCrossError', str(x),
                'coincident points: LatLon(43°55′51.28″N, 072°03′13.72″W)')

        # distance for two locations that are the same
        d = IndianPond.distanceTo(IndianPond)
        self.test('DistanceSameLocations', d, 0.0, '%.1f')

        # distance for two locations that are equal
        d = IndianPond.distanceTo(IndianPond.copy())
        self.test('DistanceEqualLocations', d, 0.0, '%.1f')

        # distance between Eiffel Tower and Versailles
        d = Eiffel.distanceTo(Versailles)
        self.test('DistanceEiffelToVersailles',
                  d,
                  dEiffelToVersailles,
                  fmt=xEiffelToVersailles,
                  known=True)

        # distance between Versailles and Eiffel Tower
        d = Versailles.distanceTo(Eiffel)
        self.test('DistanceVersaillesToEiffel',
                  d,
                  dEiffelToVersailles,
                  fmt=xEiffelToVersailles,
                  known=True)

        # initial bearing between Eiffel Tower and Versailles
        b = Eiffel.initialBearingTo(Versailles)
        self.test('InitialBearingEiffelToVersailles',
                  b,
                  ibEiffelToVersailles,
                  fmt=xbEiffelToVersailles)
        self.test('InitialBearingEiffelToVersailles(DMS)',
                  bearingDMS(b, F_DMS, prec=4), '245°08′04.5707″')

        # initial bearing between Versailles and Eiffel Tower
        b = Versailles.initialBearingTo(Eiffel)
        self.test('InitialBearingVersaillesToEiffel',
                  b,
                  ibVersaillesToEiffel,
                  fmt=xbVersaillesToEiffel)
        self.test('InitialBearingVersaillesToEiffel(DMS)',
                  bearingDMS(b, F_DMS, prec=4), '65°00′11.7142″')

        # final bearing between Eiffel Tower and Versailles
        b = Eiffel.finalBearingTo(Versailles)
        self.test('FinalBearingEiffelToVersailles',
                  b,
                  fbEiffelToVersailles,
                  fmt=xbEiffelToVersailles)
        self.test('FinalBearingEiffelToVersailles(DMS)',
                  bearingDMS(b, F_DMS, prec=4), '245°00′11.7142″')

        # final bearing between Versailles and Eiffel Tower
        b = Versailles.finalBearingTo(Eiffel)
        self.test('FinalBearingVersaillesToEiffel',
                  b,
                  fbVersaillesToEiffel,
                  fmt=xbVersaillesToEiffel)
        self.test('FinalBearingVersaillesToEiffel(DMS)',
                  bearingDMS(b, F_DMS, prec=4), '65°08′04.5707″')

        # generating a location for Versailles based on bearing and distance
        v = Eiffel.destination(dEiffelToVersailles, ibEiffelToVersailles)
        self.test('GenerateLocationVersailles', v, str(Versailles))

        # generating a location for Eiffel based on bearing and distance.
        e = Versailles.destination(dEiffelToVersailles, ibVersaillesToEiffel)
        self.test('GenerateLocationEiffel', e, str(Eiffel))

        # midpoint between the Eiffel and Versailles
        a = Eiffel.midpointTo(Versailles)
        b = Eiffel.destination(dEiffelToVersailles / 2.0, ibEiffelToVersailles)
        self.test('MidpointEiffelToVersailles', a, str(b))
        self.test('MidpointEiffelToVersailles(DMS)', a.toStr(F_DMS, prec=4),
                  '48°49′53.3817″N, 002°12′27.1279″E')
        a = Eiffel.distanceTo(a)
        m = Versailles.distanceTo(b)
        self.test('MidpointEiffelToVersailles(m)',
                  a,
                  m,
                  fmt=xMidpoint,
                  known=True)

        # midpoint between Versailles and the Eiffel Tower
        a = Versailles.midpointTo(Eiffel)
        b = Versailles.destination(dEiffelToVersailles / 2.0,
                                   ibVersaillesToEiffel)
        self.test('MidpointVersaillesToEiffel', a, str(b), known=True)
        self.test('MidpointVersaillesToEiffel(DMS)', a.toStr(F_DMS, prec=4),
                  '48°49′53.3817″N, 002°12′27.1279″E')
        a = Versailles.distanceTo(a)
        m = Eiffel.distanceTo(b)
        self.test('MidpointVersaillesToEiffel(m)',
                  a,
                  m,
                  fmt=xMidpoint,
                  known=True)

        # intersection.
        b = StGermain.initialBearingTo(Orly)
        i = StGermain.intersection(b, Eiffel, ibEiffelToVersailles)
        self.test(
            'Intersection', i.toStr(F_D, prec=9),
            '48.83569095°N, 002.221252031°E')  # '48.83569094988361°N, ...
        self.test('Intersection', i.toStr(F_D, prec=13),
                  '48.8356909498836°N, 002.2212520313074°E'
                  )  # 002.2212520313073583°E'

        # cross-track distance test of a point 90° and 200 meters away
        m = Eiffel.midpointTo(Versailles)
        b = Eiffel.initialBearingTo(Versailles)
        p = m.destination(200.0, (b + 90) % 360.0)
        d = p.crossTrackDistanceTo(Eiffel, Versailles)
        self.test('CrossTrackDistance200m+90°', d, 200.0, fmt='%0.1f')

        # cross-track distance test of a point 270° and 200 meters away
        m = Eiffel.midpointTo(Versailles)
        b = Eiffel.initialBearingTo(Versailles)
        p = m.destination(200.0, (b + 270) % 360.0)
        d = p.crossTrackDistanceTo(Eiffel, Versailles)
        self.test('CrossTrackDistance200m+270°', d, -200.0, fmt='%0.1f')

        # cross-track distance that should be very close to 0
        m = Eiffel.midpointTo(Versailles)
        d = abs(m.crossTrackDistanceTo(Eiffel, Versailles))
        self.test('CrossTrackDistanceCloseToZero', d, '0.0000000', fmt='%.7f')