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])
def testSetValue(self): so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT) so.initValues(4) so.setValue(0, 'Foo'); assert so.numvalues == 4 assert so.getValue(0) == 'Foo' assert so.getValue(1) == ''
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)
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)
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 testNullValue(self): so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT) assert so.numvalues == 0 assert so.getValue(0) == None
def testAddEmpty(self): """expect an error rather than segfault when adding an empty shape""" # See bug 1201 sf = mapscript.shapefileObj('testAddDud.shp', 1) so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT) self.assertRaises(mapscript.MapServerError, sf.add, so)