Ejemplo n.º 1
0
 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
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
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")
Ejemplo n.º 7
0
 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')
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
 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
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
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')
Ejemplo n.º 18
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')
Ejemplo n.º 19
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))
Ejemplo n.º 20
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))
Ejemplo n.º 21
0
 def testClassWithArgument(self):
     """classObj constructor with not null layer"""
     self.initMap()
     clazz = mapscript.classObj(self.map.getLayer(0))
     assert clazz.refcount == 2, clazz.refcount
Ejemplo n.º 22
0
 def testConstructorNoArg(self):
     c = mapscript.classObj()
     assert c.thisown == 1
     assert c.layer == None
     assert c.numstyles == 0
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
 def testDummyClass(self):
     """basic refcounting for classObj"""
     clazz = mapscript.classObj()
     assert clazz.refcount == 1, clazz.refcount
Ejemplo n.º 25
0
 def testClassWithArgument(self):
     """classObj constructor with not null layer"""
     self.initMap()
     clazz = mapscript.classObj(self.map.getLayer(0))
     assert clazz.refcount == 2, clazz.refcount
Ejemplo n.º 26
0
 def testDummyClass(self):
     """basic refcounting for classObj"""
     clazz = mapscript.classObj()
     assert clazz.refcount == 1, clazz.refcount
Ejemplo n.º 27
0
 def testConstructorNoArg(self):
     c = mapscript.classObj()
     assert c.thisown == 1
     assert c.layer == None 
     assert c.numstyles == 0