コード例 #1
0
    def test_pj(self):
        self.start()

        with gxcs.Coordinate_system('DHDN / Okarito 2000') as cs:
            with gxcs.Coordinate_system('DHDN') as csll:
                with gxcs.Coordinate_translate(cs, csll) as pj:

                    lon, lat = pj.convert((500000, 6500000))
                    self.assertAlmostEqual(lon, 171)
                    self.assertAlmostEqual(lat, 8)

                    lon, lat = pj.convert((500000., 6500000.))
                    self.assertAlmostEqual(lon, 171.168823147)
                    self.assertAlmostEqual(lat, 8.36948254242)

                    ll = pj.convert(
                        np.array([500000., 6500000.], dtype=np.float32))
                    self.assertAlmostEqual(ll[0], 171.16882, 5)
                    self.assertAlmostEqual(ll[1], 8.36948, 5)

                    lon, lat, z = pj.convert((500000., 6500000., 50.))
                    self.assertAlmostEqual(lon, 171.168823147)
                    self.assertAlmostEqual(lat, 8.36948254242)
                    self.assertAlmostEqual(z, 50)

                    ll = pj.convert([[500000., 6500000.], [505000., 6510000.]])
                    self.assertAlmostEqual(ll[0][0], 171.168823147)
                    self.assertAlmostEqual(ll[0][1], 8.36948254242)
                    self.assertAlmostEqual(ll[1][0], 171.214439577)
                    self.assertAlmostEqual(ll[1][1], 8.45978927383)

                    ll = pj.convert(
                        np.array([[500000., 6500000.], [505000., 6510000.]]))
                    self.assertTrue(type(ll) is np.ndarray)
                    self.assertAlmostEqual(ll[0][0], 171.168823147)
                    self.assertAlmostEqual(ll[0][1], 8.36948254242)
                    self.assertAlmostEqual(ll[1][0], 171.214439577)
                    self.assertAlmostEqual(ll[1][1], 8.45978927383)

                    vvx = gxvv.GXvv([500000., 505000.])
                    vvy = gxvv.GXvv([6500000., 6510000.])
                    pj.convert_vv(vvx, vvy)
                    self.assertAlmostEqual(vvx[0][0], 171.168823147)
                    self.assertAlmostEqual(vvy[0][0], 8.36948254242)
                    self.assertAlmostEqual(vvx[1][0], 171.214439577)
                    self.assertAlmostEqual(vvy[1][0], 8.45978927383)
コード例 #2
0
    def test_array(self):
        self.start()

        # define coordinate systems and a transformer
        cs_utm = gxcs.Coordinate_system('NAD83 / UTM zone 15N')
        cs_nad27 = gxcs.Coordinate_system('NAD27')
        cs_transform = gxcs.Coordinate_translate(cs_utm, cs_nad27)

        # example transform a single (x, y) coordinate
        lon_lat = cs_transform.convert((345000., 64250000.))
        self.assertEqual(tuple(lon_lat),
                         (88.777242210445195, -38.498998514257273))

        # example transform a single (x, y, elevation) coordinate
        ct = cs_transform.convert((345000., 64250000., 50))
        self.assertAlmostEqual(ct[0], 88.77724221146941)
        self.assertAlmostEqual(ct[1], -38.49899848105302)
        self.assertAlmostEqual(ct[2], 50.0)

        # example translate a list of (x, y, z) tuples
        locations = [(345000, 64250000, 50), (345500, 64250000, 60),
                     (346000, 64250000, 70)]
        nad27_locations = cs_transform.convert(locations)
        self.assertEqual(len(nad27_locations), 3)
        ct = nad27_locations[2]
        self.assertAlmostEqual(ct[0], 89)
        self.assertAlmostEqual(ct[1], -38)
        self.assertAlmostEqual(ct[2], 70)

        # example transform a numpy array in-place
        data = np.array(
            [[345000, 64250000, 50, 55000], [345500, 64250000, 60, 55150],
             [346000, 64250000, 70, 56000]],
            dtype=float)
        nad27_locations = cs_transform.convert(data, in_place=True)
        self.assertEqual(len(nad27_locations), 3)
        ct = nad27_locations[2]
        self.assertAlmostEqual(ct[0], 8.87657800e+01)
        self.assertAlmostEqual(ct[1], -3.84991719e+01)
        self.assertAlmostEqual(ct[2], 7.00000000e+01)
        self.assertAlmostEqual(ct[3], 5.60000000e+04)
コード例 #3
0
    def test_local(self):
        self.start()

        csd = gxcs.Coordinate_system.local(lon_lat=(-96, 43))
        self.assertEqual(csd.name, 'WGS 84 / *Local(43,-96,0,0)')

        with gxcs.Coordinate_translate(csd,
                                       gxcs.Coordinate_system('WGS 84')) as pj:
            lon, lat, z = pj.convert((0, 0, 0))
            self.assertAlmostEqual(lat, 43)
            self.assertAlmostEqual(lon, -96)
            self.assertAlmostEqual(z, 0)

        csd = gxcs.Coordinate_system.local(lon_lat=(-96, 43), azimuth=25)
        self.assertEqual(csd.name,
                         'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>')
        self.assertEqual(csd.gxf[2],
                         '"Oblique Stereographic",43,-96,0.9996,0,0')

        with gxcs.Coordinate_translate(gxcs.Coordinate_system('WGS 84'),
                                       csd) as pj:
            x, y, z = pj.convert((-96., 43., 0))
            self.assertAlmostEqual(x, 0)
            self.assertAlmostEqual(y, 0)
            self.assertAlmostEqual(z, 0)
            x, y, z = pj.convert((-95., 43., 0.))
            self.assertAlmostEqual(x, 73665.899715)
            self.assertAlmostEqual(y, 34886.2319719)
            self.assertAlmostEqual(z, 0)

        csd = gxcs.Coordinate_system.local(lon_lat=(-96, 43),
                                           azimuth=25,
                                           origin=(1800, 500))
        self.assertEqual(csd.name,
                         'WGS 84 / *Local(43,-96,1800,500) <0,0,0,0,0,25>')
        self.assertEqual(
            csd.gxf[2],
            '"Oblique Stereographic",43,-96,0.9996,1842.66314753632,-307.558977614934'
        )

        csd = gxcs.Coordinate_system.local(lon_lat=(-96, 43),
                                           azimuth=25,
                                           origin=(1800, 500),
                                           elevation=800.5,
                                           vcs='geoid')
        self.assertEqual(
            csd.name, 'WGS 84 / *Local(43,-96,1800,500) <0,0,800.5,0,0,25>')
        self.assertEqual(
            csd.gxf[2],
            '"Oblique Stereographic",43,-96,0.9996,1842.66314753632,-307.558977614934'
        )
        with gxcs.Coordinate_translate(gxcs.Coordinate_system('WGS 84'),
                                       csd) as pj:
            x, y = pj.convert((-96., 43.))
            self.assertAlmostEqual(x, 1800)
            self.assertAlmostEqual(y, 500)
        with gxcs.Coordinate_translate(csd,
                                       gxcs.Coordinate_system('WGS 84')) as pj:
            lon, lat, z = pj.convert((1800., 500., 0.))
            self.assertAlmostEqual(lat, 43)
            self.assertAlmostEqual(lon, -96)
            self.assertAlmostEqual(z, 800.5)

        datum = 'NAD27'
        local_datum = '[NAD27] (10m) USA - CONUS - onshore'
        csd = gxcs.Coordinate_system.local(lon_lat=(-96, 43),
                                           azimuth=25,
                                           origin=(1800, 500),
                                           datum='NAD83',
                                           local_datum=local_datum,
                                           elevation=800.5,
                                           vcs='geoid')
        self.assertEqual(csd.name,
                         'NAD83 / *Local(43,-96,1800,500) <0,0,800.5,0,0,25>')
        self.assertEqual(csd.gxf[4], '"NAD83 to WGS 84 (1)",0,0,0,0,0,0,0')
コード例 #4
0
    def test_local_dict(self):
        self.start()

        self.assertRaises(gxcs.CSException, gxcs.Coordinate_system,
                          {'type': 'local'})

        csdict = {'type': 'local', 'lon_lat': (-96, 43)}
        csd = gxcs.Coordinate_system(csdict)
        self.assertEqual(csd.name, 'WGS 84 / *Local(43,-96,0,0)')

        with gxcs.Coordinate_translate(csd,
                                       gxcs.Coordinate_system('WGS 84')) as pj:
            lon, lat, z = pj.convert((0, 0, 0))
            self.assertAlmostEqual(lat, 43)
            self.assertAlmostEqual(lon, -96)
            self.assertAlmostEqual(z, 0)

        csdict['azimuth'] = 25
        csd = gxcs.Coordinate_system(csdict)
        self.assertEqual(csd.name,
                         'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>')
        self.assertEqual(csd.gxf[2],
                         '"Oblique Stereographic",43,-96,0.9996,0,0')

        with gxcs.Coordinate_translate(gxcs.Coordinate_system('WGS 84'),
                                       csd) as pj:
            x, y, z = pj.convert((-96., 43., 0))
            self.assertAlmostEqual(x, 0)
            self.assertAlmostEqual(y, 0)
            self.assertAlmostEqual(z, 0)
            x, y, z = pj.convert((-95., 43., 0.))
            self.assertAlmostEqual(x, 73665.899715)
            self.assertAlmostEqual(y, 34886.2319719)
            self.assertAlmostEqual(z, 0)

        csdict['origin'] = (1800, 500)
        csd = gxcs.Coordinate_system(csdict)
        self.assertEqual(csd.name,
                         'WGS 84 / *Local(43,-96,1800,500) <0,0,0,0,0,25>')
        self.assertEqual(
            csd.gxf[2],
            '"Oblique Stereographic",43,-96,0.9996,1842.66314753632,-307.558977614934'
        )

        csdict['elevation'] = 800.5
        csdict['vcs'] = 'geoid'
        csd = gxcs.Coordinate_system(csdict)
        self.assertEqual(
            csd.name, 'WGS 84 / *Local(43,-96,1800,500) <0,0,800.5,0,0,25>')
        self.assertEqual(
            csd.gxf[2],
            '"Oblique Stereographic",43,-96,0.9996,1842.66314753632,-307.558977614934'
        )
        with gxcs.Coordinate_translate(gxcs.Coordinate_system('WGS 84'),
                                       csd) as pj:
            x, y = pj.convert((-96., 43.))
            self.assertAlmostEqual(x, 1800)
            self.assertAlmostEqual(y, 500)
        with gxcs.Coordinate_translate(csd,
                                       gxcs.Coordinate_system('WGS 84')) as pj:
            lon, lat, z = pj.convert((1800., 500., 0.))
            self.assertAlmostEqual(lat, 43)
            self.assertAlmostEqual(lon, -96)
            self.assertAlmostEqual(z, 800.5)
コード例 #5
0
import geosoft.gxpy.gx as gx
import geosoft.gxpy.coordinate_system as gxcs
import numpy as np

# create context
gxc = gx.GXpy()

# define coordinate systems and a transformer
cs_utm = gxcs.Coordinate_system('NAD83 / UTM zone 15N')
cs_nad27 = gxcs.Coordinate_system('NAD27')
cs_transform = gxcs.Coordinate_translate(cs_utm, cs_nad27)

# example transform a single (x, y) coordinate
lon_lat = cs_transform.convert((345000, 64250000))
print('(lon, lat): {}'.format(lon_lat))

# example transform a single (x, y, elevation) coordinate
print('(lon, lat, elevation): {}'.format(
    cs_transform.convert((345000, 64250000, 50))))

# example translate a list of (x, y, z) tuples
locations = [(345000, 64250000, 50), (345500, 64250000, 60),
             (346000, 64250000, 70)]
nad27_locations = cs_transform.convert(locations)
for xyz in nad27_locations:
    print(xyz)

# example transform a numpy array in-place
data = np.array([[345000, 64250000, 50, 55000], [345500, 64250000, 60, 55150],
                 [346000, 64250000, 70, 56000]],
                dtype=float)
コード例 #6
0
def t4():
    with gxcs.Coordinate_system('DHDN / Okarito 2000') as cs:
        with gxcs.Coordinate_system('DHDN') as csll:
            with gxcs.Coordinate_translate(cs, csll) as pj:
                lon, lat = pj.convert((500000, 6500000))