Ejemplo n.º 1
0
    def testEcef(self, Ecef):

        self.test(Ecef.__name__, '...', '...', nl=1)

        Karney = Ecef is EcefKarney
        Sudano = Ecef is EcefSudano

        g = Ecef(Datums.WGS84, name='Test')
        self.test('name', g.name, 'Test')

        t = g.toStr2()
        self.test('toStr', t, g.classname, known=True)

        t = Ecef(g.a, g.f, name=g.name)  # coverage
        self.test('a, f', t, t.classname, known=True)

        self.testCopy(g)

        # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Geocentric.html>
        t = g.forward(27.99, 86.93, 8820)  # Mt Everest
        self.test('forward', fstr(t[3:6], prec=2), '27.99, 86.93, 8820.0')
        self.test('forward', fstr(t[0:3], prec=1),
                  '302271.4, 5635928.4, 2979666.1')
        self.test('name', t.name, 'Test')

        t = g.reverse(302271.4, 5635928.4, 2979666.1)
        self.test('reverse', fstr(t[0:3], prec=1),
                  '302271.4, 5635928.4, 2979666.1')
        self.test('reverse',
                  fstr(t[3:6], prec=2),
                  '27.99, 86.93, 8820.01',
                  known=Sudano and _known(t, 27.99, 8820))
        self.test('case', t.C, 2 if Karney else (5 if Sudano else 1))
        self.test('iteration', t.iteration, t.iteration)
        self.test('name', t.name, 'Test')

        # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Geocentric.html>
        t = g.reverse(302e3, 5636e3, 2980e3)
        self.test('reverse', fstr(t[0:3], prec=1),
                  '302000.0, 5636000.0, 2980000.0')
        self.test('reverse',
                  fstr(t[3:6], prec=2),
                  '27.99, 86.93, 9027.03',
                  known=Sudano and _known(t, 27.99, 9027))
        self.test('case', t.C, 2 if Karney else (5 if Sudano else 1))
        self.test('iteration', t.iteration, t.iteration)

        t = g.forward(27.99, 86.93, 8820.0)
        self.test('forward', fstr(t[3:6], prec=2), '27.99, 86.93, 8820.0')
        self.test('forward', fstr(t[0:3], prec=2),
                  '302271.43, 5635928.37, 2979666.13')

        # <https://GeographicLib.SourceForge.io/html/CartConvert.1.html>
        t = g.forward(33.3, 44.4, 6000)
        self.test('forward', fstr(t[3:6], prec=2), '33.3, 44.4, 6000.0')
        self.test('forward', fstr(t[0:3], prec=2),
                  '3816209.6, 3737108.55, 3485109.57')

        t = g.reverse(3816209.6, 3737108.55, 3485109.57)
        self.test('reverse', fstr(t[0:3], prec=2),
                  '3816209.6, 3737108.55, 3485109.57')
        self.test('reverse',
                  fstr(t[3:6], prec=3),
                  '33.3, 44.4, 5999.996',
                  known=Sudano and _known(t, 33.3, 5999))
        self.test('case', t.C, 2 if Karney else (5 if Sudano else 1))
        self.test('iteration', t.iteration, t.iteration)

        # <https://GeographicLib.SourceForge.io/html/CartConvert.1.html>
        t = g.reverse(30000, 30000, 0)
        self.test('reverse', fstr(t[0:3], prec=1), '30000.0, 30000.0, 0.0')
        self.test('reverse',
                  fstr(t[3:6], prec=3),
                  '6.483, 45.0, -6335709.726',
                  known=not Karney)
        self.test('case', t.C, 3 if Karney else (0 if Sudano else 1))
        self.test('iteration', t.iteration, t.iteration)

        t = g.forward(6.483, 45.0, -6335709.726)
        self.test('forward', fstr(t[3:6], prec=3), '6.483, 45.0, -6335709.726')
        self.test('forward',
                  fstr(t[0:3], prec=1),
                  '30000.0, 30000.0, -0.0',
                  known=True)

        # Rey-Jer You <https://www.ResearchGate.net/publication/240359424>
        for i, (x, y, z, h) in enumerate(
            ((-2259148.993, 3912960.837, 4488055.516,
              1e3), (-2259502.546, 3913573.210, 4488762.622,
                     2e3), (-2259856.100, 3914185.582, 4489469.729, 3e3),
             (-2260209.653, 3914797.955, 4490176.836,
              4e3), (-2262330.973, 3918472.189, 4494419.477,
                     1e4), (-2265866.507, 3924595.914, 4501490.544, 2e4),
             (-2294150.778, 3973585.709, 4558059.087,
              1e5), (-2541638.152, 4402246.414, 5053033.834,
                     8e5), (-2612348.830, 4524720.901, 5194455.190, 1e6))):
            i = '-%d' % (i + 1, )
            r = '45.0, 120.0, %.1f' % (h, )  # Zero and First order columns
            t = g.reverse(x, y, z)
            k = Sudano and _known(t, 45, h)
            self.test('reverse' + i, fstr(t[3:6], prec=3), r, known=k)
            f = g.forward(t.lat, t.lon, t.height)
            self.test('forward' + i,
                      fstr(f[0:3], prec=1),
                      fstr((x, y, z), prec=1),
                      known=k)
            self.test('xyzh' + i,
                      fstr(f.xyzh, prec=1),
                      fstr((x, y, z, h), prec=1),
                      known=k)
            f = f.phi, f.lam
            t = radians(t.lat), radians(t.lon)
            self.test('philam' + i, fstr(f, prec=4), fstr(t, prec=4))

        # <https://www.researchgate.net/publication/3709199_An_exact_conversion_from_an_Earth-centered_coordinate_system_to_latitude_longitude_and_altitude>
        t = g.reverse(4588301.55696757, 0, 4558059.086984613)
        self.test('sudano',
                  fstr(t[3:6], prec=3),
                  '45.0, 0.0, 100000.0',
                  known=Sudano)

        # <https://www.OrdnanceSurvey.co.UK/documents/resources/guide-coordinate-systems-great-britain.pdf> pp 47
        g = Ecef(Ellipsoids.GRS80, name='OS-UK')
        self.test('name', g.name, 'OS-UK')

        t = g.forward(
            parse3llh('''53°36′43.1653"N, 001°39′51.9920"W, 299.800'''))
        self.test('forward', fstr(t[3:6], prec=8),
                  '53.61199036, -1.66444222, 299.8')
        self.test('forward', fstr(t[0:3], prec=2),
                  '3790644.9, -110149.21, 5111482.97')

        t = g.reverse(3790644.9, -110149.21, 5111482.97)
        self.test('reverse', fstr(t[0:3], prec=2),
                  '3790644.9, -110149.21, 5111482.97')
        self.test('reverse',
                  fstr(t[3:5], prec=8),
                  '53.61199036, -1.66444223',
                  known=Sudano)
        self.test('reverse.lat',
                  latDMS(t.lat, prec=4),
                  '53°36′43.1653″N',
                  known=Sudano)
        self.test('reverse.lon', lonDMS(t.lon, prec=4), '001°39′51.992″W')
        self.test('reverse.height',
                  fstr(t.height, prec=-3),
                  '299.800',
                  known=Sudano)
        self.test('case', t.C, 2 if Karney else (6 if Sudano else 1))
        self.test('iteration', t.iteration, t.iteration)

        # coverage
        self.test(EcefError.__name__,
                  g.reverse(0, 0, 0),
                  '(0.0, 0.0, ...)',
                  known=True)
        try:
            self.test(EcefError.__name__, g.forward(None, None, None),
                      EcefError.__name__)
        except Exception as x:
            self.test(EcefError.__name__,
                      str(x).split(':')[0],
                      'lat (None), lon (None) ...',
                      known=True)
        try:
            self.test(Ecef.__name__, Ecef(None), EcefError.__name__)
        except Exception as x:
            self.test(Ecef.__name__, str(x), Ecef.__name__, known=True)
Ejemplo n.º 2
0
    def testEcef(self, Ecef):

        self.test(Ecef.__name__, '...', '...', nl=1)

        Karney = Ecef is EcefKarney

        g = Ecef(Datums.WGS84, name='Test')
        self.test('name', g.name, 'Test')

        t = g.toStr2()
        self.test('toStr', t, g.classname, known=True)

        # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Geocentric.html>
        t = g.forward(27.99, 86.93, 8820)  # Mt Everest
        self.test('forward', fStr(t[3:6], prec=2), '27.99, 86.93, 8820.0')
        self.test('forward', fStr(t[0:3], prec=1),
                  '302271.4, 5635928.4, 2979666.1')
        self.test('name', t.name, 'Test')

        t = g.reverse(302271.4, 5635928.4, 2979666.1)
        self.test('reverse', fStr(t[0:3], prec=1),
                  '302271.4, 5635928.4, 2979666.1')
        self.test('reverse', fStr(t[3:6], prec=2), '27.99, 86.93, 8820.01')
        self.test('case', t.C, 2 if Karney else 1)
        self.test('name', t.name, 'Test')

        # <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Geocentric.html>
        t = g.reverse(302e3, 5636e3, 2980e3)
        self.test('reverse', fStr(t[0:3], prec=1),
                  '302000.0, 5636000.0, 2980000.0')
        self.test('reverse', fStr(t[3:6], prec=2),
                  '27.99, 86.93, 9027.03')  # 8820.0
        self.test('case', t.C, 2 if Karney else 1)

        t = g.forward(27.99, 86.93, 8820.0)
        self.test('forward', fStr(t[3:6], prec=2), '27.99, 86.93, 8820.0')
        self.test('forward', fStr(t[0:3], prec=2),
                  '302271.43, 5635928.37, 2979666.13')

        # <https://GeographicLib.SourceForge.io/html/CartConvert.1.html>
        t = g.forward(33.3, 44.4, 6000)
        self.test('forward', fStr(t[3:6], prec=2), '33.3, 44.4, 6000.0')
        self.test('forward', fStr(t[0:3], prec=2),
                  '3816209.6, 3737108.55, 3485109.57')

        t = g.reverse(3816209.6, 3737108.55, 3485109.57)
        self.test('reverse', fStr(t[0:3], prec=2),
                  '3816209.6, 3737108.55, 3485109.57')
        self.test('reverse', fStr(t[3:6], prec=3),
                  '33.3, 44.4, 5999.996')  # 6000.0
        self.test('case', t.C, 2 if Karney else 1)

        # <https://GeographicLib.SourceForge.io/html/CartConvert.1.html>
        t = g.reverse(30000, 30000, 0)
        self.test('reverse', fStr(t[0:3], prec=1), '30000.0, 30000.0, 0.0')
        self.test('reverse',
                  fStr(t[3:6], prec=3),
                  '6.483, 45.0, -6335709.726',
                  known=not Karney)
        self.test('case', t.C, 3 if Karney else 1)

        t = g.forward(6.483, 45.0, -6335709.726)
        self.test('forward', fStr(t[3:6], prec=3), '6.483, 45.0, -6335709.726')
        self.test('forward',
                  fStr(t[0:3], prec=1),
                  '30000.0, 30000.0, -0.0',
                  known=True)

        # Rey-Jer You <https://www.ResearchGate.net/publication/240359424>
        for i, (x, y, z, h) in enumerate(
            ((-2259148.993, 3912960.837, 4488055.516,
              1e3), (-2259502.546, 3913573.210, 4488762.622,
                     2e3), (-2259856.100, 3914185.582, 4489469.729, 3e3),
             (-2260209.653, 3914797.955, 4490176.836,
              4e3), (-2262330.973, 3918472.189, 4494419.477,
                     1e4), (-2265866.507, 3924595.914, 4501490.544, 2e4),
             (-2294150.778, 3973585.709, 4558059.087,
              1e5), (-2541638.152, 4402246.414, 5053033.834,
                     8e5), (-2612348.830, 4524720.901, 5194455.190, 1e6))):
            i = '-%d' % (i + 1, )
            r = '45.0, 120.0, %.1f' % (h, )  # Zero and First order columns
            t = g.reverse(x, y, z)
            self.test('reverse' + i, fStr(t[3:6], prec=3), r)
            t = g.forward(t.lat, t.lon, t.height)
            self.test('forward' + i, fStr(t[0:3], prec=1),
                      fStr((x, y, z), prec=1))

        # <https://www.OrdnanceSurvey.co.UK/documents/resources/guide-coordinate-systems-great-britain.pdf> pp 47
        g = Ecef(Ellipsoids.GRS80, name='OS-UK')
        self.test('name', g.name, 'OS-UK')

        t = g.forward(
            parse3llh('''53°36′43.1653"N, 001°39′51.9920"W, 299.800'''))
        self.test('forward', fStr(t[3:6], prec=8),
                  '53.61199036, -1.66444222, 299.8')
        self.test('forward', fStr(t[0:3], prec=2),
                  '3790644.9, -110149.21, 5111482.97')

        t = g.reverse(3790644.9, -110149.21, 5111482.97)
        self.test('reverse', fStr(t[0:3], prec=2),
                  '3790644.9, -110149.21, 5111482.97')
        self.test('reverse', fStr(t[3:5], prec=8), '53.61199036, -1.66444223')
        self.test('reverse.lat', latDMS(t.lat, prec=4), '53°36′43.1653″N')
        self.test('reverse.lon', lonDMS(t.lon, prec=4), '001°39′51.992″W')
        self.test('reverse.height', fStr(t.height, prec=-3), '299.800')
        self.test('case', t.C, 2 if Karney else 1)