示例#1
0
 def setUp(self):
     """The test fixture is a line with two points"""
     self.points = (mapscript.pointObj(0.0, 1.0),
                    mapscript.pointObj(2.0, 3.0))
     self.line = mapscript.lineObj()
     self.addPointToLine(self.line, self.points[0])
     self.addPointToLine(self.line, self.points[1])
示例#2
0
 def setUp(self):
     """The test fixture is a line with two points"""
     self.points = (mapscript.pointObj(0.0,
                                       1.0), mapscript.pointObj(2.0, 3.0))
     self.line = mapscript.lineObj()
     self.addPointToLine(self.line, self.points[0])
     self.addPointToLine(self.line, self.points[1])
示例#3
0
 def testSetPoints(self):
     """add lines of points to an existing symbol"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = mapscript.lineObj()
     self.addPointToLine(line, mapscript.pointObj(2.0, 2.0))
     self.addPointToLine(line, mapscript.pointObj(3.0, 3.0))
     assert symbol.setPoints(line) == 2
     assert symbol.numpoints == 2
     line = symbol.getPoints()
     assert line.numpoints == 2, line.numpoints
     pt = self.getPointFromLine(line, 1)
     self.assertPointsEqual(pt, mapscript.pointObj(3.0, 3.0))
示例#4
0
 def testSetPoints(self):
     """add lines of points to an existing symbol"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = mapscript.lineObj()
     self.addPointToLine(line, mapscript.pointObj(2.0, 2.0))
     self.addPointToLine(line, mapscript.pointObj(3.0, 3.0))
     assert symbol.setPoints(line) == 2
     assert symbol.numpoints == 2
     line = symbol.getPoints()
     assert line.numpoints == 2, line.numpoints
     pt = self.getPointFromLine(line, 1)
     self.assertPointsEqual(pt, mapscript.pointObj(3.0, 3.0))
示例#5
0
 def testDrawPoints(self):
     """DrawProgrammedStylesTestCase.testDrawPoints: point drawing with styles works as advertised"""
     points = [mapscript.pointObj(-0.2, 51.6), mapscript.pointObj(0.0, 51.2), mapscript.pointObj(0.2, 51.6)]
     colors = [mapscript.colorObj(255, 0, 0), mapscript.colorObj(0, 255, 0), mapscript.colorObj(0, 0, 255)]
     img = self.map.prepareImage()
     layer = self.map.getLayerByName("POINT")
     # layer.draw(self.map, img)
     class0 = layer.getClass(0)
     for i in range(len(points)):
         style0 = class0.getStyle(0)
         style0.color = colors[i]
         # style0.color.pen = -4
         assert style0.color.toHex() == colors[i].toHex()
         points[i].draw(self.map, layer, img, 0, "foo")
     img.save("test_draw_points.png")
示例#6
0
 def setUp(self):
     MapLayerTestCase.setUp(self)
     self.layer.minscaledenom = 1000
     self.layer.maxscaledenom = 2000
     self.layer.status = mapscript.MS_ON
     self.map.zoomScale(1500, mapscript.pointObj(100, 100), 200, 200,
                        self.map.extent, None)
示例#7
0
 def setUp(self):
     """The test fixture is a shape of one point"""
     self.points = (mapscript.pointObj(0.0, 1.0),)
     self.lines = (mapscript.lineObj(),)
     self.addPointToLine(self.lines[0], self.points[0])
     self.shape = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
     self.addLineToShape(self.shape, self.lines[0])
示例#8
0
 def setUp(self):
     """The test fixture is a shape of one point"""
     self.points = (mapscript.pointObj(0.0, 1.0),)
     self.lines = (mapscript.lineObj(),)
     self.addPointToLine(self.lines[0], self.points[0])
     self.shape = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
     self.addLineToShape(self.shape, self.lines[0])
示例#9
0
 def testPoint__str__(self):
     """return properly formatted string"""
     p = mapscript.pointObj(1.0, 1.0)
     if hasattr(p, 'z'):
         p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g }" % (p.x, p.y, p.z)
     else:
         p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)
     assert str(p) == p_str, str(p)
示例#10
0
 def testPoint__str__(self):
     """return properly formatted string"""
     p = mapscript.pointObj(1.0, 1.0)
     if hasattr(p, 'z'):
         p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g }" % (p.x, p.y, p.z)
     else:
         p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)
     assert str(p) == p_str, str(p)
示例#11
0
 def testSetXYM(self):
     """point can have its x and y reset (with m value)"""
     p = mapscript.pointObj()
     p.setXY(1.0, 1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)
     if hasattr(p, 'm'):
         self.assertAlmostEqual(p.m, 1.0)
示例#12
0
 def testGetPoints(self):
     """get symbol points as line and test coords"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = symbol.getPoints()
     assert line.numpoints == 1, line.numpoints
     pt = self.getPointFromLine(line, 0)
     self.assertPointsEqual(pt, mapscript.pointObj(1.0, 1.0))
示例#13
0
 def testRecenter(self):
     """ZoomPointTestCase.testRecenter: recentering the map with a point returns the same extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(1, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
示例#14
0
 def testSetXYM(self):
     """point can have its x and y reset (with m value)"""
     p = mapscript.pointObj()
     p.setXY(1.0, 1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)
     if hasattr(p, 'm'):
         self.assertAlmostEqual(p.m, 1.0)
示例#15
0
 def testZoomInPoint(self):
     """ZoomPointTestCase.testZoomInPoint: zooming in by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
示例#16
0
 def testGetPoints(self):
     """get symbol points as line and test coords"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = symbol.getPoints()
     assert line.numpoints == 1, line.numpoints
     pt = self.getPointFromLine(line, 0)
     self.assertPointsEqual(pt, mapscript.pointObj(1.0, 1.0))
示例#17
0
 def testSetXYZ(self):
     """point can have its x, y, z reset (with m value)"""
     p = mapscript.pointObj()
     p.setXYZ(1.0, 2.0, 3.0, 4.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 2.0)
     if hasattr(p, 'z') and hasattr(p, 'm'):
         self.assertAlmostEqual(p.z, 3.0)
         self.assertAlmostEqual(p.m, 4.0)
示例#18
0
 def testZoomOutPoint(self):
     """ZoomPointTestCase.testZoomOutPoint: zooming out by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
示例#19
0
 def testSetXYZ(self):
     """point can have its x, y, z reset (with m value)"""
     p = mapscript.pointObj()
     p.setXYZ(1.0, 2.0, 3.0, 4.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 2.0)
     if hasattr(p, 'z') and hasattr(p, 'm'):
         self.assertAlmostEqual(p.z, 3.0)
         self.assertAlmostEqual(p.m, 4.0)
示例#20
0
 def testZoomBadSize(self):
     """ZoomPointTestCase.testZoomBadSize: zooming to a bad size raises proper error"""
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     w = 0
     h = -1
     self.assertRaises(mapscript.MapServerError, 
         self.mapobj1.zoomPoint, -2, p, w, h, extent, None);
示例#21
0
 def xtestRecenter(self):
     """ZoomScaleTestCase.testRecenter: recentering map returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 2834.6472
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
示例#22
0
 def xtestZoomInScale(self):
     """ZoomScaleTestCase.testZoomInScale: zooming in to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 1417.3236
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
示例#23
0
 def testZoomBadExtent(self):
     """ZoomPointTestCase.testZoomBadExtent: zooming to a bad extent raises proper error"""
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     extent.maxx = extent.maxx - 1000000
     w = 100
     h = 100
     self.assertRaises(mapscript.MapServerError, 
         self.mapobj1.zoomPoint, -2, p, w, h, extent, None);
示例#24
0
    def testPointToString(self):
        """return properly formatted string in toString()"""
        p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
        if hasattr(p, 'z') and hasattr(p, 'm'):
            p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g, 'm': %.16g }" \
                  % (p.x, p.y, p.z, p.m)
        else:
            p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)

        assert p.toString() == p_str, p.toString()
示例#25
0
    def testPointToString(self):
        """return properly formatted string in toString()"""
        p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
        if hasattr(p, 'z') and hasattr(p, 'm'):
            p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g, 'm': %.16g }" \
                  % (p.x, p.y, p.z, p.m)
        else:
            p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)

        assert p.toString() == p_str, p.toString()
示例#26
0
 def xtestZoomOutScale(self):
     """ZoomScaleTestCase.testZoomOutScale: zooming out to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 5669.2944
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
示例#27
0
 def testDrawPoints(self):
     """DrawProgrammedStylesTestCase.testDrawPoints: point drawing with styles works as advertised"""
     points = [mapscript.pointObj(-0.2, 51.6),
               mapscript.pointObj(0.0, 51.2),
               mapscript.pointObj(0.2, 51.6)]
     colors = [mapscript.colorObj(255,0,0),
               mapscript.colorObj(0,255,0),
               mapscript.colorObj(0,0,255)]
     img = self.map.prepareImage()
     layer = self.map.getLayerByName('POINT')
     #layer.draw(self.map, img)
     class0 = layer.getClass(0)
     for i in range(len(points)):
         style0 = class0.getStyle(0)
         style0.color = colors[i]
         #style0.color.pen = -4
         assert style0.color.toHex() == colors[i].toHex()
         points[i].draw(self.map, layer, img, 0, "foo")
     img.save('test_draw_points.png')
示例#28
0
    def testGetPointWKT(self):
        # Create new instance from class data
        po = mapscript.pointObj(self.point_xy[0], self.point_xy[1])
        lo = mapscript.lineObj()
        lo.add(po)
        so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
        so.add(lo)

        # test output WKT
        wkt = so.toWKT()
        self.assert_(wkt == self.point_wkt, wkt)
示例#29
0
 def testZoomOutPointConstrained(self):
     """ZoomPointTestCase.testZoomOutPointConstrained: zooming out to a constrained extent returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     max = mapscript.rectObj()
     max.minx, max.miny, max.maxx, max.maxy = (-100.0,-100.0,100.0,100.0)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-4, p, w, h, extent, max)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, max)
示例#30
0
    def testGetPointWKT(self):
        # Create new instance from class data
        po = mapscript.pointObj(self.point_xy[0], self.point_xy[1])
        lo = mapscript.lineObj()
        lo.add(po)
        so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
        so.add(lo)

        # test output WKT
        wkt = so.toWKT()
        self.assert_(wkt == self.point_wkt, wkt)
示例#31
0
 def testAddPointFeature(self):
     """adding a point to an inline feature works correctly"""
     inline_layer = self.map.getLayerByName('INLINE')
     assert inline_layer.connectiontype == mapscript.MS_INLINE
     p = mapscript.pointObj(0.2, 51.5)
     l = mapscript.lineObj()
     self.addPointToLine(l, p)
     shape = mapscript.shapeObj(inline_layer.type)
     shape.classindex = 0
     self.addLineToShape(shape, l)
     inline_layer.addFeature(shape)
     msimg = self.map.draw()
     filename = 'testAddPointFeature.png'
     msimg.save(filename)
示例#32
0
 def testAddPointFeature(self):
     """adding a point to an inline feature works correctly"""
     inline_layer = self.map.getLayerByName('INLINE')
     assert inline_layer.connectiontype == mapscript.MS_INLINE
     p = mapscript.pointObj(0.2, 51.5)
     l = mapscript.lineObj()
     self.addPointToLine(l, p)
     shape = mapscript.shapeObj(inline_layer.type)
     shape.classindex = 0
     self.addLineToShape(shape, l)
     inline_layer.addFeature(shape)
     msimg = self.map.draw()
     filename = 'testAddPointFeature.png'
     msimg.save(filename)
示例#33
0
    def testSettingFonts(self):
        mo = mapscript.mapObj()
        assert mo.fontset.numfonts == 0
        mo.fontset.fonts.set('Vera',
                             os.path.join(TESTS_PATH, 'vera', 'Vera.ttf'))
        # NB: this does *not* increment the fonset.numfonts -- new bug

        mo.setSize(300, 300)
        mo.setExtent(-1.0, -1.0, 1.0, 1.0)

        lo = mapscript.layerObj()
        lo.type = mapscript.MS_LAYER_POINT
        lo.connectiontype = mapscript.MS_INLINE
        lo.status = mapscript.MS_DEFAULT

        co = mapscript.classObj()
        lbl = mapscript.labelObj()
        lbl.type = mapscript.MS_TRUETYPE
        lbl.font = 'Vera'
        lbl.size = 10
        lbl.color.setHex('#000000')
        co.addLabel(lbl)

        so = mapscript.styleObj()
        so.symbol = 0
        so.color.setHex('#000000')

        co.insertStyle(so)
        lo.insertClass(co)
        li = mo.insertLayer(lo)
        lo = mo.getLayer(li)

        point = mapscript.pointObj(0, 0)
        line = mapscript.lineObj()
        line.add(point)
        shape = mapscript.shapeObj(lo.type)
        shape.add(line)
        shape.setBounds()
        shape.text = 'Foo'
        shape.classindex = 0

        lo.addFeature(shape)
        im = mo.draw()

        #im = mo.prepareImage()
        #shape.draw(mo, lo, im)
        im.save('testSettingFonts.png')
示例#34
0
    def testSettingFonts(self):
        mo = mapscript.mapObj()
        assert mo.fontset.numfonts == 0
        mo.fontset.fonts.set('Vera', os.path.join(TESTS_PATH, 'vera',
                                                  'Vera.ttf'))
        # NB: this does *not* increment the fonset.numfonts -- new bug
                                                  
        mo.setSize(300, 300)
        mo.setExtent(-1.0, -1.0, 1.0, 1.0)
        
        lo = mapscript.layerObj()
        lo.type = mapscript.MS_LAYER_POINT
        lo.connectiontype = mapscript.MS_INLINE
        lo.status = mapscript.MS_DEFAULT

        co = mapscript.classObj()
        lbl =mapscript.labelObj() 
        lbl.type = mapscript.MS_TRUETYPE
        lbl.font = 'Vera'
        lbl.size = 10
        lbl.color.setHex('#000000')
        co.addLabel(lbl)

        so = mapscript.styleObj()
        so.symbol = 0
        so.color.setHex('#000000')
        
        co.insertStyle(so)
        lo.insertClass(co)
        li = mo.insertLayer(lo)
        lo = mo.getLayer(li)

        point = mapscript.pointObj(0,0)
        line = mapscript.lineObj()
        line.add(point)
        shape = mapscript.shapeObj(lo.type)
        shape.add(line)
        shape.setBounds()
        shape.text = 'Foo'
        shape.classindex = 0

        lo.addFeature(shape)
        im = mo.draw()
        
        #im = mo.prepareImage()
        #shape.draw(mo, lo, im)
        im.save('testSettingFonts.png')
示例#35
0
 def pointquery(self):
     p = mapscript.pointObj(0.0, 51.5)
     self.layer.queryByPoint(self.map, p, mapscript.MS_MULTIPLE, -1)
     return self.layer.getResults()
示例#36
0
 def testRectContainsPointNot(self):
     """point is not contained (spatially) in rectangle"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     p = mapscript.pointObj(3.00001, 0.0)
     assert p not in r, (p.x, p.y, r)
示例#37
0
 def testAddPointToLine(self):
     """adding a point to a line behaves correctly"""
     new_point = mapscript.pointObj(4.0, 5.0)
     self.addPointToLine(self.line, new_point)
     assert self.line.numpoints == 3
示例#38
0
 def testPointObjConstructorArgs(self):
     """point can be created with arguments"""
     p = mapscript.pointObj(1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)
示例#39
0
 def testAddPointToLine(self):
     """adding a point to a line behaves correctly"""
     new_point = mapscript.pointObj(4.0, 5.0)
     self.addPointToLine(self.line, new_point)
     assert self.line.numpoints == 3
示例#40
0
 def testZoomOutVisibility(self):
     """expect false visibility after zooming out beyond maximum"""
     self.map.zoomScale(2500, mapscript.pointObj(100, 100), 200, 200,
                        self.map.extent, None)
     assert self.layer.isVisible() == mapscript.MS_FALSE
示例#41
0
 def testPointQueryNoResults(self):
     qpoint = mapscript.pointObj(-100.0, 51.5)
     self.layer.queryByPoint(self.map, qpoint, mapscript.MS_MULTIPLE, 2.0)
     assert self.layer.getNumResults() == 0
示例#42
0
 def setUp(self):
     MapLayerTestCase.setUp(self)
     self.layer.minscaledenom = 1000
     self.layer.maxscaledenom = 2000
     self.layer.status = mapscript.MS_ON
     self.map.zoomScale(1500, mapscript.pointObj(100,100), 200, 200, self.map.extent, None)
示例#43
0
 def testPointQueryNoResults(self):
     qpoint = mapscript.pointObj(-100.0, 51.5)
     self.layer.queryByPoint(self.map, qpoint, mapscript.MS_MULTIPLE, 2.0)
     assert self.layer.getNumResults() == 0
示例#44
0
 def testZoomOutVisibility(self):
     """expect false visibility after zooming out beyond maximum"""
     self.map.zoomScale(2500, mapscript.pointObj(100,100), 200, 200, self.map.extent, None)
     assert self.layer.isVisible() == mapscript.MS_FALSE
示例#45
0
 def testCacheAfterFailedQuery(self):
     """point query with no results returns NULL"""
     p = mapscript.pointObj(0.0, 0.0)
     self.layer.queryByPoint(self.map, p, mapscript.MS_MULTIPLE, -1)
     results = self.layer.getResults()
     assert results == None
示例#46
0
 def pointquery(self):
     p = mapscript.pointObj(0.0, 51.5)
     self.layer.queryByPoint(self.map, p, mapscript.MS_MULTIPLE, -1)
     return self.layer.getResults()
示例#47
0
 def testCacheAfterFailedQuery(self):
     """point query with no results returns NULL"""
     p = mapscript.pointObj(0.0, 0.0)
     self.layer.queryByPoint(self.map, p, mapscript.MS_MULTIPLE, -1)
     results = self.layer.getResults()
     assert results == None
示例#48
0
 def testPointObjConstructorArgs(self):
     """point can be created with arguments"""
     p = mapscript.pointObj(1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)