Beispiel #1
0
    def test_3d_open(self):
        self.start()

        v3d_file = None
        try:

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.map.file_name
                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)

            self.assertRaises(gxv.ViewException, gxv.View_3d.open, 'bogus')

            with gxv.View_3d.open(v3d_file) as v:
                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

            self.crc_map(v3d_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
Beispiel #2
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
Beispiel #3
0
    def test_3dview(self):
        self.start()

        v3d_file = None

        try:

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.file_name
                self.assertTrue(v3d_file.lower().endswith('.geosoft_3dv'))
                self.assertEqual(v.name, 'test_3d')
                self.assertEqual(v.map.name, 'test_3d')

                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)

                v.new_drawing_plane('plane_0')
                self.assertEqual(v.current_3d_drawing_plane, 'plane_0')
                self.assertRaises(gxv.ViewException, v.new_drawing_plane,
                                  'plane_0')

                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                self.assertEqual(v.current_3d_drawing_plane, 'vertical')
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

                self.assertTrue('Plane' in v.plane_list)
                self.assertTrue('plane_0' in v.plane_list)
                self.assertTrue('vertical' in v.plane_list)
                self.assertEqual(v.plane_number('Plane'), 0)
                self.assertEqual(v.plane_name('vertical'), 'vertical')
                self.assertEqual(v.plane_name(2), 'vertical')
                self.assertRaises(gxv.ViewException, v.plane_number, 'bogus')
                self.assertRaises(gxv.ViewException, v.plane_number, -1)
                self.assertRaises(gxv.ViewException, v.plane_name, 3)
                self.assertRaises(gxv.ViewException, v.plane_name, 'bogus')
                self.assertEqual(v.get_class_name('Plane'), 'vertical')

            self.crc_map(v3d_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
Beispiel #4
0
    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)
Beispiel #5
0
    def test_copy_view(self):
        self.start()

        testmap = os.path.join(self.gx.temp_folder(), "test_view_cs")
        with gxmap.Map.new(testmap, overwrite=True) as gmap:
            with gxv.View.new(gmap, 'test_a') as v:
                with gxg.Draw(v, '2D stuff') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)
            with gxv.View.new(gmap, 'test_b', copy='test_a') as v:
                mdf = v.mdf('base')
                self.assertEqual(mdf[0],
                                 (36.39513677811551, 39.99513677811551, 0.0,
                                  6.395136778115507, 19.99513677811551, 0.0))
                self.assertEqual(mdf[1], (100.0, 1.0, 0.0, 0.0))
                mdf2 = v.mdf()
                self.assertEqual(mdf2, ((30.0, 20.0, 0.0, 0.0, 0.0, 0.0),
                                        (100.0, 1.0, 0.0, 0.0)))

                self.assertEqual(len(v.group_list), 1)
                self.assertEqual(v.group_list[0], '2D stuff')

                self.assertEqual(v.extent_all, v.extent_visible)
                self.assertEqual(v.extent_map_cm(), (0.0, 0.0, 30.0, 20.0))
                self.assertEqual(v.extent_group('2D stuff', unit=gxv.UNIT_MAP),
                                 (0.0, 0.0, 30.0, 20.0))
                self.assertEqual(v.extent_group('2D stuff'),
                                 (0.0, 0.0, 30.0, 20.0))

            self.assertEqual(len(gmap.view_list), 4)
Beispiel #6
0
 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))
Beispiel #7
0
    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)
Beispiel #8
0
    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)
Beispiel #9
0
    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)
Beispiel #10
0
    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)
Beispiel #11
0
    def test_reopen_map_view(self):
        self.start()

        testmap = os.path.join(self.gx.temp_folder(),
                               "test_view_reopen_map_view")
        with gxmap.Map.new(testmap, overwrite=True) as gmap:
            mapfile = gmap.file_name
            with gxv.View.new(gmap, "test_view") as v:
                with gxg.Draw(v) as g:
                    g.rectangle(v.extent_clip)
            with gxv.View.open(gmap, "test_view") as v:
                pass
        gxmap.delete_files(mapfile)
Beispiel #12
0
    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))
Beispiel #13
0
    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)
Beispiel #14
0
    def test_planes(self):
        self.start()

        v3d_file = None

        try:

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.file_name
                with gxg.Draw(v, 'default_plane') as g:
                    draw_2d_stuff(g)
                self.assertEqual(v.current_3d_drawing_plane, 'Plane')
                self.assertRaises(gxv.ViewException, v.new_drawing_plane,
                                  'Plane')

                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                self.assertEqual(v.current_3d_drawing_plane, 'vertical')
                with gxg.Draw(v, '2D stuff vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw(v, 'rectangle_plane', plane='Plane') as g:
                    g.rectangle(v.extent_clip)

                self.assertTrue('vertical' in v.plane_list)
                self.assertTrue('Plane' in v.plane_list)

                gop = v.groups_on_plane_list('Plane')
                self.assertEqual(len(gop), 2)
                self.assertTrue('default_plane' in gop)
                self.assertTrue('rectangle_plane' in gop)

            self.crc_map(v3d_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
Beispiel #15
0
    def test_3d_map(self):
        self.start()

        v3d_file = None
        map_file = None
        try:

            with gxmap.Map.new() as map:
                map_file = map.file_name
                with gxv.View.open(map, '*base') as v:
                    with gxg.Draw(v, 'edge') as g:
                        g.rectangle(v.extent_clip)

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.map.file_name
                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)
                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

                with gxmap.Map.open(map_file) as map:
                    map.create_linked_3d_view(v, 'linked_view')

            self.crc_map(map_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
            if map_file:
                gxmap.delete_files(map_file)
Beispiel #16
0
    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)
        with gxagg.Aggregate_image.new(grid_file_name, shade=True, contour=20) as agg:
            gxgroup.Aggregate_group.new(v, agg)

            # colour legend
            gxgroup.legend_color_bar(v, 'TMI_legend',
                                     title='Res TMI\nnT',
                                     location=(1.2,0),
                                     cmap=agg.layer_color_map(0),
                                     cmap2=agg.layer_color_map(1))

        # contour the grid
        gxgroup.contour(v, 'TMI_contour', grid_file_name)

    # map title and creator tag
    with gxview.View.open(gmap, "base") as v:
        with gxgroup.Draw(v, 'title') as g:

            g.text("Tutorial Example\nresidual mag",
                   reference=gxgroup.REF_BOTTOM_CENTER,
                   location=(100, 10),
                   text_def=gxgroup.Text_def(height=3.5,
                                             weight=gxgroup.FONT_WEIGHT_BOLD))
            g.text("created by:" + gxc.gid,
                   location=(1, 1.5),
                   text_def=gxgroup.Text_def(height=1.2,
                                             italics=True))

    # add a map surround to the map
    gmap.surround(outer_pen='kt500', inner_pen='kt100', gap=0.1)

    # annotate the data view locations