Beispiel #1
0
 def testStyleConstructor(self):
     """styleObj Constructor"""
     self.initMap()
     style = mapscript.styleObj(self.map.getLayer(1).getClass(0))
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #2
0
 def testStyleConstructor(self):
     """styleObj Constructor"""
     self.initMap()
     style = mapscript.styleObj(self.map.getLayer(1).getClass(0))
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #3
0
 def testCloneStyle(self):
     """check attributes of a cloned style"""
     new_style = mapscript.styleObj()
     new_style.color.setHex("#808080")
     clone = new_style.clone()
     assert clone.thisown == 1
     assert clone.color.toHex() == "#808080"
Beispiel #4
0
 def testInsertStylePastEnd(self):
     """NewStylesTestCase.testInsertStylePastEnd: inserting a style past the end of the list raises the proper error"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     new_style = mapscript.styleObj()
     self.assertRaises(mapscript.MapServerChildError, class0.insertStyle,
                       new_style, 6)
Beispiel #5
0
 def testStyleBinding(self):
     """attribute binding can be set and get"""
     new_style = mapscript.styleObj()
     assert (not new_style.getBinding(mapscript.MS_STYLE_BINDING_COLOR))
     new_style.setBinding(mapscript.MS_STYLE_BINDING_COLOR, "NEW_BINDING")
     assert (new_style.getBinding(
         mapscript.MS_STYLE_BINDING_COLOR) == "NEW_BINDING")
Beispiel #6
0
    def setUp(self):
        # Inline feature layer
        self.ilayer = mapscript.layerObj()
        self.ilayer.type = mapscript.MS_LAYER_POLYGON
        self.ilayer.status = mapscript.MS_DEFAULT
        self.ilayer.connectiontype = mapscript.MS_INLINE

        cs = 'f7fcfd,e5f5f9,ccece6,99d8c9,66c2a4,41ae76,238b45,006d2c,00441b'
        colors = ['#' + h for h in cs.split(',')]
        #print colors

        for i in range(9):
            # Make a class for feature
            ci = self.ilayer.insertClass(mapscript.classObj())
            co = self.ilayer.getClass(ci)
            si = co.insertStyle(mapscript.styleObj())
            so = co.getStyle(si)
            so.color.setHex(colors[i])
            co.label.color.setHex('#000000')
            co.label.outlinecolor.setHex('#FFFFFF')
            co.label.type = mapscript.MS_BITMAP
            co.label.size = mapscript.MS_SMALL

            # The shape to add is randomly generated
            xc = 4.0 * (random() - 0.5)
            yc = 4.0 * (random() - 0.5)
            r = mapscript.rectObj(xc - 0.25, yc - 0.25, xc + 0.25, yc + 0.25)
            s = r.toPolygon()

            # Classify
            s.classindex = i
            s.text = "F%d" % (i)

            # Add to inline feature layer
            self.ilayer.addFeature(s)
Beispiel #7
0
 def testStyleColorSettable(self):
     """a style can be set with a color tuple"""
     new_style = mapscript.styleObj()
     new_style.color.setRGB(1, 2, 3)
     assert new_style.color.red == 1
     assert new_style.color.green == 2
     assert new_style.color.blue == 3
Beispiel #8
0
 def testStyleColorSettable(self):
     """a style can be set with a color tuple"""
     new_style = mapscript.styleObj()
     new_style.color.setRGB(1,2,3)
     assert new_style.color.red == 1
     assert new_style.color.green == 2
     assert new_style.color.blue == 3
Beispiel #9
0
 def testCloneStyle(self):
     """check attributes of a cloned style"""
     new_style = mapscript.styleObj()
     new_style.color.setHex('#808080')
     clone = new_style.clone()
     assert clone.thisown == 1
     assert clone.color.toHex() == '#808080'
Beispiel #10
0
    def setUp(self):
        # Inline feature layer
        self.ilayer = mapscript.layerObj()
        self.ilayer.type = mapscript.MS_LAYER_POLYGON
        self.ilayer.status = mapscript.MS_DEFAULT
        self.ilayer.connectiontype = mapscript.MS_INLINE

        cs = 'f7fcfd,e5f5f9,ccece6,99d8c9,66c2a4,41ae76,238b45,006d2c,00441b'
        colors = ['#' + h for h in cs.split(',')]
        #print colors
        
        for i in range(9):
            # Make a class for feature
            ci = self.ilayer.insertClass(mapscript.classObj())
            co = self.ilayer.getClass(ci)
            si = co.insertStyle(mapscript.styleObj())
            so = co.getStyle(si)
            so.color.setHex(colors[i])
            co.label.color.setHex('#000000')
            co.label.outlinecolor.setHex('#FFFFFF')
            co.label.type = mapscript.MS_BITMAP
            co.label.size = mapscript.MS_SMALL
            
            # The shape to add is randomly generated
            xc = 4.0*(random() - 0.5)
            yc = 4.0*(random() - 0.5)
            r = mapscript.rectObj(xc-0.25, yc-0.25, xc+0.25, yc+0.25)
            s = r.toPolygon()
            
            # Classify
            s.classindex = i
            s.text = "F%d" % (i)
            
            # Add to inline feature layer
            self.ilayer.addFeature(s)
Beispiel #11
0
def draw_map_wfs(name, save=0):
    #print "making map in thread %s" % (name)
    mo = mapscript.mapObj(TESTMAPFILE)
    
    # WFS layer
    lo = mapscript.layerObj()
    lo.name = 'cheapo_wfs'
    lo.setProjection('+init=epsg:4326')
    lo.connectiontype = mapscript.MS_WFS
    lo.connection = 'http://zcologia.com:9001/mapserver/members/features.rpy?'
    lo.metadata.set('wfs_service', 'WFS')
    lo.metadata.set('wfs_typename', 'users')
    lo.metadata.set('wfs_version', '1.0.0')
    lo.type = mapscript.MS_LAYER_POINT
    lo.status = mapscript.MS_DEFAULT
    lo.labelitem = 'zco:mid'

    so1 = mapscript.styleObj()
    so1.color.setHex('#FFFFFF')
    so1.size = 9
    so1.symbol = 1 #mo.symbolset.index('circle')

    so2 = mapscript.styleObj()
    so2.color.setHex('#333333')
    so2.size = 7
    so2.symbol = 1 #mo.symbolset.index('circle')
    
    co = mapscript.classObj()
    co.label.type = mapscript.MS_BITMAP
    co.label.size = mapscript.MS_SMALL
    co.label.color.setHex('#000000')
    co.label.outlinecolor.setHex('#FFFFFF')
    co.label.position = mapscript.MS_AUTO

    co.insertStyle(so1)
    co.insertStyle(so2)
    lo.insertClass(co)
    mo.insertLayer(lo)

    if not mo.web.imagepath:
        mo.web.imagepath = os.environ.get('TEMP', None) or INCOMING
    mo.debug = mapscript.MS_ON
    im = mo.draw()
    if save:
        im.save('threadtest_wfs_%s.png' % (name))
Beispiel #12
0
def draw_map_wfs(name, save=0):
    #print "making map in thread %s" % (name)
    mo = mapscript.mapObj(TESTMAPFILE)

    # WFS layer
    lo = mapscript.layerObj()
    lo.name = 'cheapo_wfs'
    lo.setProjection('+init=epsg:4326')
    lo.connectiontype = mapscript.MS_WFS
    lo.connection = 'http://zcologia.com:9001/mapserver/members/features.rpy?'
    lo.metadata.set('wfs_service', 'WFS')
    lo.metadata.set('wfs_typename', 'users')
    lo.metadata.set('wfs_version', '1.0.0')
    lo.type = mapscript.MS_LAYER_POINT
    lo.status = mapscript.MS_DEFAULT
    lo.labelitem = 'zco:mid'

    so1 = mapscript.styleObj()
    so1.color.setHex('#FFFFFF')
    so1.size = 9
    so1.symbol = 1  #mo.symbolset.index('circle')

    so2 = mapscript.styleObj()
    so2.color.setHex('#333333')
    so2.size = 7
    so2.symbol = 1  #mo.symbolset.index('circle')

    co = mapscript.classObj()
    co.label.type = mapscript.MS_BITMAP
    co.label.size = mapscript.MS_SMALL
    co.label.color.setHex('#000000')
    co.label.outlinecolor.setHex('#FFFFFF')
    co.label.position = mapscript.MS_AUTO

    co.insertStyle(so1)
    co.insertStyle(so2)
    lo.insertClass(co)
    mo.insertLayer(lo)

    if not mo.web.imagepath:
        mo.web.imagepath = os.environ.get('TEMP', None) or INCOMING
    mo.debug = mapscript.MS_ON
    im = mo.draw()
    if save:
        im.save('threadtest_wfs_%s.png' % (name))
Beispiel #13
0
 def testInsertStyle(self):
     """styleObj Insert"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     idx = self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #14
0
 def testInsertStyle(self):
     """styleObj Insert"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     idx = self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #15
0
 def testRemoveStyleAtBeginning(self):
     """styleObj remove first one"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     idx = self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).removeStyle(0)
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #16
0
 def testRemoveStyleAtBeginning(self):
     """styleObj remove first one"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     idx = self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).removeStyle(0)
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
Beispiel #17
0
 def testCloneStyle(self):
     """styleObj Clone"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).getStyle(0)
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
Beispiel #18
0
 def testCloneStyle(self):
     """styleObj Clone"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).getStyle(0)
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
Beispiel #19
0
 def testAppendNewStyleOldWay(self):
     """NewStylesTestCase.testAppendNewStyleOldWay: a new style can be appended properly using old method"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj(class0)
     assert new_style.thisown == 1, new_style.thisown
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     msimg = self.map.draw()
     data = msimg.saveToString()
     filename = 'testAppendNewStyleOldWay.png'
     fh = open(filename, 'wb')
     fh.write(data)
     fh.close()
Beispiel #20
0
 def testAppendNewStyleOldWay(self):
     """NewStylesTestCase.testAppendNewStyleOldWay: a new style can be appended properly using old method"""
     p_layer = self.map.getLayerByName("POINT")
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj(class0)
     assert new_style.thisown == 1, new_style.thisown
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     msimg = self.map.draw()
     data = msimg.saveToString()
     filename = "testAppendNewStyleOldWay.png"
     fh = open(filename, "wb")
     fh.write(data)
     fh.close()
Beispiel #21
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')
Beispiel #22
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')
Beispiel #23
0
 def testInsertNewStyleAtIndex0(self):
     """NewStylesTestCase.testInsertNewStyleAtIndex0: a new style can be inserted ahead of all others"""
     l_layer = self.map.getLayerByName("LINE")
     class0 = l_layer.getClass(0)
     new_style = mapscript.styleObj()
     new_style.color.setRGB(255, 255, 0)
     new_style.symbol = 1
     new_style.size = 7
     index = class0.insertStyle(new_style, 0)
     assert index == 0, index
     assert class0.numstyles == 2, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     data = msimg.saveToString()
     filename = "testInsertNewStyleAtIndex0.png"
     fh = open(filename, "wb")
     fh.write(data)
     fh.close()
Beispiel #24
0
 def testInsertNewStyleAtIndex0(self):
     """NewStylesTestCase.testInsertNewStyleAtIndex0: a new style can be inserted ahead of all others"""
     l_layer = self.map.getLayerByName('LINE')
     class0 = l_layer.getClass(0)
     new_style = mapscript.styleObj()
     new_style.color.setRGB(255, 255, 0)
     new_style.symbol = 1
     new_style.size = 7
     index = class0.insertStyle(new_style, 0)
     assert index == 0, index
     assert class0.numstyles == 2, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     data = msimg.saveToString()
     filename = 'testInsertNewStyleAtIndex0.png'
     fh = open(filename, 'wb')
     fh.write(data)
     fh.close()
Beispiel #25
0
 def testAppendNewStyle(self):
     """a new style can be appended properly"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj()
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     index = class0.insertStyle(new_style)
     assert index == 2, index
     assert class0.numstyles == 3, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     data = msimg.saveToString()
     filename = 'testAppendNewStyle.png'
     fh = open(filename, 'wb')
     fh.write(data)
     fh.close()
Beispiel #26
0
 def testAppendNewStyle(self):
     """a new style can be appended properly"""
     p_layer = self.map.getLayerByName("POINT")
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj()
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     index = class0.insertStyle(new_style)
     assert index == 2, index
     assert class0.numstyles == 3, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     data = msimg.saveToString()
     filename = "testAppendNewStyle.png"
     fh = open(filename, "wb")
     fh.write(data)
     fh.close()
Beispiel #27
0
 def testStyleBinding(self):
     """attribute binding can be set and get"""
     new_style = mapscript.styleObj()
     assert not new_style.getBinding(mapscript.MS_STYLE_BINDING_COLOR)
     new_style.setBinding(mapscript.MS_STYLE_BINDING_COLOR, "NEW_BINDING")
     assert new_style.getBinding(mapscript.MS_STYLE_BINDING_COLOR) == "NEW_BINDING"
Beispiel #28
0
 def testStyleConstructor(self):
     """a new style is properly initialized"""
     new_style = mapscript.styleObj()
     assert new_style.color.red == -1
     assert new_style.color.green == -1
     assert new_style.color.blue == -1
Beispiel #29
0
 def testInsertStylePastEnd(self):
     """NewStylesTestCase.testInsertStylePastEnd: inserting a style past the end of the list raises the proper error"""
     p_layer = self.map.getLayerByName("POINT")
     class0 = p_layer.getClass(0)
     new_style = mapscript.styleObj()
     self.assertRaises(mapscript.MapServerChildError, class0.insertStyle, new_style, 6)
Beispiel #30
0
 def testStyleConstructor(self):
     """a new style is properly initialized"""
     new_style = mapscript.styleObj()
     assert new_style.color.red == -1
     assert new_style.color.green == -1
     assert new_style.color.blue == -1