示例#1
0
 def testZoomRectangle(self):
     """ZoomRectangleTestCase.testZoomRectangle: zooming to an extent returns proper map extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     r = mapscript.rectObj(1, 26, 26, 1, 1)
     extent = self.mapobj1.extent
     self.mapobj1.zoomRectangle(r, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-49,24,-24,49))
示例#2
0
 def testReBindingExtent(self):
     """test the rebinding of a map's extent"""
     test_map = mapscript.mapObj(TESTMAPFILE)
     rect1 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     rect2 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     test_map.extent = rect1
     assert repr(test_map.extent) != repr(rect1), (test_map.extent, rect1)
     del rect1
     self.assertRectsEqual(test_map.extent, rect2)
示例#3
0
 def testZoomRectangleConstrained(self):
     """ZoomRectangleTestCase.testZoomRectangleConstrained: zooming to a constrained extent returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     max = mapscript.rectObj(-100.0, -100.0, 100.0, 100.0)
     r = mapscript.rectObj(0, 200, 200, 0, 1)
     extent = self.mapobj1.extent
     self.mapobj1.zoomRectangle(r, w, h, extent, max)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, max)
示例#4
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')
示例#5
0
 def testDirectExtentAccess(self):
     """direct access to a layer's extent works properly"""
     pt_layer = self.map.getLayerByName('POINT')
     rect = pt_layer.extent
     assert str(pt_layer.extent) == str(rect), (pt_layer.extent, rect)
     e = mapscript.rectObj(-0.5, 51.0, 0.5, 52.0)
     self.assertRectsEqual(e, rect)
示例#6
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)
示例#7
0
 def testRectObjConstructorArgs(self):
     """a rect can be initialized with arguments"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 4.0)
示例#8
0
 def testRectObjConstructorNoArgs(self):
     """a rect can be initialized with no args"""
     r = mapscript.rectObj()
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -1.0)
     self.assertAlmostEqual(r.maxx, -1.0)
     self.assertAlmostEqual(r.maxy, -1.0)
示例#9
0
 def testRectObjConstructorArgs(self):
     """create a rect in image units"""
     r = mapscript.rectObj(-1.0, 2.0, 3.0, 0.0, mapscript.MS_TRUE)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, 2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 0.0)
示例#10
0
 def testZoomRectangleBadly(self):
     """zooming into an invalid extent raises proper error"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     r = mapscript.rectObj(0, 0, 200, 200)
     extent = self.mapobj1.extent
     self.assertRaises(mapscript.MapServerError, 
         self.mapobj1.zoomRectangle, r, w, h, extent, None)
示例#11
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")
示例#12
0
 def testDirectExtentAccess(self):
     """direct access to a layer's extent works properly"""
     pt_layer = self.map.getLayerByName('POINT')
     rect = pt_layer.extent
     assert str(pt_layer.extent) == str(rect), (pt_layer.extent, rect)
     e = mapscript.rectObj(-0.5, 51.0, 0.5, 52.0)
     self.assertRectsEqual(e, rect)
示例#13
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)
示例#14
0
 def testZoomInPoint(self):
     """ZoomPointTestCase.testZoomInPoint: zooming in by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
示例#15
0
 def testRecenter(self):
     """ZoomPointTestCase.testRecenter: recentering the map with a point returns the same extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(1, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
示例#16
0
 def testGetPresetExtent(self):
     """test layer.setExtent() and layer.getExtent() to return preset instead of calculating extents"""
     r = mapscript.rectObj(1.0, 1.0, 3.0, 3.0)
     self.layer.setExtent(r.minx, r.miny, r.maxx, r.maxy)
     rect = self.layer.extent
     assert r.minx == rect.minx, rect
     assert r.miny == rect.miny, rect.miny
     assert r.maxx == rect.maxx, rect.maxx
     assert r.maxy == rect.maxy, rect.maxy
示例#17
0
 def testZoomOutPoint(self):
     """ZoomPointTestCase.testZoomOutPoint: zooming out by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
示例#18
0
 def testGetPresetExtent(self):
     """test layer.setExtent() and layer.getExtent() to return preset instead of calculating extents"""
     r = mapscript.rectObj(1.0, 1.0, 3.0, 3.0)
     self.layer.setExtent(r.minx, r.miny, r.maxx, r.maxy)
     rect = self.layer.extent
     assert r.minx == rect.minx, rect
     assert r.miny == rect.miny, rect.miny
     assert r.maxx == rect.maxx, rect.maxx
     assert r.maxy == rect.maxy, rect.maxy
示例#19
0
 def testRectObjToPolygon(self):
     """a rect can be converted into a MS_POLYGON shape"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     s = r.toPolygon()
     assert s.numlines == 1, s.numlines
     line = self.getLineFromShape(s, 0)
     assert line.numpoints == 5, line.numpoints
     point = self.getPointFromLine(line, 0)
     self.assertAlmostEqual(point.x, -1.0)
     self.assertAlmostEqual(point.y, -2.0)
示例#20
0
 def xtestRecenter(self):
     """ZoomScaleTestCase.testRecenter: recentering map returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 2834.6472
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50,-50,50,50))
示例#21
0
 def xtestZoomInScale(self):
     """ZoomScaleTestCase.testZoomInScale: zooming in to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 1417.3236
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25,-25,25,25))
示例#22
0
 def testRect__str__(self):
     """__str__ returns properly formatted string"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0001, 4.0)
     r_str = str(r)
     assert r_str == "{ 'minx': -1 , 'miny': -2 , 'maxx': 3.0001 , 'maxy': 4 }", r_str
     r2 = eval(r_str)
     self.assertAlmostEqual(r2['minx'], r.minx)
     self.assertAlmostEqual(r2['miny'], r.miny)
     self.assertAlmostEqual(r2['maxx'], r.maxx)
     self.assertAlmostEqual(r2['maxy'], r.maxy)
示例#23
0
 def xtestZoomOutScale(self):
     """ZoomScaleTestCase.testZoomOutScale: zooming out to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 5669.2944
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-100,-100,100,100))
示例#24
0
 def testZoomOutPointConstrained(self):
     """ZoomPointTestCase.testZoomOutPointConstrained: zooming out to a constrained extent returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     max = mapscript.rectObj()
     max.minx, max.miny, max.maxx, max.maxy = (-100.0,-100.0,100.0,100.0)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-4, p, w, h, extent, max)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, max)
示例#25
0
 def testRectQueryNoResults(self):
     qrect = mapscript.rectObj(-101.0, 0.0, -100.0, 1.0)
     self.layer.queryByRect(self.map, qrect)
     assert self.layer.getNumResults() == 0
示例#26
0
 def testRectQueryNoResults(self):
     qrect = mapscript.rectObj(-101.0, 0.0, -100.0, 1.0)
     self.layer.queryByRect(self.map, qrect)
     assert self.layer.getNumResults() == 0
示例#27
0
 def testRectQuery(self):
     qrect = mapscript.rectObj(-10.0, 45.0, 10.0, 55.0)
     self.layer.queryByRect(self.map, qrect)
     assert self.layer.getNumResults() == 1
示例#28
0
 def testRectContainsPointNot(self):
     """point is not contained (spatially) in rectangle"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     p = mapscript.pointObj(3.00001, 0.0)
     assert p not in r, (p.x, p.y, r)
示例#29
0
 def testRectToString(self):
     """return properly formatted string"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0001, 4.0)
     r_str = r.toString()
     assert r_str == "{ 'minx': -1 , 'miny': -2 , 'maxx': 3.0001 , 'maxy': 4 }", r_str
示例#30
0
 def testPolygonGetExtent(self):
     """retrieve the extent of a polygon layer"""
     e = mapscript.rectObj(-0.25, 51.227222, 0.25, 51.727222)
     self.assertRectsEqual(e, self.layer.getExtent())
示例#31
0
 def testShapeQueryNoResults(self):
     qrect = mapscript.rectObj(-101.0, 0.0, -100.0, 1.0)
     qshape = qrect.toPolygon()
     self.layer.queryByShape(self.map, qshape)
     assert self.layer.getNumResults() == 0
示例#32
0
 def testPolygonExtent(self):
     """retrieve the extent of a polygon layer"""
     e = mapscript.rectObj()
     self.assertRectsEqual(e, self.layer.extent)
示例#33
0
 def testExceptionMessage(self):
     """test formatted error message"""
     try:
         r = mapscript.rectObj(1.0, -2.0, -3.0, 4.0)
     except mapscript.MapServerError, msg:
         assert str(msg) == "rectObj(): Invalid rectangle. { 'minx': 1.000000 , 'miny': -2.000000 , 'maxx': -3.000000 , 'maxy': 4.000000 }", msg
示例#34
0
 def testPolygonGetExtent(self):
     """retrieve the extent of a polygon layer"""
     e = mapscript.rectObj(-0.25, 51.227222, 0.25, 51.727222)
     self.assertRectsEqual(e, self.layer.getExtent())
示例#35
0
 def testResetLayerExtent(self):
     """test resetting a layer's extent"""
     layer = self.map.getLayerByName('POLYGON')
     layer.setExtent()
     self.assertRectsEqual(layer.extent, mapscript.rectObj())
示例#36
0
 def testRectQuery(self):
     qrect = mapscript.rectObj(-10.0, 45.0, 10.0, 55.0)
     self.layer.queryByRect(self.map, qrect)
     assert self.layer.getNumResults() == 1
示例#37
0
 def testShapeQueryNoResults(self):
     qrect = mapscript.rectObj(-101.0, 0.0, -100.0, 1.0)
     qshape = qrect.toPolygon()
     self.layer.queryByShape(self.map, qshape)
     assert self.layer.getNumResults() == 0
示例#38
0
 def testResetLayerExtent(self):
     """test resetting a layer's extent"""
     layer = self.map.getLayerByName('POLYGON')
     layer.setExtent()
     self.assertRectsEqual(layer.extent, mapscript.rectObj())
示例#39
0
 def testPolygonExtent(self):
     """retrieve the extent of a polygon layer"""
     e = mapscript.rectObj()
     self.assertRectsEqual(e, self.layer.extent)
示例#40
0
# 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()

    # Add to shapefile
    shpfile.add(s)

    # Add to inline feature layer
    ilayer.addFeature(s)
    
    i = i + 1

del shpfile # closes up the file

# Prepare the testing fixture
m = mapscript.mapObj('timing.map')
l = m.getLayerByName('POLYGON')