Example #1
0
    def test_cs(self):
        self.start()

        p = gxgeo.Point((5, 10))
        self.assertTrue(p == p)
        self.assertTrue(
            gxgeo.Point((1, 2), coordinate_system="WGS 84") == gxgeo.Point(
                (1, 2), coordinate_system="WGS 84"))
        self.assertTrue(
            gxgeo.Point((1,
                         2), coordinate_system="WGS 84") == gxgeo.Point((1,
                                                                         2)))
        self.assertTrue(gxgeo.Point((1, 2)) == gxgeo.Point((1, 2)))

        s = "WGS 84 / UTM zone 32N <0, 0, 0, 10, 15, 32>"
        p = gxgeo.Point((5, 10), coordinate_system=s)
        hcsd = p.coordinate_system.coordinate_dict()
        self.assertEqual(hcsd['name'],
                         "WGS 84 / UTM zone 32N <0,0,0,10,15,32>")
        self.assertTrue(p == p)

        s = s + ' [geoid]'
        pp = gxgeo.PPoint(((8, 12), (5, 10)), coordinate_system=s)
        hcsd = p.coordinate_system.coordinate_dict()
        self.assertEqual(hcsd['name'],
                         "WGS 84 / UTM zone 32N <0,0,0,10,15,32>")
        self.assertEqual(pp.coordinate_system.vcs, "geoid")
        self.assertTrue(pp == pp)
        self.assertTrue(pp == gxgeo.PPoint(((8, 12), (5, 10))))
        self.assertFalse(pp == gxgeo.PPoint(
            ((8, 12), (5, 10)), coordinate_system='WGS 84 [geoid]'))
        self.assertFalse(
            gxgeo.PPoint(((8, 12), (5, 10)),
                         coordinate_system='WGS 84 [geoid]') == pp)
Example #2
0
    def test_union(self):
        self.start()

        cs = "NAD83 / UTM zone 32N>"
        p = gxgeo.Point((500000, 6000000), cs)
        ext = gxgeo.extent_union(p, p)
        self.assertEqual(ext.p0.xyz, p.xyz)
        self.assertEqual(ext.p1.xyz, p.xyz)

        p2 = gxgeo.Point((500010, 6000100), cs)
        ext = gxgeo.extent_union(p, p2)
        self.assertEqual(ext.p0.xyz, p.xyz)
        self.assertEqual(ext.p1.xyz, p2.xyz)

        p3 = (490000, 5900000)
        ext = gxgeo.extent_union(p, p3)
        self.assertEqual(ext.p0.xyz, (490000, 5900000, 0))
        self.assertEqual(ext.p1.xyz, p.xyz)

        pp = gxgeo.PPoint((p2, gxgeo.Point(p3)))
        ext = gxgeo.extent_union(p, pp)
        self.assertEqual(ext.p0.xyz, (490000, 5900000, 0))
        self.assertEqual(ext.p1.xyz, p2.xyz)

        p2.coordinate_system = "NAD27 / UTM zone 32N"
        p2.z = -88
        p3 = gxgeo.Point(p3, "NAD27 / UTM zone 32N")
        p3.z = 51
        pp = gxgeo.PPoint((p2, p3))
        ext = gxgeo.extent_union(p, pp)
        self.assertEqual(ext.p0.xyz,
                         (490159.31817756349, 5900080.4689568691, -88.0))
        self.assertEqual(ext.p1.xyz,
                         (500169.21834333451, 6000179.4198679868, 51.0))
Example #3
0
    def test_pp_cs(self):
        self.start()

        p0 = gxgeo.Point((500000, 6000000))
        p1 = gxgeo.Point((500000, 6000000),
                         coordinate_system='NAD83 / UTM zone 15N')
        p2 = gxgeo.Point((500000, 6000000),
                         coordinate_system='NAD27 / UTM zone 15N')
        pp = gxgeo.PPoint((p0, p1, p2))
        self.assertEqual(pp.coordinate_system, 'NAD83 / UTM zone 15N')
        self.assertEqual(pp[0].xyz, (500000, 6000000, 0))
        self.assertEqual(pp[1].xyz, (500000, 6000000, 0))
        self.assertEqual(pp[2].xyz,
                         (499983.64366013405, 6000222.4158355873, 0.0))
        pp = gxgeo.PPoint((p0, p2, p1))
        self.assertEqual(pp.coordinate_system, 'NAD27 / UTM zone 15N')
        self.assertEqual(pp[0].xyz, (500000, 6000000, 0))
        self.assertEqual(pp[1].xyz, (500000, 6000000, 0))
        self.assertEqual(pp[2].xyz,
                         (500016.35614845896, 5999777.5863711238, 0.0))
        pp = gxgeo.PPoint((p0, p1, p2),
                          coordinate_system='NAD27 / UTM zone 15N')
        self.assertEqual(pp.coordinate_system, 'NAD27 / UTM zone 15N')
        self.assertEqual(pp[0].xyz, (500000, 6000000, 0))
        self.assertEqual(pp[1].xyz,
                         (500016.35614845896, 5999777.5863711238, 0.0))
        self.assertEqual(pp[2].xyz, (500000, 6000000, 0))
Example #4
0
    def test_pp_merge(self):
        self.start()

        plinelist = [[110, 5], [120, 20], [130, 15]]
        plinelst2 = [[150, 50], [160, 70]]
        plinelst3 = (190, 65, 4)

        pm = gxgeo.PPoint.merge((plinelist, plinelst2, [plinelst3]))
        self.assertEqual(pm.length, 6)
        self.assertEqual(tuple(pm[0]), (110, 5, 0))
        self.assertEqual(tuple(pm[4]), (160, 70, 0))
        self.assertEqual(tuple(pm[5]), (190, 65, 4))

        pm = gxgeo.PPoint.merge(
            (gxgeo.PPoint(plinelist), gxgeo.Point2(plinelst2),
             gxgeo.Point(plinelst3)))
        self.assertEqual(pm.length, 6)
        self.assertEqual(tuple(pm[0]), (110, 5, 0))
        self.assertEqual(tuple(pm[4]), (160, 70, 0))
        self.assertEqual(tuple(pm[5]), (190, 65, 4))

        center = gxgeo.Point((550000, 6000000))
        a = gxgeo.PPoint(plinelist) + center
        b = gxgeo.Point2(plinelst2,
                         coordinate_system="NAD83 / UTM zone 15N") + center
        c = gxgeo.Point(plinelst3,
                        coordinate_system="NAD27 / UTM zone 15N") + center

        pm = gxgeo.PPoint.merge((a, b, c))
        self.assertEqual(pm.length, 6)
        self.assertTrue(pm.coordinate_system == b.coordinate_system)
        self.assertEqual(tuple(pm[0]), (550110., 6000005., 0.))
        self.assertEqual(tuple(pm[4]), (550160., 6000070., 0.))
        self.assertEqual(str(pm[5]),
                         '_point_(550173.9373550161, 6000287.416398498, 4.0)')
Example #5
0
def draw_2d_stuff(g, size=1.0):
    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) * size
    g.pen = g.new_pen(line_style=2, line_pitch=2.0)
    g.polyline(pp)
    g.pen = g.new_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:, :]) * size
    g.pen = g.new_pen(line_style=5,
                      line_pitch=5.0,
                      line_smooth=gxg.SMOOTH_CUBIC,
                      line_color=gxg.C_RED,
                      line_thick=0.25,
                      fill_color=gxg.C_LT_BLUE)
    g.polygon(pp)

    g.pen = g.new_pen(fill_color=gxg.C_LT_GREEN)
    p1 = gxgm.Point((100, 0, 0)) * size
    p2 = gxgm.Point((100, 0, 0)) * size
    pp = (pp - p1) / 2 + p2
    g.polygon(pp)
    pp += gxgm.Point((0, 25, 0)) * size
    g.pen = g.new_pen(fill_color=gxg.C_LT_RED)
    g.polygon(pp)
Example #6
0
def draw_stuff(view, size=1.0):
    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) * size
    view.pen = {'line_style': (2, 2.0)}
    view.xy_poly_line(pp)
    view.pen = {'line_style': (4, 2.0), 'line_smooth': gxv.SMOOTH_AKIMA}
    view.xy_poly_line(pp)

    ppp = np.array(plinelist)
    pp = gxgm.PPoint(ppp[3:, :]) * size
    view.pen = {
        'line_style': (5, 5.0),
        'line_smooth': gxv.SMOOTH_CUBIC,
        'line_color': gxapi.C_RED,
        'line_thick': 0.25,
        'fill_color': gxapi.C_LT_BLUE
    }
    view.xy_poly_line(pp, close=True)

    view.pen = {'fill_color': gxapi.C_LT_GREEN}
    p1 = gxgm.Point((100, 0, 0)) * size
    p2 = gxgm.Point((100, 0, 0)) * size
    pp = (pp - p1) / 2 + p2
    view.xy_poly_line(pp, close=True)
    pp += gxgm.Point((0, 25, 0)) * size
    view.pen = {'fill_color': gxapi.C_LT_RED}
    view.xy_poly_line(pp, close=True)
Example #7
0
    def test_ppoint_constructors(self):
        self.start()

        def verify():
            self.assertEqual(pp.x.tolist(), [1., 4., 7., 10., 13.])
            self.assertEqual(pp.z.tolist(), [3., 6., 9., 12., 15.])
            self.assertEqual(pp.xy.tolist(), nppp[:, :2].tolist())

        lpp = ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12), (13, 14, 15))
        nppp = np.array(lpp)
        pp = gxgeo.PPoint(lpp)
        verify()

        nppp = np.array(lpp)
        pp = gxgeo.PPoint(nppp)
        verify()

        vvx = gxvv.GXvv(nppp[:, 0])
        vvy = gxvv.GXvv(nppp[:, 1])
        vvz = gxvv.GXvv(nppp[:, 2])
        pp = gxgeo.PPoint((vvx, vvy, vvz))
        verify()
        pp = gxgeo.PPoint((vvx, vvy), z=5)
        self.assertEqual(pp.x.tolist(), [1., 4., 7., 10., 13.])
        self.assertEqual(pp.z.tolist(), [5, 5, 5, 5, 5])

        vvx, vvy, vvz = pp.make_xyz_vv()
        self.assertEqual(tuple(vvx),
                         ((1, 0.0), (4, 1.0), (7, 2.0), (10, 3.0), (13, 4.0)))
        self.assertEqual(tuple(vvy),
                         ((2, 0.0), (5, 1.0), (8, 2.0), (11, 3.0), (14, 4.0)))
        self.assertEqual(tuple(vvz), ((5.0, 0.0), (5.0, 1.0), (5.0, 2.0),
                                      (5.0, 3.0), (5.0, 4.0)))

        pps = []
        for xyz in lpp:
            pps.append(gxgeo.Point(xyz))
        pp = gxgeo.PPoint(pps)
        verify()

        e = pp.extent
        self.assertTrue(e[0] == gxgeo.Point((1, 2, 3)))
        self.assertTrue(e[1] == gxgeo.Point((13, 14, 15)))
Example #8
0
    def test_names(self):
        self.start()

        self.assertEqual(gxgeo.Point((1, 2)).name, '_point_')
        self.assertEqual(gxgeo.Point((1, 2), name='maki').name, 'maki')
        self.assertTrue(
            gxgeo.Point((1, 2)) == gxgeo.Point((1, 2), name='maki'))
        self.assertEqual(gxgeo.Point(gxgeo.Point((1, 2))).name, '_point_')
        self.assertEqual(
            gxgeo.Point(gxgeo.Point((1, 2)), name='maki').name, 'maki')
        p1 = (1, 2)
        p2 = (2, 3)
        self.assertEqual(gxgeo.Point2((p1, p2)).name, '_point2_')
        self.assertEqual(gxgeo.Point2((p1, p2), name='maki').name, 'maki')
        self.assertTrue(
            gxgeo.Point2((p1, p2)) == gxgeo.Point2((p1, p2), name='maki'))
        pp = ((1, 2), (3, 2), (4, 5))
        self.assertEqual(gxgeo.PPoint(pp).name, '_ppoint_')
        self.assertEqual(gxgeo.PPoint(pp, name='maki').name, 'maki')
        self.assertTrue(gxgeo.PPoint(pp) == gxgeo.PPoint(pp, name='maki'))
Example #9
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
Example #10
0
def new_test_map(mapname='test', rescale=1.0, locate=None):

    test_map = os.path.join(gx.GXpy().temp_folder(), mapname)
    with gxmap.GXmap.new(test_map, overwrite=True) as gmap:
        with gxv.GXview(gmap, "rectangle_test") as view:
            view.start_group('rectangle')
            view.xy_rectangle((gxgm.Point((0, 0)), gxgm.Point((250, 110))),
                              pen={'line_thick': 1})

            p1 = gxgm.Point((5, 5)) * rescale
            p2 = gxgm.Point((100, 100)) * rescale
            poff = gxgm.Point((10, 5)) * rescale
            view.pen = {'fill_color': gxapi.C_LT_GREEN}
            view.xy_rectangle((p1, p2))

            view.pen = {'line_style': (2, 2.0)}
            view.xy_line((p1 + poff, p2 - poff))

        with gxv.GXview(gmap, "poly") as view:
            view.start_group('poly')
            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
            view.pen = {'line_style': (2, 2.0)}
            view.xy_poly_line(pp)
            view.pen = {
                'line_style': (4, 2.0),
                'line_smooth': gxv.SMOOTH_AKIMA
            }
            view.xy_poly_line(pp)

            ppp = np.array(plinelist)
            pp = gxgm.PPoint(ppp[3:, :]) * rescale
            view.pen = {
                'line_style': (5, 5.0),
                'line_smooth': gxv.SMOOTH_CUBIC,
                'line_color': gxapi.C_RED,
                'line_thick': 0.25,
                'fill_color': gxapi.C_LT_BLUE
            }
            view.xy_poly_line(pp, close=True)

            view.pen = {'fill_color': gxapi.C_LT_GREEN}
            pp = (pp - (100, 0, 0)) / 2 + (100, 0, 0)
            view.xy_poly_line(pp, close=True)
            pp += (0, 25, 0)
            view.pen = {'fill_color': gxapi.C_LT_RED}
            view.xy_poly_line(pp, close=True)

        return gmap.filename
Example #11
0
    def test_ppoint(self):
        self.start()

        points = [(5, 10), (6, 11), (7, 12)]
        pp = gxgeo.PPoint(points)
        self.assertEqual(len(pp), 3)
        i = 0
        for p in pp:
            self.assertEqual(p.xy, points[i])
            i += 1
        i = 0
        for p in pp:
            self.assertEqual(p.xyz, (points[i][0], points[i][1], 0.0))
            i += 1

        p = pp[1]
        self.assertEqual(p.xy, points[1])

        pp -= (0, 0, 15)
        self.assertEqual(pp[0].xyz, (5.0, 10.0, -15.0))
        self.assertEqual(pp[2].xyz, (7.0, 12.0, -15.0))

        pp += gxgeo.Point((0, 0, 15))
        self.assertEqual(pp[0].xyz, (5.0, 10.0, 0.0))
        self.assertEqual(pp[2].xyz, (7.0, 12.0, 0.0))

        px = pp + gxgeo.PPoint(((0, 0, 15), (-1, -1, -10), (1, 2, 3)))
        self.assertEqual(px[0].xyz, (5.0, 10.0, 15.0))
        self.assertEqual(px[2].xyz, (8.0, 14.0, 3.0))

        pp -= gxgeo.PPoint(((0, 0, 15), (-1, -1, -10), (0, 0, 0)))
        self.assertEqual(pp[0].xyz, (5.0, 10.0, -15.0))
        self.assertEqual(pp[1].xyz, (7, 12, 10))
        self.assertEqual(pp[2].xyz, (7., 12., 0.))

        pp -= gxgeo.Point((1, 2, 3))
        self.assertEqual(pp[0].xyz, (4.0, 8.0, -18.0))
        self.assertEqual(pp[1].xyz, (6, 10, 7))
        self.assertEqual(pp[2].xyz, (6., 10., -3.))

        pp = gxgeo.PPoint([(5, 10, 3.5)])
        self.assertEqual(pp[0].xyz, (5.0, 10.0, 3.5))

        pp = gxgeo.PPoint(((1, 2, 3), (4, 5, 6), (7, 8, 9)))

        pp += (1, 2, 3)
        self.assertEqual(pp[0].xyz, (2., 4., 6.))
        self.assertEqual(pp[2].xyz, (8., 10., 12.))

        pp *= (1, 2, 3)
        pp /= (1, 2, 3)
        self.assertEqual(pp[0].xyz, (2., 4., 6.))
        self.assertEqual(pp[2].xyz, (8., 10., 12.))
        pp *= (1, 2, 3)
        pp /= gxgeo.Point((1, 2, 3))
        self.assertEqual(pp[0].xyz, (2., 4., 6.))
        self.assertEqual(pp[2].xyz, (8., 10., 12.))
        pp *= (1, 2, 3)
        p = gxgeo.Point((1, 2, 3))
        pp /= gxgeo.PPoint((p, p, p))
        self.assertEqual(pp[0].xyz, (2., 4., 6.))
        self.assertEqual(pp[2].xyz, (8., 10., 12.))

        pp *= gxgeo.Point((-1, -1, -1))
        self.assertEqual(pp[0].xyz, (-2., -4., -6.))
        self.assertEqual(pp[2].xyz, (-8., -10., -12.))
        pp = -pp

        pp *= 2
        self.assertEqual(pp[1].xyz, (10., 14., 18.))

        pp /= 2
        self.assertEqual(pp[1].xyz, (5., 7., 9.))

        pp = -pp
        self.assertEqual(pp[1].xyz, (-5., -7., -9.))

        pp = pp + (1, 2)
        self.assertEqual(pp[1].xyz, (-4., -5., -9.))

        pp = pp + (5, 2, 6)
        self.assertEqual(pp[1].xyz, (1., -3., -3.))

        pp = pp + ((1, 2, 3), (4, 5, 6), (7, 8, 9))
        self.assertEqual(pp[1].xyz, (5., 2., 3.))

        pp = pp * gxgeo.PPoint(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
        self.assertEqual(pp[1].xyz, (20., 10., 18.))
        self.assertEqual(len(pp), 3)
        self.assertEqual(tuple(pp.x), (5., 20., 35.))
        self.assertEqual(tuple(pp.y), (4., 10., 16.))
        self.assertEqual(tuple(pp.z), (9., 18., 27.))

        points = [(5, 10), (6, 11), (7, 12)]
        pp = gxgeo.PPoint(points, z=3.5)
        self.assertEqual(pp.x.tolist(), [5., 6., 7.])
        self.assertEqual(pp.z.tolist(), [3.5, 3.5, 3.5])
        self.assertEqual(pp.xy.tolist(), np.array(points).tolist())

        pp.x = 4.8
        pp.y = (8., 5., 3.)
        pp.z = (1., 2., "-3")
        self.assertEqual(pp.x.tolist(), [4.8, 4.8, 4.8])
        self.assertEqual(pp.y.tolist(), [8., 5., 3.])
        self.assertEqual(pp.z.tolist(), [1., 2., -3.])

        pp.xy = [(1, 2), (3, 4), (5, 6)]
        self.assertEqual(pp.xy.tolist(), [[1., 2.], [3., 4.], [5., 6.]])

        pp = gxgeo.PPoint(((500000, 6000000), (500001, 6000001)),
                          coordinate_system='NAD83 / UTM zone 15N')
        pp27 = gxgeo.PPoint(pp, coordinate_system='NAD27 / UTM zone 15N')
        self.assertEqual(pp27[0].xyz,
                         (500016.35614845896, 5999777.5863711238, 0.0))
        self.assertEqual(pp27[1].xyz,
                         (500017.35614260647, 5999778.5863652565, 0.0))
        self.assertEqual(pp27.length, 2)
Example #12
0
def sample_map(gxp, mapname='test', rescale=1.0, locate=None):

    with gxmap.GXmap.new(mapname, overwrite=True) as gmap:
        """
        with gxv.GXview(gmap, 'base',area=(0, 0, 200, 150), scale=100.0)as vw:
            vw.xy_rectangle(vw.extent(), pen={"line_color":'B'})
        with gxv.GXview(gmap, 'data', map_location=(5,5), area=(0,0,300,250)) as vw:
            vw.xy_rectangle(vw.extent())
        """

        p2 = gxgm.Point((110, 110)) * rescale
        with gxv.GXview(gmap,
                        "rectangle_test",
                        area=(0, 0, p2.x, p2.y),
                        scale=100.0) as view:
            view.start_group('rect')
            view.xy_rectangle(((0, 0), p2), pen={'line_thick': 1})

            p1 = gxgm.Point((5, 5)) * rescale
            p2 = gxgm.Point((100, 100)) * rescale
            poff = gxgm.Point((10, 5)) * rescale
            view.pen = {'fill_color': gxapi.C_LT_GREEN}
            view.xy_rectangle((p1, p2))

            view.pen = {'line_style': (2, 2.0)}
            view.xy_line((p1 + poff, p2 - poff))

        p2 = gxgm.Point((250, 110)) * rescale
        with gxv.GXview3d(gmap,
                          viewname="poly",
                          area=(0, 0, p2.x, p2.y),
                          scale=100.0) as view:
            view.start_group('stuff')
            view.xy_rectangle(((0, 0), p2),
                              pen={
                                  'line_thick': 3,
                                  'line_color': 'B'
                              })
            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
            view.pen = {'line_style': (2, 2.0)}
            view.xy_poly_line(pp)
            view.pen = {
                'line_style': (4, 2.0),
                'line_smooth': gxv.SMOOTH_AKIMA
            }
            view.xy_poly_line(pp)

            ppp = np.array(plinelist)
            pp = gxgm.PPoint(ppp[3:, :]) * rescale
            view.pen = {
                'line_style': (5, 5.0),
                'line_smooth': gxv.SMOOTH_CUBIC,
                'line_color': gxapi.C_RED,
                'line_thick': 0.25,
                'fill_color': gxapi.C_LT_BLUE
            }
            view.xy_poly_line(pp, close=True)

            view.pen = {'fill_color': gxapi.C_LT_GREEN}
            pp = (pp - (100, 0, 0)) / 2 + (100, 0, 0)
            view.xy_poly_line(pp, close=True)
            pp += (0, 25, 0)
            view.pen = {'fill_color': "B"}
            view.xy_poly_line(pp, close=True)

            #TODO - viewer does not properly disply items on the plane if the box_3d is called
            view.box_3d(((20, 10, 30), (80, 50, 50)),
                        pen={'fill_color': 'R255G100B50'})

        return gmap.filename
Example #13
0
    def test_resample(self):
        self.start()

        plinelist = [[110, 5], [120, 20], [130, 15], [150, 50], [160, 70],
                     [175, 35], [190, 65], [220, 50], [235, 18.5]]

        pp = gxgeo.PPoint.from_list(plinelist)
        ppr = gxgeou.resample(pp, 2.5)
        self.assertEqual(ppr.length, 93)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-1]),
            '_point_(234.61203746485876, 20.64579408987188, 0.0)')

        ppr = gxgeou.resample(pp, 2.5, closed=True)
        self.assertEqual(ppr.length, 145)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(ppr[-1].xyz, ppr[0].xyz)

        ppr = gxgeou.resample(pp, 2.5, spline=gxgeou.SPLINE_AKIMA, closed=True)
        self.assertEqual(ppr.length, 145)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-2]),
            '_point_(109.96046205631022, 4.960353267681198, 0.0)')

        ppr = gxgeou.resample(pp,
                              2.5,
                              spline=gxgeou.SPLINE_LINEAR,
                              closed=True)
        self.assertEqual(ppr.length, 145)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-2]),
            '_point_(110.15605873233088, 5.016854343091733, 0.0)')

        ppr = gxgeou.resample(plinelist,
                              2.5,
                              spline=gxgeou.SPLINE_LINEAR,
                              closed=True)
        ppr = gxgeo.PPoint(ppr)
        self.assertEqual(ppr.length, 145)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-2]),
            '_point_(110.15605873233088, 5.016854343091733, 0.0)')

        ppr = gxgeou.resample(plinelist,
                              2.5,
                              spline=gxgeou.SPLINE_NEAREST,
                              closed=True)
        ppr = gxgeo.PPoint(ppr)
        self.assertEqual(ppr.length, 144)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(ppr[-1], pp[0])

        ppr = gxgeou.resample(plinelist, 2.5, spline=gxgeou.SPLINE_NEAREST)
        ppr = gxgeo.PPoint(ppr)
        self.assertEqual(ppr.length, 93)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(str(ppr[-1]), '_point_(235.0, 18.5, 0.0)')

        pp = np.array(plinelist)
        ppr = gxgeou.resample(pp[:, 0].flatten(),
                              2.5,
                              spline=gxgeou.SPLINE_CUBIC)
        self.assertEqual(len(ppr), 51)
        self.assertEqual(ppr[0, 0], pp[0, 0])
        self.assertEqual(ppr[-1, 0], 235.)

        pp = np.array(plinelist)
        ppr = gxgeou.resample(pp[:, 0].flatten(),
                              2.5,
                              spline=gxgeou.SPLINE_CUBIC,
                              closed=True)
        self.assertEqual(len(ppr), 102)
        self.assertEqual(ppr[0, 0], pp[0, 0])
        self.assertEqual(ppr[-1, 0], pp[0, 0])

        self.assertRaises(gxgeou.GeometryUtilityException, gxgeou.resample,
                          plinelist, -1)

        plinelist = [[110, 5], [120, 20], [130, 15], [150, 50], [160, 70],
                     [175, 35], [190, 65], [220, 50], [235, 18.5], [110, 5]]

        pp = gxgeo.PPoint(plinelist)
        ppr = gxgeou.resample(pp, 2.5, spline=gxgeou.SPLINE_AKIMA)
        self.assertEqual(ppr.length, 145)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-2]),
            '_point_(109.96046205631022, 4.960353267681198, 0.0)')

        pp = gxgeo.PPoint([[110, 5], [120, 20]])
        ppr = gxgeou.resample(pp, 2.5, spline=gxgeou.SPLINE_AKIMA)
        self.assertEqual(ppr.length, 8)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(
            str(ppr[-1]),
            '_point_(119.7072534339415, 19.560880150912265, 0.0)')

        pp = gxgeo.PPoint([[110, 5]])
        ppr = gxgeou.resample(pp, 2.5, spline=gxgeou.SPLINE_AKIMA)
        self.assertEqual(ppr.length, 1)
        self.assertEqual(ppr[0], pp[0])

        pp = gxgeo.PPoint([[110, 5], [110, 5]])
        ppr = gxgeou.resample(pp, 2.5, spline=gxgeou.SPLINE_AKIMA)
        self.assertEqual(ppr.length, 2)
        self.assertEqual(ppr[0], pp[0])
        self.assertEqual(ppr[1], pp[1])