Exemple #1
0
def draw_map_wms(name, save=0):
    #print "making map in thread %s" % (name)
    mo = mapscript.mapObj(TESTMAPFILE)

    # WFS layer
    lo = mapscript.layerObj()
    lo.name = 'jpl_wms'
    lo.setProjection('+init=epsg:4326')
    lo.connectiontype = mapscript.MS_WMS
    #    lo.connection = 'http://wms.jpl.nasa.gov/wms.cgi?'
    lo.connection = 'http://labs.metacarta.com/wms/vmap0?'
    lo.metadata.set('wms_service', 'WMS')
    lo.metadata.set('wms_server_version', '1.1.1')
    lo.metadata.set('wms_name', 'basic')
    lo.metadata.set('wms_style', 'visual')
    lo.metadata.set('wms_format', 'image/jpeg')
    lo.type = mapscript.MS_LAYER_RASTER
    lo.status = mapscript.MS_DEFAULT
    lo.debug = mapscript.MS_ON
    mo.insertLayer(lo)

    if not mo.web.imagepath:
        mo.web.imagepath = os.environ.get('TEMP', None) or INCOMING
    mo.debug = mapscript.MS_ON
    mo.selectOutputFormat('image/jpeg')
    im = mo.draw()
    if save:
        im.save('threadtest_wms_%s.jpg' % (name))
Exemple #2
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
Exemple #3
0
 def testLayerObj(self):
 	self.initMap()
 	layer = mapscript.layerObj(self.map)
 	self.map=None
 	assert str(layer.p_map).find('mapscript.mapObj') != -1
 	gc.collect()
 	assert layer.map != None, layer.map
Exemple #4
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
Exemple #5
0
def draw_map_wms(name, save=0):
    #print "making map in thread %s" % (name)
    mo = mapscript.mapObj(TESTMAPFILE)
     
    # WFS layer
    lo = mapscript.layerObj()
    lo.name = 'jpl_wms'
    lo.setProjection('+init=epsg:4326')
    lo.connectiontype = mapscript.MS_WMS
#    lo.connection = 'http://wms.jpl.nasa.gov/wms.cgi?'
    lo.connection = 'http://labs.metacarta.com/wms/vmap0?'
    lo.metadata.set('wms_service', 'WMS')
    lo.metadata.set('wms_server_version', '1.1.1')
    lo.metadata.set('wms_name', 'basic')
    lo.metadata.set('wms_style', 'visual')
    lo.metadata.set('wms_format', 'image/jpeg')
    lo.type = mapscript.MS_LAYER_RASTER
    lo.status = mapscript.MS_DEFAULT
    lo.debug = mapscript.MS_ON
    mo.insertLayer(lo)

    if not mo.web.imagepath:
        mo.web.imagepath = os.environ.get('TEMP', None) or INCOMING
    mo.debug = mapscript.MS_ON
    mo.selectOutputFormat('image/jpeg')
    im = mo.draw()
    if save:
        im.save('threadtest_wms_%s.jpg' % (name))
Exemple #6
0
 def testLayerObj(self):
     self.initMap()
     layer = mapscript.layerObj(self.map)
     self.map = None
     assert str(layer.p_map).find('mapscript.mapObj') != -1
     gc.collect()
     assert layer.map != None, layer.map
Exemple #7
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)
Exemple #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)
    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")
Exemple #10
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')
Exemple #11
0
    def testLayerConstructorNoArg(self):
        """test layer constructor with no argument"""
        layer = mapscript.layerObj()
        t = type(layer)
        assert str(t) == "<class 'mapscript.layerObj'>", t
        assert layer.thisown == 1
        assert layer.index == -1
	assert layer.map == None, layer.map
Exemple #12
0
    def testLayerConstructorMapArg(self):
        """test layer constructor with map argument"""
        layer = mapscript.layerObj(self.map)
        t = type(layer)
        assert str(t) == "<class 'mapscript.layerObj'>", t
        assert layer.thisown == 1
        assert str(layer) == str(self.map.getLayer(self.map.numlayers-1))
	assert layer.map != None, layer.map
Exemple #13
0
 def testLayerConstructorNoArg(self):
     """test layer constructor with no argument"""
     layer = mapscript.layerObj()
     t = type(layer)
     assert str(t) == "<class 'mapscript.layerObj'>", t
     assert layer.thisown == 1
     assert layer.index == -1
     assert layer.map == None, layer.map
Exemple #14
0
 def testLayerConstructorMapArg(self):
     """test layer constructor with map argument"""
     layer = mapscript.layerObj(self.map)
     t = type(layer)
     assert str(t) == "<class 'mapscript.layerObj'>", t
     assert layer.thisown == 1
     assert str(layer) == str(self.map.getLayer(self.map.numlayers - 1))
     assert layer.map != None, layer.map
Exemple #15
0
 def testLayerConstructorMapArg(self):
     """test layer constructor with map argument"""
     layer = mapscript.layerObj(self.map)
     t = type(layer)
     assert str(t) == "<class 'mapscript.layerObj'>", t
     assert layer.thisown == 1
     l = self.map.getLayer(self.map.numlayers - 1)
     # assert str(layer) == str(l) # TODO - check why these are not equal
     assert layer.map != None, layer.map
Exemple #16
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
Exemple #17
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
Exemple #18
0
 def setUp(self):
     self.mo = mapscript.mapObj()
     lo = mapscript.layerObj()
     lo.name = 'pg_sub_layer'
     lo.type = mapscript.MS_LAYER_POLYGON
     lo.connectiontype = mapscript.MS_POSTGIS
     lo.connection = PG_CONNECTION_STRING
     lo.data = "the_geom from (select * from polygon) as foo using unique gid using srid=4326"
     li = self.mo.insertLayer(lo)
     self.lo = self.mo.getLayer(li)
Exemple #19
0
    def testLayerClone(self):
        """Clone a layer"""
        layer = mapscript.layerObj()
        layer.name = "sample"
        copy = layer.clone()

        assert layer.refcount == 1, layer.refcount
        assert copy.refcount == 1, copy.refcount
        assert layer.name == copy.name
        assert copy.map == None
Exemple #20
0
 def setUp(self):
     self.mo = mapscript.mapObj()
     lo = mapscript.layerObj()
     lo.name = 'pg_sub_layer'
     lo.type = mapscript.MS_LAYER_POLYGON
     lo.connectiontype = mapscript.MS_POSTGIS
     lo.connection = PG_CONNECTION_STRING
     lo.data = "the_geom from (select * from polygon) as foo using unique gid using srid=4326"
     li = self.mo.insertLayer(lo)
     self.lo = self.mo.getLayer(li)
Exemple #21
0
 def setUp(self):
     self.mo = mapscript.mapObj()
     lo = mapscript.layerObj()
     lo.name = 'pg_layer'
     lo.type = mapscript.MS_LAYER_POLYGON
     lo.connectiontype = mapscript.MS_POSTGIS
     lo.connection = PG_CONNECTION_STRING
     lo.data = "the_geom from polygon"
     li = self.mo.insertLayer(lo)
     self.lo = self.mo.getLayer(li)
Exemple #22
0
 def setUp(self):
     self.mo = mapscript.mapObj()
     lo = mapscript.layerObj()
     lo.name = 'pg_layer'
     lo.type = mapscript.MS_LAYER_POLYGON
     lo.connectiontype = mapscript.MS_POSTGIS
     lo.connection = PG_CONNECTION_STRING
     lo.data = "the_geom from polygon"
     li = self.mo.insertLayer(lo)
     self.lo = self.mo.getLayer(li)
Exemple #23
0
    def testLayerClone(self):
        """Clone a layer"""
        layer = mapscript.layerObj()
        layer.name = 'sample'
        copy = layer.clone()

        assert layer.refcount == 1, layer.refcount
        assert copy.refcount == 1, copy.refcount
        assert layer.name == copy.name
        assert copy.map == None
Exemple #24
0
 def testMapInsertLayerDrawingOrder(self):
     """MapLayersTestCase.testMapInsertLayerDrawingOrder: test affect of insertion of a new layer at index 1 on drawing order"""
     n = self.map.numlayers
     # reverse layer drawing order
     o_start = (6, 5, 4, 3, 2, 1, 0)
     self.map.setLayerOrder(o_start)
     # insert Layer
     layer = mapscript.layerObj()
     layer.name = 'new'
     index = self.map.insertLayer(layer, 1)
     assert index == 1, index 
     # We expect our new layer to be at index 1 in drawing order as well
     order = self.map.getLayerOrder()
     assert order == (7, 1, 6, 5, 4, 3, 2, 0), order
Exemple #25
0
    def testMapInsertLayer(self):
        """MapLayersTestCase.testMapInsertLayer: test insertion of a new layer at default (last) index"""
        n = self.map.numlayers
        layer = mapscript.layerObj()
        layer.name = 'new'
	assert layer.map == None, layer.map
        index = self.map.insertLayer(layer)
	assert layer.map != None, layer.map
        assert index == n, index
        assert self.map.numlayers == n + 1
        names = [self.map.getLayer(i).name for i in range(self.map.numlayers)]
        assert names == ['RASTER', 'POLYGON', 'LINE', 'POINT', 'INLINE', 
                         'INLINE-PIXMAP-RGBA', 'INLINE-PIXMAP-PCT', 'new']
        order = self.map.getLayerOrder()
        assert order == (0, 1, 2, 3, 4, 5, 6, 7), order
Exemple #26
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')
Exemple #27
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')
Exemple #28
0
    def testMapInsertedLayer(self):
        """MapLayersTestCase.testMapInsertedLayer: test insertion of a new layer at default (last) index"""
	self.initMap()
        n = self.map.numlayers
        layer = mapscript.layerObj()
        layer.name = 'new'
	assert layer.refcount == 1
	assert layer.thisown == 1
        index = self.map.insertLayer(layer)
        assert index == n, index
        assert self.map.numlayers == n + 1
	assert layer.refcount == 2
	assert layer.thisown == 1
        assert self.map.getLayer(index).refcount == 3
	assert self.map.getLayer(index).thisown == 1
	assert layer.refcount == 2 
	assert layer.thisown == 1
Exemple #29
0
 def testMapInsertedLayerWithIndex(self):
     """MapLayersTestCase.testMapInsertedLayerWithIndex: test insertion of a new layer at index 0"""
     self.initMap()
     n = self.map.numlayers
     layer = mapscript.layerObj()
     layer.name = 'new'
     assert layer.refcount == 1
     assert layer.thisown == 1
     index = self.map.insertLayer(layer, 0)
     assert index == 0, index
     assert self.map.numlayers == n + 1
     assert layer.refcount == 2
     assert layer.thisown == 1
     assert self.map.getLayer(index).refcount == 3
     assert self.map.getLayer(index).thisown == 1
     assert layer.refcount == 2
     assert layer.thisown == 1
Exemple #30
0
 def testMapInsertedLayerWithIndex(self):
     """MapLayersTestCase.testMapInsertedLayerWithIndex: test insertion of a new layer at index 0"""
     self.initMap()
     n = self.map.numlayers
     layer = mapscript.layerObj()
     layer.name = "new"
     assert layer.refcount == 1
     assert layer.thisown == 1
     index = self.map.insertLayer(layer, 0)
     assert index == 0, index
     assert self.map.numlayers == n + 1
     assert layer.refcount == 2
     assert layer.thisown == 1
     assert self.map.getLayer(index).refcount == 3
     assert self.map.getLayer(index).thisown == 1
     assert layer.refcount == 2
     assert layer.thisown == 1
Exemple #31
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))
Exemple #32
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))
Exemple #33
0
 def testBehaveWhenParentIsNull(self):
     """behave when parent (map) is null"""
     self.initMap()
     layer = mapscript.layerObj()
     layer.name = "new"
     index = self.map.insertLayer(layer, 0)
     assert index == 0, index
     self.map = None
     assert layer.map != None, layer.map
     exception = None
     try:
         layer.open()
     except:
         # must fail because the new layer is missing information
         assert True
         exception = True
     if not exception:
         fail
Exemple #34
0
 def testBehaveWhenParentIsNull(self):
     """behave when parent (map) is null"""
     self.initMap()
     layer = mapscript.layerObj()
     layer.name = 'new'
     index = self.map.insertLayer(layer, 0)
     assert index == 0, index
     self.map = None
     assert layer.map != None, layer.map
     exception = None
     try:
         layer.open()
     except:
         # must fail because the new layer is missing information
         assert True
         exception = True
     if not exception:
         fail
Exemple #35
0
 def testLayerConstructorOwnership(self):
     """LayerTestCase.testLayerConstructorOwnership: newly constructed layer has proper ownership"""
     layer = mapscript.layerObj(self.map)
     assert layer.thisown == 1
Exemple #36
0
# Get Number of shapes from the command line
try:
    opts, args = getopt.getopt(sys.argv[1:], 'n:')
except getopt.GetoptError:
    sys.exit(2)

numshapes = 100 # default to 100
for o, a in opts:
    if o == '-n':
        numshapes = int(a)

# The shapefileObj
shpfile = mapscript.shapefileObj('timing.shp', mapscript.MS_SHAPEFILE_POLYGON)

# Inline feature layer
ilayer = mapscript.layerObj()
ilayer.type = mapscript.MS_LAYER_POLYGON
ilayer.setProjection('init=epsg:4326')
ilayer.status = mapscript.MS_DEFAULT
ilayer.connectiontype = mapscript.MS_INLINE

print numshapes, "shapes"

i = 0
while i < numshapes:
    # 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()
Exemple #37
0
 def testMapInsertLayerBadIndex(self):
     """MapLayersTestCase.testMapInsertLayerBadIndex: expect an exception when index is too large"""
     layer = mapscript.layerObj()
     self.assertRaises(mapscript.MapServerChildError, self.map.insertLayer, 
                       layer, 1000)
Exemple #38
0
 def testLayerConstructorOwnership(self):
     """LayerTestCase.testLayerConstructorOwnership: newly constructed layer has proper ownership"""
     layer = mapscript.layerObj(self.map)
     assert layer.thisown == 1
Exemple #39
0
 def testBehaveWhenParentIsNotNull(self):
     """behave when parent (map) is not null"""
     self.initMap()
     layer = mapscript.layerObj(self.map)
     layer.name = 'new'
     assert layer.refcount == 2, layer.refcount
Exemple #40
0
 def testBehaveWhenParentIsNotNull(self):
     """behave when parent (map) is not null"""
     self.initMap()
     layer = mapscript.layerObj(self.map)
     layer.name = "new"
     assert layer.refcount == 2, layer.refcount