def test_annotate_ll_local(self): self.start() cs = gxcs.Coordinate_system({ 'type': 'local', 'lon_lat': (-96, 45), 'datum': 'nad83', 'azimuth': -30 }) cs = gxcs.Coordinate_system( "NAD27 / UTM zone 15N <425000,6500145,0,0,0,-30>") name = os.path.join(gx.gx().temp_folder(), "test") with gxmap.Map.new(file_name='mapplot_anoxy_rotated_cs_bug_UTM', overwrite=True, data_area=(0, 0, 5000, 3500), coordinate_system=cs, media="A3", margins=(3, 3, 4, 3)) as map: mapfile = map.file_name map.scale_bar(location=(2, 0, 2), length=6, sections=5) map.surround() map.annotate_data_xy(grid=gxmap.GRID_LINES) map.annotate_data_ll(grid=gxmap.GRID_LINES, grid_pen=gxg.Pen(line_color='b', line_thick=0.025), text_def=gxg.Text_def(height=0.18, italics=True), top=gxmap.TOP_IN) map.surround() self.crc_map(mapfile) gxmap.delete_files(mapfile)
def test_set_properties(self): self.start() with gxgrd.Grid.open(self.g1f) as g1: properties = g1.properties() properties['x0'] = 45.0 properties['y0'] = -15.0 properties['dx'] = 1.5 properties['dy'] = 2.5 properties['rot'] = 33.333333 properties['coordinate_system'] = gxcs.Coordinate_system( 'NAD27 / UTM zone 18N') self.assertRaises(gxgrd.GridException, g1.set_properties, properties) outGrid = os.path.join( self.folder, 'test_set_properties.grd(GRD;TYPE=SHORT;COMP=SPEED)') with gxgrd.Grid.open(self.g1f) as g: with gxgrd.Grid.copy(g, outGrid) as grd: grd.dx = 1.5 grd.dy = 2.5 grd.x0 = 45.0 grd.y0 = -15.0 grd.rot = 33.333333 grd.coordinate_system = gxcs.Coordinate_system( 'NAD27 / UTM zone 18N') with gxgrd.Grid.open(outGrid) as grd: properties = grd.properties() self.assertEqual(properties.get('dx'), 1.5) self.assertEqual(properties.get('dy'), 2.5) self.assertEqual(properties.get('x0'), 45.0) self.assertEqual(properties.get('y0'), -15.0) self.assertEqual(properties.get('rot'), 33.333333) self.assertEqual(properties.get('nx'), 101) self.assertEqual(properties.get('ny'), 101) self.assertEqual(str(properties.get('coordinate_system')), 'NAD27 / UTM zone 18N') self.assertEqual(properties.get('dtype'), np.int16) outGrid = os.path.join( self.folder, 'test_set_properties.grd(GRD;TYPE=SHORT;COMP=SPEED)') with gxgrd.Grid.open(self.g1f) as g: with gxgrd.Grid.copy(g, outGrid, overwrite=True) as grd: grd.set_properties(properties) with gxgrd.Grid.open(outGrid) as grd: properties = grd.properties() self.assertEqual(properties.get('dx'), 1.5) self.assertEqual(properties.get('dy'), 2.5) self.assertEqual(properties.get('x0'), 45.0) self.assertEqual(properties.get('y0'), -15.0) self.assertEqual(properties.get('rot'), 33.333333) self.assertEqual(properties.get('nx'), 101) self.assertEqual(properties.get('ny'), 101) self.assertEqual(str(properties.get('coordinate_system')), 'NAD27 / UTM zone 18N') self.assertEqual(properties.get('dtype'), np.int16)
def test_oriented(self): self.start() with gxcs.Coordinate_system({ 'type': 'local', 'lon_lat': (-96., 43.), 'azimuth': 25 }) as cs: self.assertTrue(cs.is_oriented) xyzo = (10., 0., 0.) xyz = cs.xyz_from_oriented(xyzo) self.assertEqual(xyz, (9.063077870366499, -4.2261826174069945, 0.0)) xyz = (9.063077870366499, -4.2261826174069945, 0.0) xyz = cs.oriented_from_xyz(xyz) self.assertAlmostEqual(xyz[0], xyzo[0]) self.assertAlmostEqual(xyz[1], xyzo[1]) self.assertAlmostEqual(xyz[2], xyzo[2]) xyzo = ((10., 0., 0.), (0., 10., 5.)) xyz = cs.xyz_from_oriented(xyzo) self.assertEqual(tuple(xyz[0]), (9.063077870366499, -4.2261826174069945, 0.0)) self.assertEqual(tuple(xyz[1]), (4.2261826174069945, 9.0630778703664987, 5.0)) xyz = ((9.063077870366499, -4.2261826174069945, 0.0), (4.2261826174069945, 9.0630778703664987, 5.0)) xyz = cs.oriented_from_xyz(xyz) self.assertAlmostEqual(xyz[0][0], xyzo[0][0]) self.assertAlmostEqual(xyz[0][1], xyzo[0][1]) self.assertAlmostEqual(xyz[0][2], xyzo[0][2]) xyzo = ((10., 0.), (0., 10.), (0., 5.)) xyz = cs.xyz_from_oriented(xyzo, column_ordered=True) self.assertEqual(tuple(xyz[0]), (9.063077870366499, 4.2261826174069945)) self.assertEqual(tuple(xyz[1]), (-4.2261826174069945, 9.063077870366499)) self.assertEqual(tuple(xyz[2]), (0.0, 5.0)) self.assertTrue(cs == gxcs.Coordinate_system({ 'type': 'local', 'lon_lat': (-96., 43.), 'azimuth': 25 })) self.assertFalse( cs == gxcs.Coordinate_system({ 'type': 'local', 'lon_lat': (-96., 43.), 'azimuth': 20 }))
def test_crooked_path(self): self.start() cs = gxgrd.Grid.open(self.crooked).coordinate_system cp = gxv.CrookedPath(cs) self.assertEqual(len(cp.xy), 1629) cp = gxv.CrookedPath(cs.gxipj) self.assertEqual(len(cp.xy), 1629) xy = cp.xy[:100] cp = gxv.CrookedPath(xy, coordinate_system="NAD83 / UTM zone 50N", name="Maki") self.assertEqual(len(cp.xy), 100) self.assertTrue(cp.coordinate_system == "NAD83 / UTM zone 50N") self.assertEqual(cp.name, "Maki") cp.name = "Billy" self.assertEqual(cp.name, "Billy") self.assertEqual(len(cp.ppoint), 100) cs = gxcs.Coordinate_system("NAD83 / UTM zone 50N") self.assertRaises(gxv.ViewException, gxv.CrookedPath, cs) cp.set_in_geosoft_ipj(cs) cp = gxv.CrookedPath(cs, name="hmmm") self.assertEqual(len(cp.ppoint), 100) self.assertEqual(cp.extent_xyz, (632840.88509899995, 4633409.6098999996, 0.0, 633012.53350000002, 4633574.2674000002, 0.0)) with gxgrd.Grid.open(self.crooked) as crooked: cp = gxv.CrookedPath(crooked.coordinate_system) v = gxv.View.new(area=crooked.extent_2d()) self.assertFalse(v.is_crooked_path) v = gxv.View.new(area=crooked.extent_2d(), crooked_path=cp) self.assertTrue(v.is_crooked_path) self.assertEqual(len(v.crooked_path()), 1629)
def test_array_locations(self): self.start() with gxgrd.Grid.new(properties={'x0':100, 'y0':-25.25, 'dx': 5, 'nx':101, 'ny':501}) as g: a = g.xyzv() self.assertEqual(len(a.shape),3) self.assertEqual(a.shape[0], g.ny) self.assertEqual(a.shape[1], g.nx) self.assertEqual(a.shape[2], 4) self.assertEqual(a[0,0,0], 100.0) self.assertEqual(a[0,0,1], -25.25) self.assertEqual(a[0,0,2], 0.0) self.assertTrue(np.isnan(a[0, 0, 3])) self.assertEqual(a[0,1,0]-a[0,0,0], g.dx) self.assertEqual(a[1,0,1]-a[0,0,1], g.dy) self.assertEqual(a[0,0,2]-a[1,1,2], 0.) props = {'x0':100, 'y0':-25.25, 'dx': 5, 'nx':101, 'ny':501, 'rot':10} a = gxgrd.array_locations(props) self.assertEqual((tuple(a[0, 0, :])), (100.0, -25.25, 0.0)) self.assertEqual((tuple(a[0, 10, :])), (149.24038765061039, -33.932408883346518, 0.0)) self.assertEqual((tuple(a[10, 0, :])), (108.68240888334651, 23.990387650610401, 0.0)) self.assertEqual((tuple(a[10, 10, :])), (157.92279653395693, 15.307978767263883, 0.0)) cs = gxcs.Coordinate_system({'type': 'local', 'lon_lat': (-96,43), 'azimuth': 10}).gxf props = {'x0':0, 'y0':0, 'dx': 5, 'nx':101, 'ny':501, 'coordinate_system':cs} a = gxgrd.array_locations(props) self.assertEqual((tuple(a[0, 0, :])), (0.0, 0.0, 0.0)) self.assertEqual((tuple(a[0, 10, :])), (49.240387650610401, -8.6824088833465165, 0.0)) self.assertEqual((tuple(a[10, 0, :])), (8.6824088833465165, 49.240387650610401, 0.0)) self.assertEqual((tuple(a[10, 10, :])), (57.92279653395692, 40.557978767263883, 0.0))
def test_map_classes(self): self.start() with gxmap.Map.new(file_name='test_geosoft', overwrite=True) as map: self.assertEqual(map.get_class_name('data'), 'data') self.assertEqual(map.get_class_name('base'), 'base') self.assertEqual(map.get_class_name('section'), 'section') self.assertEqual(map.get_class_name('some_class_name'), 'some_class_name') map.set_class_name('base', 'bogus') self.assertEqual(map.get_class_name('base'), 'bogus') map.set_class_name('data', 'bogus_data') #self.assertEqual(map.get_class_name('data'), 'bogus_data') map.set_class_name('Section', 'yeah') self.assertEqual(map.get_class_name('Section'), 'yeah') map.set_class_name('mine', 'boom') self.assertEqual(map.get_class_name('mine'), 'boom') with gxmap.Map.new(data_area=(0, 0, 100, 80), coordinate_system=gxcs.Coordinate_system( "DHDN / Okarito 2000 [geodetic]")) as map: self.assertEqual(map.get_class_name('base'), 'base') self.assertEqual(map.get_class_name('data'), 'data') with gxv.View(map, "copy_data", mode=gxv.WRITE_NEW, copy="data"): pass map.set_class_name('data', 'copy_data') self.assertEqual(map.get_class_name('data'), 'copy_data')
def test_new_geosoft_map(self): self.start() # temp map with gxmap.Map.new(data_area=(0, 0, 100, 80)) as map: views = map.view_list self.assertTrue('base' in views) self.assertTrue('data' in views) self.assertEqual(len(map.aggregate_list()), 0) with gxmap.Map.new(data_area=(0, 0, 100, 80), coordinate_system=gxcs.Coordinate_system( "DHDN / Okarito 2000 [geodetic]")) as map: with gxv.View(map, 'data', mode=gxv.WRITE_OLD) as v: self.assertEqual("DHDN / Okarito 2000 [geodetic]", str(v.coordinate_system)) self.assertEqual(map.current_data_view, 'data') self.assertEqual(map.current_base_view, 'base') self.assertEqual(map.current_section_view, 'section') # the following does not make sense, for testing purposes only map.current_data_view = 'base' self.assertEqual(map.current_data_view, 'base') map.current_base_view = 'data' self.assertEqual(map.current_base_view, 'data') map.current_section_view = 'data' self.assertEqual(map.current_section_view, 'data')
def test_in_memory(self): self.start() with gxgrd.Grid.new(in_memory=True, properties={'dtype': np.int16, 'nx': 100, 'ny': 50, 'x0':4, 'y0':8, 'dx': 0.1, 'dy':0.2, 'rot': 5, 'coordinate_system': gxcs.Coordinate_system('NAD27 / UTM zone 18N')}) as grd: properties = grd.properties() self.assertEqual(properties.get('dx'),0.1) self.assertEqual(properties.get('dy'),0.2) self.assertEqual(properties.get('x0'),4.0) self.assertEqual(properties.get('y0'),8.0) self.assertEqual(properties.get('rot'),5.0) self.assertEqual(properties.get('nx'),100) self.assertEqual(properties.get('ny'),50) self.assertEqual(properties.get('gridtype'), 'MEMORY') self.assertEqual(str(properties.get('coordinate_system')),'NAD27 / UTM zone 18N') self.assertEqual(properties.get('dtype'),np.int16) m = grd.metadata self.assertFalse(bool(m)) stats = grd.statistics() self.assertTrue(stats['mean'] is None)
def test_known(self): self.start() self.assertFalse(gxcs.is_known(None)) self.assertTrue(gxcs.is_known('WGS 84')) self.assertTrue(gxcs.is_known(gxcs.Coordinate_system('WGS 84'))) self.assertFalse(gxcs.is_known('crazy'))
def test_temp(self): self.start() with gxgrd.Grid.new( properties={ 'dtype': np.int16, 'nx': 100, 'ny': 50, 'x0': 4, 'y0': 8, 'dx': 0.1, 'dy': 0.2, 'rot': 5, 'coordinate_system': gxcs.Coordinate_system( 'NAD27 / UTM zone 18N') }) as grd: properties = grd.properties() self.assertEqual(properties.get('dx'), 0.1) self.assertEqual(properties.get('dy'), 0.2) self.assertEqual(properties.get('x0'), 4.0) self.assertEqual(properties.get('y0'), 8.0) self.assertEqual(properties.get('rot'), 5.0) self.assertEqual(properties.get('nx'), 100) self.assertEqual(properties.get('ny'), 50) self.assertEqual(str(properties.get('coordinate_system')), 'NAD27 / UTM zone 18N') self.assertEqual(properties.get('dtype'), np.int16) m = grd.metadata self.assertFalse(bool(m))
def test_datacard_properties(self): self.start() with gxdap.DapClient() as dap: # some point data datacard = dap['Kimberlite Indicator Mineral Grain Chemistry'] # individual properties self.assertEqual(datacard.info['Id'], '127') self.assertEqual(datacard.edition, '') self.assertEqual(datacard.disclaimer['title'], 'Copyright Notice') self.assertEqual(datacard.permission, 1) self.assertEqual(len(datacard.metadata), 4) self.assertEqual( str( gxcs.Coordinate_system( datacard.spatial_properties['CoordinateSystem'])), 'WGS 84') self.assertEqual(len(datacard.point_properties), 9) self.assertTrue(datacard.grid_properties is None) self.assertTrue(datacard.voxel_properties is None) self.assertTrue(datacard.map_properties is None) self.assertEqual(len(dap.datacard_from_id(905).grid_properties), 13) self.assertEqual( len(dap.datacard_from_id(872).document_properties), 8)
def test_unit_only(self): self.start() with gxcs.Coordinate_system('cm') as cs: self.assertEqual(str(cs), '*unknown') self.assertEqual(cs.gxf[3], 'cm,0.01') self.assertEqual(cs.unit_of_measure, 'cm') self.assertEqual(cs.units_name, cs.unit_of_measure)
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)
def test_section_ipj(self): self.start() cs = gxgrd.Grid.open(self.section).coordinate_system self.assertFalse(cs.is_known) self.assertTrue(cs.is_oriented) new_cs = gxcs.Coordinate_system(cs) self.assertTrue(new_cs.is_oriented) self.assertFalse(new_cs.is_known)
def test_set_georeferencing(self): self.start() with segy.SegyReader(self.testfile_3d) as target: georef_dict = target.georeferencing.coordinate_dict() georef_dict['name'] = 'NAD83 / UTM zone 15N' target.georeferencing = coordinate_system.Coordinate_system( georef_dict) self.assertEqual(target.georeferencing.coordinate_dict()['name'], 'NAD83 / UTM zone 15N')
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)
def test_surround_1(self): self.start() cs = gxcs.Coordinate_system('NAD83 / UTM zone 15N') with gxmap.Map.new(data_area=(350000, 7000000, 400000, 7030000), coordinate_system=cs) as map: mapfile = map.file_name with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.surround() self.crc_map(mapfile)
def test_surround_2(self): self.start() cs = gxcs.Coordinate_system('NAD83 / UTM zone 15N') with gxmap.Map.new(data_area=(350000, 7000000, 400000, 7030000), coordinate_system=cs) as map: mapfile = map.file_name with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.surround(gap=0.2, outer_pen=gxg.Pen(line_thick=0.2), inner_pen='bt500') self.crc_map(mapfile)
def test_copy_geometry(self): self.start() p1 = gxgeo.Point((1, 2)) p2 = p1 self.assertTrue(p1 is p2) p2 = gxgeo.Point(p2) self.assertFalse(p1 is p2) self.assertTrue(p1 == p2) p2.cs = "WGS 84" self.assertTrue(p1 == p2) p1.cs = "WGS 84" self.assertTrue(p1 == p2) p1.cs = gxcs.Coordinate_system("WGS 84 [geoid]") self.assertTrue(p1 == p2)
def test_voxel(self): self.start() if self.skip(): name = 'voxel.geosoft_voxel' gxapi.GXVOX.generate_constant_value(name, 1.0, 5, 0, 0, 0, 1, 1, 1, 300, 200, 50, gxcs.Coordinate_system().gxipj, gxmeta.Metadata().gxmeta) gxvox = gxapi.GXVOX.create(name) minx = gxapi.float_ref() miny = gxapi.float_ref() minz = gxapi.float_ref() maxx = gxapi.float_ref() maxy = gxapi.float_ref() maxz = gxapi.float_ref() gxvox.get_area(minx, miny, minz, maxx, maxy, maxz) self.assertEqual(minx.value, -0.5) self.assertEqual(maxz.value, 49.5) vvx = gxvv.GXvv() vvy = gxvv.GXvv() vvz = gxvv.GXvv() gxvox.get_location_points(vvx.gxvv, vvy.gxvv, vvz.gxvv) gxvoxe = gxapi.GXVOXE.create(gxvox) vvd = gxvv.GXvv([float(n) for n in range(500)]) gxvoxe.vector(0., 0., 0., 1.5, 1.5, 0.5, vvd.gxvv, gxapi.VOXE_EVAL_INTERP) self.assertEqual(vvd.length, 500) self.assertEqual(vvd[0][0], 1.0) self.assertTrue(np.isnan(vvd[499][0])) gxvoxe = None gxvox = None try: os.remove(name) os.remove(name + '.xml') except: pass
def _data_map(self, name=None, data_area=(1000, 0, 11000, 5000), margins=None, coordinate_system=None): if name is None: name = os.path.join(self.gx.temp_folder(), "test") gxmap.delete_files(name) if coordinate_system is None: coordinate_system = gxcs.Coordinate_system("WGS 84 / UTM zone 15N") if margins is None: margins = (1.5, 1.5, 3, 1) return gxmap.Map.new(file_name=name, data_area=data_area, coordinate_system=coordinate_system, media="A4", margins=margins, inside_margin=0.5)
def test_vcs(self): self.start() self.assertEqual( gxcs.Coordinate_system("nad83 / UTM zone 15N [NAVD92]").name, 'NAD83 / UTM zone 15N [NAVD92]') self.assertEqual( gxcs.Coordinate_system("nad83 [NAVD92]").name, 'NAD83 [NAVD92]') self.assertFalse( gxcs.Coordinate_system("nad83 [NAVD92]").same_as( gxcs.Coordinate_system("NAD83 [geodetic]"))) self.assertFalse( gxcs.Coordinate_system("nad83 [geoid]").same_vcs( gxcs.Coordinate_system("NAD27 [NAVD92]")))
def test_create(self): self.start() with gxmap.Map.new() as gmap: vlist = gmap.view_list self.assertEqual(len(vlist), 2) self.assertTrue('base' in vlist) self.assertTrue('data' in vlist) with gxv.View.open(gmap, 'base') as v: self.assertTrue(v.guid) self.assertEqual(v.name, "base") self.assertEqual(v.scale, 1.0) self.assertEqual(v.aspect, 1.0) self.assertEqual(v.units_name, 'mm') self.assertEqual(v.units_per_metre, 1000.0) self.assertEqual(v.units_per_map_cm, 10.0) with gxv.View.new(gmap, 'ft12000', coordinate_system='ft', scale=12000, area=(0, 0, 50000, 40000)) as v: self.assertEqual(v.name, "ft12000") self.assertAlmostEqual(v.scale, 12000.0) self.assertAlmostEqual(v.aspect, 1.0) self.assertEqual(v.units_name, 'ft') self.assertAlmostEqual(v.units_per_metre, 3.280839895) self.assertAlmostEqual(v.units_per_map_cm, 393.7007874) with gxv.View.new(gmap) as vw: self.assertEqual(vw.name, "_unnamed_view") self.assertEqual(vw.scale, 100.0) self.assertEqual(vw.aspect, 1.0) self.assertEqual(vw.units_name, 'unknown') self.assertEqual(vw.units_per_metre, 1.0) with gxmap.Map.new() as gmap: with gxv.View.new(gmap, "test") as vw: self.assertEqual(vw.name, "test") with gxmap.Map.new() as gmap: area = (100, 500, 15100, 10500) scale = 20000 location = (0, 0) xcm = (area[2] - area[0]) * 100.0 / scale ycm = (area[3] - area[1]) * 100.0 / scale with gxv.View.new(gmap, "test", map_location=location, area=area, scale=scale, coordinate_system="WGS 84 / UTM zone 34N") as vw: self.assertEqual(vw.extent_clip, area) self.assertEqual(vw.extent_map_cm(vw.extent_clip), (0, 0, xcm, ycm)) self.assertEqual(vw.scale, scale, scale) self.assertTrue( vw.coordinate_system.same_as( gxcs.Coordinate_system("WGS 84 / UTM zone 34N"))) self.assertEqual(vw.units_per_metre, 1.0) self.assertEqual(vw.units_name, 'm') with gxmap.Map.new() as gmap: area = (100, 500, 15100, 10500) scale = 12000 loc = (7.5, 2.0) mpu = 1.0 / float( gxcs.parameters(gxcs.PARM_UNITS, 'ftUS')['FACTOR']) xcm = 100.0 * ((area[2] - area[0]) / scale) / mpu ycm = 100.0 * ((area[3] - area[1]) / scale) / mpu with gxv.View.new(gmap, "test", map_location=loc, area=area, scale=scale, coordinate_system=("WGS 84 / UTM zone 34N", '', '', 'ftUS', '')) as vw: self.assertEqual(vw.extent_clip, area) mx = vw.extent_map_cm(vw.extent_clip) self.assertAlmostEqual(mx[0], loc[0]) self.assertAlmostEqual(mx[1], loc[1]) self.assertAlmostEqual(mx[2], loc[0] + xcm) self.assertAlmostEqual(mx[3], loc[1] + ycm) self.assertAlmostEqual(vw.scale, scale) self.assertAlmostEqual(vw.aspect, 1.0) self.assertFalse( vw.coordinate_system.same_as( gxcs.Coordinate_system("WGS 84 / UTM zone 34N"))) self.assertTrue( vw.coordinate_system.same_as( gxcs.Coordinate_system( ("WGS 84 / UTM zone 34N", '', '', 'ftUS', '')))) self.assertAlmostEqual(vw.units_per_metre, 3.28083333333334) self.assertEqual(vw.units_name, 'ftUS') with gxmap.Map.new() as gmap: area = (100, 500, 15100, 10500) scale = 12000 loc = (7.5, 2.0) mpu = 1.0 / float( gxcs.parameters(gxcs.PARM_UNITS, 'ftUS')['FACTOR']) xcm = 100.0 * ((area[2] - area[0]) / scale) / mpu ycm = 100.0 * ((area[3] - area[1]) / scale) / mpu with gxv.View.new(gmap, "test", map_location=loc, area=area, scale=scale, coordinate_system='ftUS') as vw: self.assertEqual(vw.extent_clip, area) mx = vw.extent_map_cm(vw.extent_clip) self.assertAlmostEqual(mx[0], loc[0]) self.assertAlmostEqual(mx[1], loc[1]) self.assertAlmostEqual(mx[2], loc[0] + xcm) self.assertAlmostEqual(mx[3], loc[1] + ycm) self.assertAlmostEqual(vw.scale, scale) self.assertAlmostEqual(vw.aspect, 1.0) self.assertTrue( vw.coordinate_system.same_as( gxcs.Coordinate_system(('', '', '', 'ftUS', '')))) self.assertAlmostEqual(vw.units_per_metre, 3.28083333333334) self.assertEqual(vw.units_name, 'ftUS') with gxmap.Map.new() as gmap: with gxv.View.new(gmap, "test", area=(100, 500, 15100, 10500), scale=(50000, 10000), map_location=(10, 25)) as vw: self.assertEqual(vw.extent_clip, (100, 500, 15100, 10500)) self.assertEqual(vw.scale, 50000) self.assertEqual(vw.aspect, 0.2) self.assertEqual(vw.extent_map_cm(vw.extent_clip), (10., 25., 40., 125.)) self.assertTrue( vw.coordinate_system.same_as(gxcs.Coordinate_system()))
def test_extent(self): self.start() with gxgrd.Grid.open(self.g1f) as g: with gxgrd.Grid.copy(g, os.path.join(self.folder, 'test_extent.grd(GRD)')) as grd: grd.delete_files() grd.x0 = grd.y0 = 0.0 grd.dx = grd.dy = 0.1 grd.rot = 0.0 ex = grd.extent_2d() self.assertAlmostEqual(ex[0], -0.05) self.assertAlmostEqual(ex[1], -0.05) self.assertAlmostEqual(ex[2], 10.05) self.assertAlmostEqual(ex[3], 10.05) grd.rot = 30.0 ex = grd.extent_2d() self.assertAlmostEqual(ex[0], -0.06830127018922194) self.assertAlmostEqual(ex[1], -5.068301270189221) self.assertAlmostEqual(ex[2], 13.72855530803361) self.assertAlmostEqual(ex[3], 8.72855530803361) cs = grd.coordinate_system cs_name = cs.cs_name(gxcs.NAME_HCS_VCS) + ' <0,0,0,0,0,30>' grd.coordinate_system = gxcs.Coordinate_system(cs_name) ex = grd.extent_2d() self.assertAlmostEqual(ex[0], -0.06830127018922194) self.assertAlmostEqual(ex[1], -5.068301270189221) self.assertAlmostEqual(ex[2], 13.72855530803361) self.assertAlmostEqual(ex[3], 8.72855530803361) grd.rot = 0 ex = grd.extent_2d() self.assertAlmostEqual(ex[0], -0.05) self.assertAlmostEqual(ex[1], -0.05) self.assertAlmostEqual(ex[2], 10.05) self.assertAlmostEqual(ex[3], 10.05) ex = grd.extent_3d() self.assertAlmostEqual(ex[0], -0.06830127018922) self.assertAlmostEqual(ex[1], -5.068301270189221) self.assertAlmostEqual(ex[2], 0.0) self.assertAlmostEqual(ex[3], 13.72855530803361) self.assertAlmostEqual(ex[4], 8.72855530803361) self.assertAlmostEqual(ex[5], 0) cs_name = cs.cs_name(gxcs.NAME_HCS_VCS) + ' <0,0,0,90,0,30>' grd.coordinate_system = gxcs.Coordinate_system(cs_name) ex = grd.extent_3d() self.assertAlmostEqual(ex[0], -0.04330127018922194) self.assertAlmostEqual(ex[1], -5.025) self.assertAlmostEqual(ex[2], -10.05) self.assertAlmostEqual(ex[3], 8.70355530803360) self.assertAlmostEqual(ex[4], 0.025) self.assertAlmostEqual(ex[5], 0.05) grd.rot = 30.0 ex = grd.extent_2d() self.assertAlmostEqual(ex[0], -0.0683012701892219) self.assertAlmostEqual(ex[1], -5.068301270189221) self.assertAlmostEqual(ex[2], 13.72855530803361) self.assertAlmostEqual(ex[3], 8.72855530803361) ex = grd.extent_3d() self.assertAlmostEqual(ex[0], -0.05915063509461113) self.assertAlmostEqual(ex[1], -6.864277654016804) self.assertAlmostEqual(ex[2], -8.72855530803361) self.assertAlmostEqual(ex[3], 11.889277654016805) self.assertAlmostEqual(ex[4], 0.03415063509461143) self.assertAlmostEqual(ex[5], 5.068301270189221)
def test_name_cs(self): self.start() hcs, orient, vcs = gxcs.hcs_orient_vcs_from_name( "DHDN / Okarito 2000 [geoid]") self.assertEqual(hcs, "DHDN / Okarito 2000") self.assertEqual(orient, "") self.assertEqual(vcs, "geoid") self.assertEqual(gxcs.name_from_hcs_orient_vcs(hcs, orient, vcs), "DHDN / Okarito 2000 [geoid]") hcs, orient, vcs = gxcs.hcs_orient_vcs_from_name( "DHDN / Okarito 2000 <0,0,0,0,0,0> [geoid] ") self.assertEqual(hcs, "DHDN / Okarito 2000") self.assertEqual(orient, "0,0,0,0,0,0") self.assertEqual(vcs, "geoid") self.assertEqual(gxcs.name_from_hcs_orient_vcs(hcs, orient, vcs), "DHDN / Okarito 2000 <0,0,0,0,0,0> [geoid]") hcs, orient, vcs = gxcs.hcs_orient_vcs_from_name( "DHDN / Okarito 2000 <0,0,0,0,0,0>") self.assertEqual(hcs, "DHDN / Okarito 2000") self.assertEqual(orient, "0,0,0,0,0,0") self.assertEqual(vcs, "") self.assertEqual(gxcs.name_from_hcs_orient_vcs(hcs, orient, vcs), "DHDN / Okarito 2000 <0,0,0,0,0,0>") hcs, orient, vcs = gxcs.hcs_orient_vcs_from_name("DHDN / Okarito 2000") self.assertEqual(hcs, "DHDN / Okarito 2000") self.assertEqual(orient, "") self.assertEqual(vcs, "") self.assertEqual(gxcs.name_from_hcs_orient_vcs(hcs, orient, vcs), "DHDN / Okarito 2000") with gxcs.Coordinate_system('DHDN / Okarito 2000 [geodetic]') as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000 [geodetic]') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') self.assertEqual(cs.cs_name(), 'DHDN / Okarito 2000 [geodetic]') self.assertEqual(cs.cs_name(what=gxcs.NAME), 'DHDN / Okarito 2000 [geodetic]') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), 'geodetic') self.assertEqual(cs.cs_name(what=gxcs.NAME_DATUM), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_PROJECTION), 'Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_ORIENTATION), '0,0,0,0,0,0') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT), 'm') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT_FULL), 'metre') with gxcs.Coordinate_system('DHDN [geoid]') as cs: self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), cs.name) self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), cs.hcs) self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), cs.vcs) self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), 'geoid') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN [geoid]') with gxcs.Coordinate_system('DHDN [geodetic]') as cs: self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), cs.name) self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), cs.hcs) self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), cs.vcs) self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), 'geodetic') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN [geodetic]')
def test_any(self): self.start() # name with gxcs.Coordinate_system('DHDN / Okarito 2000') as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') self.assertEqual(cs.cs_name(), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), '') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_DATUM), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_PROJECTION), 'Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_ORIENTATION), '0,0,0,0,0,0') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT), 'm') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT_FULL), 'metre') # GXF strings with gxcs.Coordinate_system(['', 'DHDN', 'Okarito 2000', '', '']) as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') cs.gxf = [ '', 'NAD27', '"Transverse Mercator",0,-87,0.9996,500000,0', 'm,1', '' ] self.assertEqual(cs, 'NAD27 / UTM zone 16N') # dictionary, json with gxcs.Coordinate_system('DHDN / Okarito 2000') as cs: dct = cs.coordinate_dict() with gxcs.Coordinate_system(dct) as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') csd = cs.coordinate_dict() self.assertEqual(csd['name'], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') js = cs.json with gxcs.Coordinate_system(js) as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') cs = gxcs.Coordinate_system() cs.json = '{"units": "m,1", "orientation": "", "datum": "NAD27,6378206.4,0.0822718542230039,0", "local_datum": "\\"NAD27 to WGS 84 (4)\\",-8,160,176,0,0,0,0", "projection": "\\"Transverse Mercator\\",0,-105,0.9996,500000,0", "name": "NAD27 / UTM zone 13N", "type": "Geosoft", "vcs": ""}' self.assertEqual(cs, 'NAD27 / UTM zone 13N') # ESRI wkt esri_wkt = 'PROJCS["Okarito_2000",GEOGCS["GCS_Deutsches_Hauptdreiecksnetz",DATUM["D_Deutsches_Hauptdreiecksnetz",SPHEROID["Bessel_1841",6377397.155,299.152812800001]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199432955]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000],PARAMETER["False_Northing",800000],PARAMETER["Central_Meridian",170.260833333333],PARAMETER["Scale_Factor",1],PARAMETER["Latitude_Of_Origin",-43.11],UNIT["Meter",1]]' with gxcs.Coordinate_system(esri_wkt) as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225274,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') cs.esri_wkt = 'PROJCS["NAD_1927_UTM_Zone_16N",GEOGCS["GCS_North_American_1927",DATUM["D_North_American_1927",SPHEROID["Clarke_1866",6378206.4,294.9786982]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-87.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",26716]]' self.assertEqual(cs, 'NAD27 / UTM zone 16N') # name with a separate vcs with gxcs.Coordinate_system('DHDN / Okarito 2000') as cs: cs.vcs = 'geoid' self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), str(cs)) self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), 'geoid') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN / Okarito 2000 [geoid]') # name with embedded vcs with gxcs.Coordinate_system('DHDN / Okarito 2000 [geoid]') as cs: self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), str(cs)) self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), 'geoid') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN / Okarito 2000 [geoid]') ipj = gxapi.GXIPJ.create() ipj.set_gxf('', 'DHDN', 'Okarito 2000', '', '') with gxcs.Coordinate_system(ipj) as cs: gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') self.assertEqual(cs.cs_name(), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), '') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_DATUM), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_PROJECTION), 'Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_ORIENTATION), '0,0,0,0,0,0') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT), 'm') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT_FULL), 'metre') with gxcs.Coordinate_system(gxcs.Coordinate_system(ipj)) as cs: self.assertEqual(cs.vcs, '') gxfs = cs.gxf self.assertEqual(gxfs[0], 'DHDN / Okarito 2000') self.assertEqual(gxfs[1], 'DHDN,6377397.155,0.0816968312225275,0') self.assertEqual( gxfs[2], '"Transverse Mercator",-43.11,170.260833333333,1,400000,800000' ) self.assertEqual(gxfs[3], 'm,1') self.assertEqual( gxfs[4], '"DHDN to WGS 84 (1)",582,105,414,1.04,0.35,-3.08,8.3') self.assertEqual(cs.cs_name(), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_VCS), '') self.assertEqual(cs.cs_name(what=gxcs.NAME_HCS_VCS), 'DHDN / Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_DATUM), 'DHDN') self.assertEqual(cs.cs_name(what=gxcs.NAME_PROJECTION), 'Okarito 2000') self.assertEqual(cs.cs_name(what=gxcs.NAME_ORIENTATION), '0,0,0,0,0,0') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT), 'm') self.assertEqual(cs.cs_name(what=gxcs.NAME_UNIT_FULL), 'metre')
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)
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)
def test_from_xml(self): self.start() temp_grid = gx.gx().temp_file('grd') cs = gxcs.Coordinate_system('NAD27 / UTM zone 18N') gxgrd.Grid.new(temp_grid, properties={ 'dtype': np.int16, 'nx': 100, 'ny': 50, 'x0': 4, 'y0': 8, 'dx': 0.1, 'dy': 0.2, 'rot': 5, 'coordinate_system': cs }).close() cs = gxspd.coordinate_system_from_metadata_file(temp_grid) self.assertEqual(str(cs), 'NAD27 / UTM zone 18N') gxf = cs.gxf.copy() gxf[0] = 'crazy' gxf[1] = 'weird,6378206.4,0.0822718542230039,0' cs = gxcs.Coordinate_system(gxf) with gxgrd.Grid.new(temp_grid, overwrite=True, properties={ 'dtype': np.int16, 'nx': 100, 'ny': 50, 'x0': 4, 'y0': 8, 'dx': 0.1, 'dy': 0.2, 'rot': 5, 'coordinate_system': cs }) as grd: pass cs = gxspd.coordinate_system_from_metadata_file(temp_grid) self.assertEqual(str(cs), 'weird / UTM zone 18N') with gxcs.Coordinate_system('WGS 84') as cs: xml = cs.xml xml_dict = gxu.dict_from_xml(xml) with gxcs.Coordinate_system(xml_dict) as wgs: self.assertEqual(str(wgs), 'WGS 84') with gxcs.Coordinate_system() as cs: cs.xml = xml self.assertEqual(str(cs), 'WGS 84') with gxcs.Coordinate_system(xml) as cs: self.assertEqual(str(cs), 'WGS 84') with gxcs.Coordinate_system.local(lon_lat=(-96, 43), azimuth=25) as csd: 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') xml = csd.xml with gxcs.Coordinate_system() as csxml: csxml.xml = xml self.assertEqual(csxml.name, 'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>') self.assertEqual(csxml.gxf[2], '"Oblique Stereographic",43,-96,0.9996,0,0') with gxcs.Coordinate_system(xml) as csxml: self.assertEqual(csxml.name, 'WGS 84 / *Local(43,-96,0,0) <0,0,0,0,0,25>') self.assertEqual(csxml.gxf[2], '"Oblique Stereographic",43,-96,0.9996,0,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')