def test_view_extents(self): self.start() testmap = os.path.join(self.gx.temp_folder(), "test") with gxmap.Map.new(testmap, overwrite=True) as gmap: gmap.delete_view('data') gxv.View(gmap, "my_data_1", map_location=(2, 3), area=(0, 0, 1000, 1500), scale=10000).close() gxv.View(gmap, "my_data_2", map_location=(15, 3), area=(0, 0, 1000, 1500), scale=10000).close() ex = gmap.extent_data_views() self.assertEqual(ex, (2, 3, 25, 18)) mdf = gmap.mdf() self.assertEqual(mdf[0], (36.39513677811551, 39.99513677811551, 3.0, 24.395136778115507, 21.99513677811551, 2.0)) self.assertEqual(mdf[1], (10000.0, 1.0, 0.0, 0.0))
def _new_data_map(self, mapname=None, rescale=1.0): if mapname is None: mapname = os.path.join(self.gx.temp_folder(), 'test') with gxmap.Map.new(mapname, overwrite=True) as map: with gxv.View(map, "rectangle_test") as v: with gxg.Draw(v, 'rectangle') as g: g.rectangle((gxgm.Point((0, 0)), gxgm.Point((250, 110))), pen=gxg.Pen(line_thick=1)) p1 = gxgm.Point((5, 5)) * rescale p2 = gxgm.Point((100, 100)) * rescale poff = gxgm.Point((10, 5)) * rescale g.pen = gxg.Pen(fill_color=gxg.C_LT_GREEN) g.rectangle((p1, p2)) g.pen = gxg.Pen(line_style=2, line_pitch=2.0) g.line((p1 + poff, p2 - poff)) with gxv.View(map, "poly") as v: with gxg.Draw(v, 'poly') as g: plinelist = [[110, 5], [120, 20], [130, 15], [150, 50], [160, 70], [175, 35], [190, 65], [220, 50], [235, 18.5]] pp = gxgm.PPoint.from_list(plinelist) * rescale g.pen = gxg.Pen(line_style=2, line_pitch=2.0) g.polyline(pp) g.pen = gxg.Pen(line_style=4, line_pitch=2.0, line_smooth=gxg.SMOOTH_AKIMA) g.polyline(pp) ppp = np.array(plinelist) pp = gxgm.PPoint(ppp[3:, :]) * rescale g.pen = gxg.Pen(line_style=5, line_pitch=5.0, line_smooth=gxg.SMOOTH_CUBIC, line_color=gxapi.C_RED, line_thick=0.25, fill_color=gxapi.C_LT_BLUE) g.polyline(pp, close=True) g.pen = gxg.Pen(fill_color=gxapi.C_LT_GREEN) pp = (pp - (100, 0, 0)) / 2 + (100, 0, 0) g.polyline(pp, close=True) pp += (0, 25, 0) g.pen = gxg.Pen(fill_color=gxapi.C_LT_RED) g.polyline(pp, close=True) return map.file_name
def test_north_arrow_0(self): self.start() with gxmap.Map.new(coordinate_system='ft') as map: mapfile = map.file_name with gxv.View(map, 'base') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.north_arrow() self.crc_map(mapfile)
def crc_media(map_file, test_number): with gxmap.Map.open(map_file) as map: with gxv.View(map, "base") as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip, pen=gxg.Pen(line_thick=0.2, line_color='K')) with gxv.View(map, "data") as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip, pen=gxg.Pen(line_thick=0.2, line_color='R')) self.crc_map(map_file, pix_width=256, alt_crc_name='{}_{}'.format(gxsys.func_name(1), test_number))
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_surround_3(self): self.start() with gxmap.Map.new(data_area=(350000, 7000000, 400000, 7030000)) 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='rt500', inner_pen='K16') self.crc_map(mapfile)
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_scale_2(self): self.start() with gxmap.Map.new(data_area=(350000, 7000000, 400000, 7030000), coordinate_system='NAD83 / UTM zone 15N') as map: mapfile = map.file_name with gxv.View(map, 'base') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.scale_bar() map.scale_bar(location=(2, 0, 2), length=10, sections=12, pen=gxg.Pen(line_color='R'), text_def=gxg.Text_def(color='B', weight=gxg.FONT_WEIGHT_BOLD)) self.crc_map(mapfile)
def test_north_arrow_1(self): self.start() with gxmap.Map.new(coordinate_system='m', data_area=(0, 0, 20, 10), scale=100) as map: mapfile = map.file_name with gxv.View(map, 'base') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.north_arrow(location=(2, 0, 3), inclination=-12, declination=74.5, text_def=gxg.Text_def(font='Calibri')) self.crc_map(mapfile)
def test_multiple_temp_maps(self): self.start() mapfiles = [] for i in range(3): with gxmap.Map.new() as map: mapfiles.append(map.file_name) with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) for fn in mapfiles: self.assertTrue(os.path.isfile(fn))
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_metadata(self): self.start() testmap = os.path.join(self.gx.temp_folder(), "test") with gxmap.Map.new(testmap, overwrite=True) as gmap: gmap.delete_view('data') gxv.View(gmap, "my_data_1", map_location=(2, 3), area=(0, 0, 1000, 1500), scale=10000).close() gxv.View(gmap, "my_data_2", map_location=(15, 3), area=(0, 0, 1000, 1500), scale=10000).close() m = gmap.metadata gm = m['geosoft'] self.assertEqual(len(gm), 2) self.assertTrue('dataset' in gm) newstuff = {'maki': {'a': 1, 'b': (4, 5, 6), 'units': 'nT'}} gmap.metadata = newstuff with gxmap.Map.open(testmap) as gmap: m = gmap.metadata gm = m['geosoft'] self.assertEqual(len(gm), 2) self.assertTrue('dataset' in gm) maki = m['maki'] self.assertEqual(maki['b'], ['4', '5', '6']) self.assertEqual(maki['units'], 'nT')
def test_scale_1(self): self.start() with gxmap.Map.new(data_area=(350000, 7000000, 400000, 7030000), coordinate_system='ft') as map: mapfile = map.file_name with gxv.View(map, 'base') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) with gxv.View(map, 'data') as v: with gxg.Draw(v) as g: g.rectangle(v.extent_clip) map.scale_bar() map.scale_bar(location=(2, 0, 2), length=10, sections=12) map.scale_bar(location=(5, 0, 0), length=8, sections=2, post_scale=True) map.scale_bar(location=(3, -3, 1.5), length=4, text_def=gxg.Text_def(height=0.2, italics=True), post_scale=True) self.crc_map(mapfile)