示例#1
0
    def testGars(self, LL):

        # Karney's geographiclib/1.49/examples/example-GARS.cpp
        # <https://SourceForge.net/p/geographiclib/code/ci/release/tree/examples/example-GARS.cpp>
        g = Garef('57.64911, 10.40744', precision=2)
        self.test('Garef', g, '381NH45')
        self.test('Garef', repr(g), "Garef('381NH45')")
        self.test('Garef.precision', g.precision, 2)
        self.testCopy(g)

        self.test('Garef.latlon', fStr(g.latlon, prec=5), '57.64911, 10.40744')
        t = g.toLatLon(LL)
        self.test('Garef.toLatLon', repr(t),
                  'LatLon(57°38′56.8″N, 010°24′26.78″E)')
        self.testCodec3(g, '57.625, 10.375, 2.0', prec=4)
        t = Garef(t, precision=2, name='self')
        self.test('Garef(LatLon)', t, g)
        self.testCopy(t)

        for t in range(-1, 4):
            r = gars.resolution(t)
            p = gars.precision(r)
            self.test('precision', t, p, known=t < 0 or t > 2)
            b = degDMS(r, prec=0, s_D='', s_S='')  # only S_MIN
            x = ('30' + S_MIN) if p < 1 else (('15' + S_MIN) if p < 2 else
                                              ('5' + S_MIN))
            self.test('resolution', b, x)  # also to test degDMS
示例#2
0
    def testGeoref(self, LL):

        # Karney's geographiclib/1.49/examples/example-Georef.cpp
        # <http://SourceForge.net/p/geographiclib/code/ci/release/tree/examples/example-Georef.cpp>
        g = Georef('57.64911, 10.40744', precision=6)
        self.test('Georef', g, 'NKLN2444638946')
        self.test('Georef', repr(g), "Georef('NKLN2444638946')")
        self.test('Georef.latlon', fStr(g.latlon, prec=5),
                  '57.64911, 10.40744')
        t = g.toLatLon(LL)
        self.test('Georef.toLatLon', repr(t),
                  'LatLon(57°38′56.8″N, 010°24′26.78″E)')
        self.testCodec3(g, '57.64911, 10.40744, 6.0', prec=5)

        # <http://WikiPedia.org/wiki/World_Geographic_Reference_System>
        g = Georef('38.286108, -76.4291704', precision=6)
        self.test('Georef', g, 'GJPJ3424917166')
        self.test('Georef', repr(g), "Georef('GJPJ3424917166')")
        self.test('Georef.latlon', fStr(g.latlon, prec=6),
                  '38.286108, -76.42917')
        t = g.toLatLon(LL)
        self.test('Georef.toLatLon', repr(t),
                  'LatLon(38°17′09.99″N, 076°25′45.01″W)')
        self.testCodec3(g, '38.286108, -76.429175, 6.0', prec=6)

        # <http://Earth-Info.NGA.mil/GandG/coordsys/grids/georef.pdf>
        self.testCodec3('MKPG1204', '51.075, -1.7917, 3.0', prec=4)

        # <http://www.map-reading.com/ch4-4.php>
        self.testCodec3('WJKG1503', '36.0583, 129.2583, 3.0', prec=4)

        # <http://WikiPedia.org/wiki/World_Geographic_Reference_System>
        self.testCodec5('GJPJ4103R5',
                        '38.0583, -76.3083, 3.0, None, 9260.0',
                        prec=4)
        self.testCodec5('GJPJ4103H17',
                        '38.0583, -76.3083, 3.0, 5181.6, None',
                        prec=4)
        self.testCodec5('GJPJ4103R5H17',
                        '38.0583, -76.3083, 3.0, 5181.6, 9260.0',
                        prec=4)

        for t in range(-1, 13):
            r = wgrs.resolution(t)
            p = wgrs.precision(r)
            self.test('precision', t, p, known=t < 0 or t > 11)
            b = degDMS(r, prec=t if r < 1 else 0, s_S='')  # no S_SEC
            x = ('15' + S_DEG) if p < 1 else (('1' + S_DEG) if p < 2 else
                                              ('0.%s1%s' % ('0' *
                                                            (p - 2), S_MIN)))
            self.test('resolution', b, x)  # also to test degDMS
示例#3
0
    def testUps(self, LL):
        u = Ups(0, 'N', 448251, 5411932.0001)
        self.test('Ups', u.toStr(4), '00 N 448251.0 5411932.0001')

        u = Ups(0, 'N', 448251.795, 5411932.678, falsed=False)
        self.test('Ups', u, '00 N 448252 5411933')
        self.test('Ups', u.toStr(prec=3), '00 N 448251.795 5411932.678')
        self.test('Ups', u.toStr(prec=1, B=True, cs=True),
                  '00Z N 448251.8 5411932.7 n/a n/a')
        self.test('Ups2', u.toRepr(), '[Z:00, H:N, E:448252, N:5411933]')
        self.test('Ups2', u.toStr2(), '[Z:00, H:N, E:448252, N:5411933]')

        ll = u.toLatLon(LL, unfalse=False)  # UTM 48.85820000°N, 002.29450000°E
        self.test('Ups.toLatLon', ll, '43.684097°N, 175.265195°E')
        self.test('Ups.toLatLon', ll.toStr(form=F_DMS),
                  '43°41′02.75″N, 175°15′54.7″E')

        # u = ll.toUps(falsed=False)  # UTM N 448251.795205746 5411932.67761691
        # self.test('LL.toUps', u, 'N 448252 5411933')
        # self.test('LL.toUps', u.toStr(prec=3), 'N 448251.795 5411932.678')
        # self.test('LL.toUps', u.toStr2(B=True, cs=True), '[Z:00Z P:N E:448252 N:5411933 C:+175.26519494° S:1.17547892]')

        m = u.toMgrs()
        self.test('Ups.toMgrs', m, '60T UP 60176 38249')
        t = u.toUps()
        self.test('Ups.toUps', t, '00 N 448252 5411933')
        t = u.toUtm(u.zone)
        self.test('Ups.toUtm', t, '60 N 360177 4838249')

        # TM8358-2 pg 3-7 ID 1
        u = toUps8('84 17 14.042N', '132 14 52.761W')  # -132.247988889
        self.test('toUpsID1', u.toStr(prec=2, cs=True),
                  '00 N 1530125.78 2426773.6 -132.24798917° 0.99647445')

        # TM8358-2 pg 3-7 ID 2
        u = toUtmUps8(
            '73N', '44E'
        )  # Karney 38n 467368 8100752 (73°00'00.0"N 044°00'00.0"E) MGRS 38XMG6736700752
        self.test('toUtmUps8ID2',
                  u.toStr(prec=2, cs=True),
                  '38 N 3320416.75 632668.43 +44.0° 1.01619505',
                  known=True)
        u = toUps8('73N', '44E', strict=False)  # allow lat outside UPS range
        self.test('toUtmUps8ID2', u.toStr(prec=2, cs=True),
                  '00 N 3320416.75 632668.43 +44.0° 1.01619505')

        # TM8358-2 pg 3-7 ID 3
        u = toUps8('87 17 14.4S', '132 14 52.303E', pole='S')  # -132.247861111
        self.test('toUpsID3', u.toStr(prec=2, cs=True),
                  '00 S 2222979.47 1797474.9 -132.24786194° 0.99455723')

        # TM8358-2 pg 3-7 ID 4
        u = Ups(0, 'N', '1530125.78', '2426773.6')
        ll = u.toLatLon(LL)
        self.test('Ups.toLatLonID4', ll.toStr(form=F_DMS),
                  '84°17′14.04″N, 132°14′52.76″W')
        self.test('Ups.toLatLonID4', ll, '84.287234°N, 132.247989°W')

        # TM8358-2 pg 3-7 ID 5
        u = Ups(0, 'N', '3320416.75', '632668.43')
        ll = u.toLatLon(LL)
        self.test('Ups.toLatLonID5', ll.toStr(form=F_DMS),
                  '73°00′00.0″N, 044°00′00.0″E')  # '72°59′60.0″N, ...
        self.test('Ups.toLatLonID5', ll, '73.0°N, 044.0°E')

        # TM8358-2 pg 3-7 ID 6
        u = Ups(0, 'S', '2222979.47', '1797474.9')
        ll = u.toLatLon(LL)
        self.test('Ups.toLatLonID6', ll.toStr(form=F_DMS),
                  '87°17′14.4″S, 132°14′52.3″E')
        self.test('Ups.toLatLonID6', ll, '87.287333°S, 132.247861°E')

        # <https://GeographicLib.SourceForge.io/cgi-bin/GeoConvert>
        ll = LL(84, 84)
        self.test('latlon', ll, ll)
        u = toUps8(
            ll
        )  # n 2663075 1930308 (84°00'00.0"N 084°00'00.0"E) MGRS ZJG6307530307
        self.test('toUps', u, '00 N 2663075 1930308')
        self.test('toUps', u.toStr(prec=6, cs=True),
                  '00 N 2663075.299562 1930307.977716 +84.0° 0.99673')
        # self.test('toMgrs5', u.toMgrs(), 'Z JG 63075 30307')

        t = ' '.join(toUps8(ll, Ups=None).toStr(prec=6).split()[:5] + ['...)'])
        self.test('toUps(None)',
                  t,
                  "(0, 'N', 2663075.299562, 1930307.977716, 'Z', ...)",
                  known=True)  # coverage
        self.test('.scale0', u.scale0, '0.994000', fmt='%.6f')
        u.rescale0(84, 1.0)
        self.test('rescale0', u.scale0, '0.997261', fmt='%.6f')

        # <https://Earth-Info.NGA.mil/GandG/publications/NGA_SIG_0012_2_0_0_UTMUPS/NGA.SIG.0012_2.0.0_UTMUPS.pdf>
        # 10.2 Examples of computng {x, y, sigma, gamma}, given {lambda, phi, Z} page 41
        # replaced with Karney's results from <https://GeographicLib.SourceForge.io/cgi-bin/GeoConvert>
        #  8: lat lon 83   90  UTM/UPS 46n 459200.256323 9217519.441609  MGRS 46X DT 5920025632317519441609
        #  9: lat lon 82   91  UTM/UPS 46n 468930.934996 9105366.008486  MGRS 46X DS 6893093499605366008486
        # 10: lat lon 81  179  UTM/UPS 60n 534921.971582 8993806.415149  MGRS 60X WQ 3492197158193806415148
        # 11: lat lon 80  180  UTM/UPS 01n 441867.784867 8883084.955948  MGRS 01X DJ 4186778486783084955948
        # 12: lat lon 40    0  UTM/UPS 31n 243900.352030 4432069.056899  MGRS 31T BE 4390035202932069056898
        # 13: lat lon  3 -179  UTM/UPS 01n 277707.830749  331796.291679  MGRS 01N BD 7770783074931796291678
        # 14: lat lon  2  -90  UTM/UPS 16n 166223.907623  221366.166030  MGRS 16N AH 6622390762321366166030
        # 15: lat lon  1   -1  UTM/UPS 30n 722561.736479  110597.972524  MGRS 30N YG 2256173647810597972523
        # 16: lat lon  0    0  UTM/UPS 31n 166021.443081       0.000000  MGRS 31N AA 6602144308000000000000
        # 17: lat lon -1    1  UTM/UPS 31s 277438.263521 9889402.027476  MGRS 31M BU 7743826352189402027476
        # 18: lat lon -2   90  UTM/UPS 46s 166223.907623 9778633.833970  MGRS 46M AC 6622390762378633833969
        # 19: lat lon -3  179  UTM/UPS 60s 722292.169251 9668203.708321  MGRS 60M YB 2229216925068203708321
        # 20: lat lon -4  180  UTM/UPS 01s 166831.065275 9557263.747314  MGRS 01M AR 6683106527557263747313
        for t in (
                '1   -0 90 N   2000000.0        2000000.0      0.994      -0',
                '2 -179 89 N   1998062.320046   2111009.610243 0.994076 -179',
                '3  -90 88 N   1777930.731071   2000000.0      0.994303  -90',
                '4   -1 87 N   1994185.827038   1666906.254073 0.994682   -1',
                '5    0 86 N   2000000.0        1555731.570643 0.995212    0',
                '6    1 85 N   2009694.068153   1444627.207468 0.995895    1',
                '7   89 84 N   2666626.157825   1988363.997132 0.996730   89',
                #  '8   90 83 N   2778095.750322   2000000.0      0.997718   90',
                '8   90 83 N    459200.256323   9217519.441609 0.997718   -2.97767886',
                #  '9   91 82 N   2889442.490749   2015525.276426 0.998860   91',
                '9   91 82 N    468930.934996   9105366.008486 0.998860   -1.98055172',
                # '10  179 81 N   2017473.190606   3001038.419357 1.000156  179',
                '10  179 81 N    534921.971582   8993806.415149 1.000156   +1.97539632',
                # '11  180 80 N   2000000.0        3112951.136955 1.001608  180',
                '11  180 80 N    441867.784867   8883084.955948 1.001608   -2.95450468',
                # '12    0 40 N   2000000.0       -3918313.984953 1.209619    0',
                '12    0 40 N   243900.35203     4432069.056899 1.0004075  -1.92940969',
                # '13 -179  3 N   1790630.987261  13994742.706481 1.883453 -179',
                '13 -179  3 N    277707.830749    331796.291679 1.00021172 -0.1047151895',
                # '14  -90  2 N -10206568.118587   2000000.0      1.914973  -90',
                '14  -90  2 N    166223.907623    221366.16603  1.00097936 -0.104796101',
                # '15   -1  1 N   1783239.204558 -10418217.653909 1.947589   -1',
                '15   -1  1 N    722561.736479    110597.972524 1.00021322  0.03491928033333334',
                # '16    0  0 N   2000000.0      -10637318.498257 1.981349    0',
                '16    0  0 N    166021.443081         0.0      1.00098106  0',
                # '17    1 -1 N   2224408.737826 -10856367.979638 2.016305    1',
                '17    1 -1 S    277438.263521   9889402.027476 1.00021322  0.03491928033333334',
                # '18   90 -2 N  15083269.373905   2000000.0      2.052510   90',
                '18   90 -2 S    166223.907623   9778633.83397  1.00097936  0.104796101',
                # '19  179 -3 N   2232331.498720  15310262.647286 2.090020  179',
                '19  179 -3 S    722292.169251   9668203.708321 1.00021172 -0.1047151895',
                # '20  180 -4 N   2000000.0       15545537.944524 2.128897  180',
                '20  180 -4 S    166831.065275   9557263.747314 1.00097428  0.209463796167',
        ):
            i, lon, lat, p, e, n, s, c = t.split()
            u = toUtmUps8(lat, lon)
            z = '%02d' % (u.zone, )
            x = ' '.join((z, p, e, n, degDMS(float(c), prec=8, pos='+'), s))
            t = u.toStr(prec=6, cs=True)
            if abs(float(s) - u.scale) < 1e-2:
                t = ' '.join(t.split()[:-1] + [s])
            self.test('NGA-10.2-' + i, t, x)

        # <https://Earth-Info.NGA.mil/GandG/publications/NGA_SIG_0012_2_0_0_UTMUPS/NGA.SIG.0012_2.0.0_UTMUPS.pdf>
        # 10.3 Examples of computing {lambda, phi}, given {Z, x, y} page 41
        for t in ('1 S       0       0 -135.0          -64.9164123332',
                  '2 S 1000000       0 -153.4349488229 -70.0552944014',
                  '3 S 2000000       0 -180.0          -72.1263610163',
                  '4 S 3000000       0  153.4349488229 -70.0552944014',
                  '5 S 4000000       0  135.0          -64.9164123332',
                  '6 S       0 1000000 -116.5650511771 -70.0552944014',
                  '7 S 1000000 1000000 -135.0          -77.3120791908',
                  '8 S 2000000 1000000  180.0          -81.0106632645',
                  '9 S 3000000 1000000  135.0          -77.3120791908',
                  '10 S 4000000 1000000  116.5650511771 -70.0552944014',
                  '11 S       0 2000000  -90.0          -72.1263610163',
                  '12 S 1000000 2000000  -90.0          -81.0106632645',
                  '13 S 2000000 2000000    0.0          -90.0',
                  '14 S 3000000 2000000   90.0          -81.0106632645',
                  '15 S 4000000 2000000   90.0          -72.1263610163',
                  '16 S       0 3000000  -63.4349488229 -70.0552944014',
                  '17 S 1000000 3000000  -45.0          -77.3120791908',
                  '18 S 2000000 3000000    0.0          -81.0106632645',
                  '19 S 3000000 3000000   45.0          -77.3120791908',
                  '20 S 4000000 3000000   63.4349488229 -70.0552944014',
                  '21 S       0 4000000  -45.0          -64.9164123332',
                  '22 S 1000000 4000000  -26.5650511771 -70.0552944014',
                  '23 S 2000000 4000000    0.0          -72.1263610163',
                  '24 S 3000000 4000000   26.5650511771 -70.0552944014',
                  '25 S 4000000 4000000   45.0          -64.9164123332'):
            i, p, e, n, lon, lat = t.split()
            x = lat + ' ' + lon
            u = parseUTMUPS5(' '.join(('00', p, e, n)))
            ll = u.toLatLon(LL)
            t = ' '.join(strs(ll.latlon, prec=10))
            self.test('NGA-10.3-' + i, t, x, known=i == '3')
示例#4
0
    def testDms(self):  # MCCABE 14
        for t in ('0.0°', '0°', '''000°00'00"''', '''000°00'00.0"''',
                  '''000° 00'00"''', '''000°00 ' 00.0"''',
                  '''000° 00' 00.0'''):
            self.test("parseDMS('%s')" % (t, ), parseDMS(t), '0.0')
        t = '000°-00′-00.0"'
        self.test("parseDMS('%s')" % (t, ), parseDMS(t, sep='-'), '0.0')

        _X = ''
        for t, X, x in ((1, '1.0', _X), (12, '12.0', _X), (123, '123.0', _X),
                        (1234, '12.567', '1234.0'), (12345, '123.75',
                                                     '12345.0'),
                        (123456, '12.582', '123456.0'), (1234567, '123.769',
                                                         '1234567.0'),
                        (12345678, '1234.955', '12345678.0'), (.1, 0.1, _X),
                        (1.2, 1.2, _X), (12.3, 12.3, _X), (123.4, 123.4, _X),
                        (1234.5, 12.575, 1234.5), (12345.6, 123.76, 12345.6),
                        (123456.7, 12.582, 123456.7), ('1N', '1.0', _X),
                        ('12S', '-12.0', _X), ('012.3W', '-12.3', _X),
                        ('123E', '123.0', _X), ('1234N', '12.567', '1234.0'),
                        ('12345E', '123.75',
                         '12345.0'), ('1234.5S', '-12.575',
                                      '-1234.5'), ('12345.6E', '123.76',
                                                   '12345.6'),
                        ('123456.7S', '-12.582',
                         '-123456.7'), ('1234567.8W', '-123.769',
                                        '-1234567.8'), ('12345678E',
                                                        '12345678.0', _X)):
            self.test('parseDDDMMSS(%r)' % (t, ), fstr(parseDDDMMSS(t),
                                                       prec=3), X)
            self.test('parseDMS(%r)' % (t, ), fstr(parseDMS(t), prec=3), x
                      or X)

        t = 345.0
        self.test('parseDDDMMSS(%r, NS)' % (t, ),
                  fstr(parseDDDMMSS(t, suffix='NS'), prec=3), '3.75')
        self.test('parseDDDMMSS(%r, EW)' % (t, ),
                  fstr(parseDDDMMSS(t, suffix='EW'), prec=3), '345.0')
        t = 5430.0
        self.test('parseDDDMMSS(%r, NS)' % (t, ),
                  fstr(parseDDDMMSS(t, suffix='NS'), prec=3), '54.5')
        self.test('parseDDDMMSS(%r, EW)' % (t, ),
                  fstr(parseDDDMMSS(t, suffix='EW'), prec=3), '54.5')

        for t, x in (('12E', '12.0'), ('012.3S', '-12.3'), ('123N', '123.0'),
                     ('1234E', '1234.0'), ('12345N', '12345.0'), ('1234.5W',
                                                                  '-1234.5'),
                     ('123456E', '123456.0'), ('1234567S', '-1234567.0')):
            try:
                self.test('parseDDDMMSS(%r)' % (t, ), parseDDDMMSS(t),
                          ParseError.__name__)
            except ParseError as X:
                self.test('parseDDDMMSS(%r)' % (t, ), repr(X), repr(X))
            self.test('parseDMS(%r)' % (t, ), fstr(parseDMS(t), prec=5), x)

        r = rangerrors(True)
        try:
            self.test('parseDMS', parseDMS(181, clip=180), RangeError.__name__)
        except RangeError as x:
            self.test('parseDMS', str(x), str(x))
        rangerrors(False)
        try:
            self.test('parseDMS', parseDMS(-91, clip=90), RangeError.__name__)
        except RangeError as x:
            self.test('parseDMS', str(x), str(x))
        rangerrors(r)

        x = parse3llh('000° 00′ 05.31″W, 51° 28′ 40.12″ N')
        self.test('parse3llh', fstr(x, prec=6), '51.477811, -0.001475, 0.0')

        t = 'toDMS(%s)' % ('', )
        self.test(t, toDMS(45.99999, F_DM, prec=1), '46°00.0′')  # not 45°60.0′
        self.test(t, toDMS(45.99999, F_DM, prec=2), '46°00.0′')
        self.test(t, toDMS(45.9999, F_DM, prec=2), '45°59.99′')
        self.test(t, toDMS(45.99999, F_DM, prec=3), '45°59.999′')
        self.test(t, toDMS(45.99999, F_DMS, prec=1), '46°00′00.0″')
        self.test(t, toDMS(45.99999, F_DMS, prec=2), '45°59′59.96″')
        self.test(t, toDMS(45.99999, F_DMS, prec=3), '45°59′59.964″')

        self.test(t, toDMS(45.76260), '45°45′45.36″')

        for F, p, x in ((F_D, None, '45.7626°'), (F_DM, None, "45°45.756'"),
                        (F_DMS, None, '''45°45'45.36"'''),
                        (F_DEG, None, '45.7626'), (F_MIN, None, '4545.756'),
                        (F_SEC, None, '454545.36'), (F_RAD, None, '0.79871'),
                        (F_D, 6, '45.7626°'), (F_DM, -4, "45°45.7560'"),
                        (F_DMS, 2, '''45°45'45.36"'''), (F_DEG, -6,
                                                         '45.762600'),
                        (F_MIN, -5, '4545.75600'), (F_SEC, -3, '454545.360'),
                        (F_RAD, -6, '0.798708'), (F_D_, 6, '45.7626°'),
                        (F_DM_, -4, "45°45.7560'"), (F_DMS_, 2,
                                                     '''45°45'45.36"'''),
                        (F_DEG_, -6, '45.762600'), (F_MIN_, -5, '4545.75600'),
                        (F_SEC_, -3, '454545.360'), (F_RAD_, -6, '0.798708')):
            t = 'toDMS(%s)' % (F, )
            self.test(t, toDMS(45.76260, F, prec=p), x)
            self.test(t, toDMS(-45.76260, F, prec=p), '-' + x)

        for F, p, x in ((F_D__, 6, '45.7626°'), (F_DM__, -4, "45°45.7560'"),
                        (F_DMS__, 2, '''45°45'45.36"'''),
                        (F_DEG__, -6, '45.762600'), (F_MIN__, -5,
                                                     '4545.75600'),
                        (F_SEC__, -3, '454545.360'), (F_RAD__, -6,
                                                      '0.798708')):
            t = 'toDMS(%s)' % (F, )
            self.test(t, toDMS(45.76260, F, prec=p), '+' + x)
            self.test(t, toDMS(-45.76260, F, prec=p), '-' + x)

        # <https://GitHub.com/chrisveness/geodesy/blob/master/test/dms-tests.js>
        for a, x in (
            ((1, ), 'N'),
            ((0, ), 'N'),
            ((-1, ), 'N'),
            ((359, ), 'N'),
            ((24, ), 'NNE'),
            ((24, 1), 'N'),
            ((24, 2), 'NE'),
            ((24, 3), 'NNE'),
            ((226, ), 'SW'),
            ((226, 1), 'W'),
            ((226, 2), 'SW'),
            ((226, 3), 'SW'),
            ((237, ), 'WSW'),
            ((237, 1), 'W'),
            ((237, 2), 'SW'),
            ((237, 3), 'WSW'),
                # Martin Schultz
            ((11.25, ), 'NNE'),
            ((11.249, ), 'N'),
            ((-11.25, ), 'N'),
            ((348.749, ), 'NNW'),
            ((45, 1), 'E'),
            ((44.99, 1), 'N'),
            ((45, 2), 'NE'),
            ((44.99, 2), 'NE'),
            ((45, 3), 'NE'),
            ((44.99, 3), 'NE'),
            ((45, 4), 'NE'),
            ((44.99, 4), 'NE'),  # XXX
            ((22.5, 1), 'N'),
            ((22.49, 1), 'N'),
            ((22.5, 2), 'NE'),
            ((22.49, 2), 'N'),
            ((22.5, 3), 'NNE'),
            ((22.49, 3), 'NNE'),
            ((22.5, 4), 'NNE'),
            ((22.49, 4), 'NNE'),  # XXX
            ((11.25, 1), 'N'),
            ((11.249, 1), 'N'),
            ((11.25, 2), 'N'),
            ((11.249, 2), 'N'),
            ((11.25, 3), 'NNE'),
            ((11.249, 3), 'N'),
            ((11.25, 4), 'NbE'),
            ((11.249, 4), 'NbE'),  # XXX
                # examples
            ((24, 1), 'N'),
            ((24, 2), 'NE'),
            ((24, 3), 'NNE'),
            ((24, ), 'NNE'),
            ((18, 3), 'NNE'),
            ((11, 4), 'NbE'),
            ((30, 4), 'NEbN')):
            self.test('compassPoint%s' % (a, ), compassPoint(*a), x)

        for a, x in enumerate(
            ('NbE', 'NEbN', 'NEbE', 'EbN', 'EbS', 'SEbE', 'SEbS', 'SbE', 'SbW',
             'SWbS', 'SWbW', 'WbS', 'WbN', 'NWbW', 'NWbN', 'NbW')):
            a = 11.25 + a * 22.5
            self.test('compassPoint(%s)' % (a, ), compassPoint(a, 4), x)

        t = degDMS(1.0101, prec=5, s_D='', pos='+')  # coverage
        self.test('_DEG', t, '+1.0101')
        t = degDMS(0.0101, prec=5, s_S='', pos='+')
        self.test('_MIN', t, "+0.606'")
        t = degDMS(0.0101, prec=5, s_M='', pos='+')
        self.test('_SEC', t, '+36.36"')
示例#5
0
    def testDms(self):
        # dms module tests
        for i, t in enumerate(
            ('0.0°', '0°', '''000°00'00"''', '''000°00'00.0"''',
             '''000° 00'00"''', '''000°00 ' 00.0"''', '''000° 00' 00.0''')):
            self.test('parseDMS' + str(i + 1), parseDMS(t), '0.0')
        self.test('parseDMS' + str(i + 2), parseDMS('000°-00′-00.0"', sep='-'),
                  '0.0')

        r = rangerrors(True)
        try:
            self.test('parseDMS', parseDMS(181, clip=180), 'ValueError')
        except ValueError as x:
            self.test('parseDMS', str(x), '181.0 beyond 180 degrees')
        rangerrors(False)
        try:
            self.test('parseDMS', parseDMS(-91, clip=90), -90)
        except ValueError as x:
            self.test('parseDMS', str(x), '-90')
        rangerrors(r)

        x = parse3llh('000° 00′ 05.31″W, 51° 28′ 40.12″ N')
        self.test('parse3llh', fStr(x, prec=6), '51.477811, -0.001475, 0.0')

        for a, x in (((), '''45°45'45.36"'''), ((F_D, None), '45.7626°'),
                     ((F_DM, None), "45°45.756'"), ((F_DMS, None),
                                                    '''45°45'45.36"'''),
                     ((F_DEG, None), '45.7626'), ((F_MIN, None), '4545.756'),
                     ((F_SEC, None), '454545.36'), ((F_RAD, None), '0.79871'),
                     ((F_D, 6), '45.7626°'), ((F_DM, -4), "45°45.7560'"),
                     ((F_DMS, 2), '''45°45'45.36"'''),
                     ((F_DEG, -6), '45.762600'), ((F_MIN, -5), '4545.75600'),
                     ((F_SEC, -3), '454545.360'), ((F_RAD, -6), '0.798708')):
            t = 'toDMS(%s)' % (a[:1] or '')
            self.test(t, toDMS(45.76260, *a), x)

        for a, x in (((F_D_, 6), '45.7626°'), ((F_DM_, -4), "45°45.7560'"),
                     ((F_DMS_, 2), '''45°45'45.36"'''),
                     ((F_DEG_, -6), '45.762600'), ((F_MIN_, -5), '4545.75600'),
                     ((F_SEC_, -3), '454545.360'), ((F_RAD_, -6), '0.798708')):
            t = 'toDMS(%s)' % (a[:1] or '')
            self.test(t, toDMS(45.76260, *a), x)
            self.test(t, toDMS(-45.76260, *a), '-' + x)

        for a, x in (((F_D__, 6), '45.7626°'), ((F_DM__, -4), "45°45.7560'"),
                     ((F_DMS__, 2), '''45°45'45.36"'''),
                     ((F_DEG__, -6), '45.762600'), ((F_MIN__, -5),
                                                    '4545.75600'),
                     ((F_SEC__, -3), '454545.360'), ((F_RAD__, -6),
                                                     '0.798708')):
            t = 'toDMS(%s)' % (a[:1] or '')
            self.test(t, toDMS(45.76260, *a), '+' + x)
            self.test(t, toDMS(-45.76260, *a), '-' + x)

        # <https://GitHub.com/chrisveness/geodesy/blob/master/test/dms-tests.js>
        for a, x in (
            ((1, ), 'N'),
            ((0, ), 'N'),
            ((-1, ), 'N'),
            ((359, ), 'N'),
            ((24, ), 'NNE'),
            ((24, 1), 'N'),
            ((24, 2), 'NE'),
            ((24, 3), 'NNE'),
            ((226, ), 'SW'),
            ((226, 1), 'W'),
            ((226, 2), 'SW'),
            ((226, 3), 'SW'),
            ((237, ), 'WSW'),
            ((237, 1), 'W'),
            ((237, 2), 'SW'),
            ((237, 3), 'WSW'),
                # Martin Schultz
            ((11.25, ), 'NNE'),
            ((11.249, ), 'N'),
            ((-11.25, ), 'N'),
            ((348.749, ), 'NNW'),
            ((45, 1), 'E'),
            ((44.99, 1), 'N'),
            ((45, 2), 'NE'),
            ((44.99, 2), 'NE'),
            ((45, 3), 'NE'),
            ((44.99, 3), 'NE'),
            ((45, 4), 'NE'),
            ((44.99, 4), 'NE'),  # XXX
            ((22.5, 1), 'N'),
            ((22.49, 1), 'N'),
            ((22.5, 2), 'NE'),
            ((22.49, 2), 'N'),
            ((22.5, 3), 'NNE'),
            ((22.49, 3), 'NNE'),
            ((22.5, 4), 'NNE'),
            ((22.49, 4), 'NNE'),  # XXX
            ((11.25, 1), 'N'),
            ((11.249, 1), 'N'),
            ((11.25, 2), 'N'),
            ((11.249, 2), 'N'),
            ((11.25, 3), 'NNE'),
            ((11.249, 3), 'N'),
            ((11.25, 4), 'NbE'),
            ((11.249, 4), 'NbE'),  # XXX
                # examples
            ((24, 1), 'N'),
            ((24, 2), 'NE'),
            ((24, 3), 'NNE'),
            ((24, ), 'NNE'),
            ((18, 3), 'NNE'),
            ((11, 4), 'NbE'),
            ((30, 4), 'NEbN')):
            self.test('compassPoint%s' % (a, ), compassPoint(*a), x)

        for a, x in enumerate(
            ('NbE', 'NEbN', 'NEbE', 'EbN', 'EbS', 'SEbE', 'SEbS', 'SbE', 'SbW',
             'SWbS', 'SWbW', 'WbS', 'WbN', 'NWbW', 'NWbN', 'NbW')):
            a = 11.25 + a * 22.5
            self.test('compassPoint(%s)' % (a, ), compassPoint(a, 4), x)

        t = degDMS(1.0101, prec=5, s_D='', pos='+')  # coverage
        self.test('_DEG', t, '+1.0101')
        t = degDMS(0.0101, prec=5, s_S='', pos='+')
        self.test('_MIN', t, "+0.606'")
        t = degDMS(0.0101, prec=5, s_M='', pos='+')
        self.test('_SEC', t, '+36.36"')