def testMap(self): """ReferenceCountingTestCase.testMap: test map constructor with no argument""" test_map = mapscript.mapObj() maptype = type(test_map) assert str(maptype) == "<class 'mapscript.mapObj'>", maptype assert test_map.thisown == 1 assert test_map.refcount == 1
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))
def testSetExtent(self): """MapExtentTestCase.testSetExtent: test the setting of a mapObj's extent""" test_map = mapscript.mapObj(TESTMAPFILE) e = test_map.extent result = test_map.setExtent(e.minx, e.miny, e.maxx, e.maxy) self.assertAlmostEqual(test_map.scaledenom, 14.24445829) assert result == mapscript.MS_SUCCESS, result
def testMapWithDefaultMap(self): """ReferenceCountingTestCase.testTestMap: test map constructor with default map file""" test_map = mapscript.mapObj(TESTMAPFILE) maptype = type(test_map) assert str(maptype) == "<class 'mapscript.mapObj'>", maptype assert test_map.thisown == 1 assert test_map.refcount == 1 assert test_map.getLayer(0).refcount == 2
def testExternalClassification(self): mo = mapscript.mapObj() mo.setSize(400, 400) mo.setExtent(-2.5, -2.5, 2.5, 2.5) mo.selectOutputFormat('image/png') mo.insertLayer(self.ilayer) im = mo.draw() im.save('testExternalClassification.png')
def trigger_exception(name): #print "triggering exception in thread %s" % (name) mo = mapscript.mapObj(TESTMAPFILE) try: mo.setExtent(1, 50, -1, 51) raise Exception, "We expected a MapServer exception" except mapscript.MapServerError: pass
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)
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)
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)
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 testNoGetFontSetFile(self): """an empty map should have fontset filename == None""" self.map = mapscript.mapObj() assert self.map.fontset.filename == None
# reloading the mapfile each time print "Test 1A: reloading maps from mapfile" s = """\ m = mapscript.mapObj(TESTMAPFILE) """ t = timeit.Timer(stmt=s, setup='from __main__ import mapscript, TESTMAPFILE') print "%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100) # =========================================================================== # Test 1B: Cloning # # Cloning instead of reloading print "Test 1B: cloning maps instead of reloading" m = mapscript.mapObj(TESTMAPFILE) s = """\ c = m.clone() """ t = timeit.Timer(stmt=s, setup='from __main__ import m') print "%.2f usec/pass" % (1000000 * t.timeit(number=100) / 100) # =========================================================================== # Test 2: Add 20 dups of the POLYGON layer to see how results scale timing_map = mapscript.mapObj(TESTMAPFILE) polygon_layer = timing_map.getLayerByName('POLYGON') # duplicate POLYGON layer 20 times for i in range(20): timing_map.insertLayer(polygon_layer)
def draw_map(name, save=0): #print "making map in thread %s" % (name) mo = mapscript.mapObj(TESTMAPFILE) im = mo.draw() if save: im.save('threadtest_%s.png' % (name))
def initMap(self): self.map = mapscript.mapObj(TESTMAPFILE)
# reloading the mapfile each time print "Test 1A: reloading maps from mapfile" s = """\ m = mapscript.mapObj(TESTMAPFILE) """ t = timeit.Timer(stmt=s, setup='from __main__ import mapscript, TESTMAPFILE') print "%.2f usec/pass" % (1000000 * t.timeit(number=100)/100) # =========================================================================== # Test 1B: Cloning # # Cloning instead of reloading print "Test 1B: cloning maps instead of reloading" m = mapscript.mapObj(TESTMAPFILE) s = """\ c = m.clone() """ t = timeit.Timer(stmt=s, setup='from __main__ import m') print "%.2f usec/pass" % (1000000 * t.timeit(number=100)/100) # =========================================================================== # Test 2: Add 20 dups of the POLYGON layer to see how results scale timing_map = mapscript.mapObj(TESTMAPFILE) polygon_layer = timing_map.getLayerByName('POLYGON') # duplicate POLYGON layer 20 times for i in range(20): timing_map.insertLayer(polygon_layer)
def setUp(self): self.map = mapscript.mapObj('')
def setUp(self): self.mapobj_orig = mapscript.mapObj(TESTMAPFILE) self.mapobj_clone = self.mapobj_orig.clone()
def testSetExtentBadly(self): """MapExtentTestCase.testSetExtentBadly: test that mapscript raises an error for an invalid mapObj extent""" test_map = mapscript.mapObj(TESTMAPFILE) self.assertRaises(mapscript.MapServerError, test_map.setExtent, 1.0, -2.0, -3.0, 4.0)
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') 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')
def testMapConstructorFilenameArg(self): """MapConstructorTestCasetest.testMapConstructorEmptyStringArg: map constructor with filename argument""" test_map = mapscript.mapObj(TESTMAPFILE) maptype = type(test_map) assert str(maptype) == "<class 'mapscript.mapObj'>", maptype assert test_map.thisown == 1
def testMapConstructorEmptyStringArg(self): """MapConstructorTestCase.testMapConstructorEmptyStringArg: test map constructor with old-style empty string argument""" test_map = mapscript.mapObj('') maptype = type(test_map) assert str(maptype) == "<class 'mapscript.mapObj'>", maptype assert test_map.thisown == 1
def testMapConstructorNoArg(self): """MapConstructorTestCase.testMapConstructorNoArg: test map constructor with no argument""" test_map = mapscript.mapObj() maptype = type(test_map) assert str(maptype) == "<class 'mapscript.mapObj'>", maptype assert test_map.thisown == 1