def testCloneClass(self): """check attributes of a cloned class""" c = mapscript.classObj() c.minscaledenom = 5.0 clone = c.clone() assert clone.thisown == 1 assert clone.minscaledenom == 5.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)
def testConstructorWithArg(self): l = mapscript.layerObj() l.name = 'foo' c = mapscript.classObj(l) assert c.thisown == 1 assert c.layer.name == l.name assert c.numstyles == 0
def testDrawMapWithSecondPolygon(self): """draw a blue polygon and a red polygon""" p = self.map.getLayerByName("POLYGON") ip = mapscript.layerObj(self.map) ip.type = mapscript.MS_LAYER_POLYGON ip.status = mapscript.MS_DEFAULT c0 = mapscript.classObj(ip) # turn off first polygon layer's color p.getClass(0).getStyle(0).color.setRGB(-1, -1, -1) # copy this style to inline polygon layer, then change outlinecolor c0.insertStyle(p.getClass(0).getStyle(0)) st0 = c0.getStyle(0) st0.outlinecolor.setRGB(255, 0, 0) # pull out the first feature from polygon layer, shift it # and use this as an inline feature in new layer p.open() s0 = p.getFeature(0) p.close() r0 = s0.bounds r1 = mapscript.rectObj(r0.minx - 0.1, r0.miny - 0.1, r0.maxx - 0.1, r0.maxy - 0.1) s1 = r1.toPolygon() ip.addFeature(s1) img = self.map.draw() img.save("test_drawmapw2ndpolygon.png")
def xtestDrawMapWithSecondPolygon(self): """draw a blue polygon and a red polygon""" p = self.map.getLayerByName('POLYGON') ip = mapscript.layerObj(self.map) ip.type = mapscript.MS_LAYER_POLYGON ip.status = mapscript.MS_DEFAULT c0 = mapscript.classObj(ip) # turn off first polygon layer's color p.getClass(0).getStyle(0).color.setRGB(-1,-1,-1) # copy this style to inline polygon layer, then change outlinecolor c0.insertStyle(p.getClass(0).getStyle(0)) st0 = c0.getStyle(0) st0.outlinecolor.setRGB(255, 0, 0) # pull out the first feature from polygon layer, shift it # and use this as an inline feature in new layer p.open() s0 = p.getFeature(0) p.close() r0 = s0.bounds r1 = mapscript.rectObj(r0.minx-0.1, r0.miny-0.1, r0.maxx-0.1, r0.maxy-0.1) s1 = r1.toPolygon() ip.addFeature(s1) img = self.map.draw() img.save('test_drawmapw2ndpolygon.png')
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 testClassObj(self): self.initMap() layer = mapscript.layerObj(self.map) clazz = mapscript.classObj(layer) self.map = None layer = None assert str(clazz.p_layer).find('mapscript.layerObj') != -1 gc.collect() assert clazz.layer != None, clazz.layer
def testClassObj(self): self.initMap() layer = mapscript.layerObj(self.map) clazz = mapscript.classObj(layer) self.map=None layer=None assert str(clazz.p_layer).find('mapscript.layerObj') != -1 gc.collect() assert clazz.layer != None, clazz.layer
def testClassInsert(self): """classObj insert at end""" self.initMap() clazz = mapscript.classObj() clazz.minscaledenom = 666 assert clazz.refcount == 1, clazz.refcount idx = self.map.getLayer(1).insertClass(clazz) assert clazz.refcount == 2, clazz.refcount assert self.map.getLayer(1).getClass(idx).refcount == 3, self.map.getLayer(1).getClass(idx).refcount assert self.map.getLayer(1).getClass(idx).minscaledenom == 666, self.map.getLayer(1).getClass(idx).minscaledenom
def testLayerInsertClassAtZero(self): """insert class at index 0""" n = self.layer.numclasses new_class = mapscript.classObj() new_class.name = 'foo' new_index = self.layer.insertClass(new_class, 0) assert new_index == 0 assert self.layer.numclasses == n + 1 c = self.layer.getClass(new_index) assert c.thisown == 1 assert c.name == new_class.name
def testClassInsertAtMiddle(self): """classObj insert at pos. 1""" self.initMap() clazz = mapscript.classObj() clazz.minscaledenom = 666 assert clazz.refcount == 1, clazz.refcount idx = self.map.getLayer(1).insertClass(clazz, 1) assert idx == 1, idx assert clazz.refcount == 2, clazz.refcount assert self.map.getLayer(1).getClass(idx).refcount == 3, self.map.getLayer(1).getClass(idx).refcount assert self.map.getLayer(1).getClass(idx).thisown, self.map.getLayer(1).getClass(idx).thisown assert self.map.getLayer(1).getClass(idx).minscaledenom == 666, self.map.getLayer(1).getClass(idx).minscaledenom
def testClassInsert(self): """classObj insert at end""" self.initMap() clazz = mapscript.classObj() clazz.minscaledenom = 666 assert clazz.refcount == 1, clazz.refcount idx = self.map.getLayer(1).insertClass(clazz) assert clazz.refcount == 2, clazz.refcount assert self.map.getLayer(1).getClass( idx).refcount == 3, self.map.getLayer(1).getClass(idx).refcount assert self.map.getLayer(1).getClass( idx).minscaledenom == 666, self.map.getLayer(1).getClass( idx).minscaledenom
def testClassInsertAtMiddle(self): """classObj insert at pos. 1""" self.initMap() clazz = mapscript.classObj() clazz.minscaledenom = 666 assert clazz.refcount == 1, clazz.refcount idx = self.map.getLayer(1).insertClass(clazz, 1) assert idx == 1, idx assert clazz.refcount == 2, clazz.refcount assert self.map.getLayer(1).getClass( idx).refcount == 3, self.map.getLayer(1).getClass(idx).refcount assert self.map.getLayer(1).getClass(idx).thisown, self.map.getLayer( 1).getClass(idx).thisown assert self.map.getLayer(1).getClass( idx).minscaledenom == 666, self.map.getLayer(1).getClass( idx).minscaledenom
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 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 testClassWithArgument(self): """classObj constructor with not null layer""" self.initMap() clazz = mapscript.classObj(self.map.getLayer(0)) assert clazz.refcount == 2, clazz.refcount
def testConstructorNoArg(self): c = mapscript.classObj() assert c.thisown == 1 assert c.layer == None assert c.numstyles == 0
l = m.getLayerByName('POLYGON') l.data = os.path.join(os.getcwd(), 'timing') # Save three map images to check afterwards img = m.draw() img.save('timing.png') shpfile = mapscript.shapefileObj('timing.shp') img = m.prepareImage() for i in range(shpfile.numshapes): s = shpfile.getShape(i) s.classindex = 0 s.draw(m, l, img) img.save('timing-shapes.png') class0 = mapscript.classObj(ilayer) class0.insertStyle(l.getClass(0).getStyle(0)) img = m.prepareImage() ilayer.draw(m, img) img.save('timing-inline.png') # ========================================================================= # Test 1A: Draw all shapes at once using map.draw() print "Test 1A: draw map, all shapes at once" s = """\ img = m.draw() """ t = timeit.Timer(stmt=s, setup='from __main__ import m') print "%.2f usec/pass" % (1000000 * t.timeit(number=100)/100)
def testDummyClass(self): """basic refcounting for classObj""" clazz = mapscript.classObj() assert clazz.refcount == 1, clazz.refcount