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
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"
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)
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")
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)
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
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
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'
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)
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))
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
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
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
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()
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()
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')
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')
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()
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()
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()
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()
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"
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
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)