⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawshapes.py

📁 Welcome to MS4W, the no fuss installer for setting up MapServer on Microsoft Windows platforms. The
💻 PY
字号:
# $Id: drawshapes.py,v 1.3 2004/12/07 21:33:28 sean Exp $## Timing tests of feature drawing -- map.draw vs drawing features# shape by shape.import getoptimport osimport sysimport timeitfrom random import randomfrom testing import mapscript# Get Number of shapes from the command linetry:    opts, args = getopt.getopt(sys.argv[1:], 'n:')except getopt.GetoptError:    sys.exit(2)numshapes = 100 # default to 100for o, a in opts:    if o == '-n':        numshapes = int(a)# The shapefileObjshpfile = mapscript.shapefileObj('timing.shp', mapscript.MS_SHAPEFILE_POLYGON)# Inline feature layerilayer = mapscript.layerObj()ilayer.type = mapscript.MS_LAYER_POLYGONilayer.setProjection('init=epsg:4326')ilayer.status = mapscript.MS_DEFAULTilayer.connectiontype = mapscript.MS_INLINEprint numshapes, "shapes"i = 0while 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 + 1del shpfile # closes up the file# Prepare the testing fixturem = mapscript.mapObj('timing.map')l = m.getLayerByName('POLYGON')l.data = os.path.join(os.getcwd(), 'timing')# Save three map images to check afterwardsimg = 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)# =========================================================================# Test 1B: Draw shape by shape from the shapefileObjprint "Test 1B: draw shapes one at a time"s = """\img = m.prepareImage()for i in range(shpfile.numshapes):    s = shpfile.getShape(i)    s.classindex = 0    s.draw(m, l, img)"""t = timeit.Timer(stmt=s, setup='from __main__ import m, l, shpfile')print "%.2f usec/pass" % (1000000 * t.timeit(number=100)/100)# =========================================================================# Test 1C: Draw shapes after pushing them into an inline layerprint "Test 1C: draw inline layer shapes"s = """\img = m.prepareImage()ilayer.draw(m, img)"""t = timeit.Timer(stmt=s, setup='from __main__ import m, ilayer')print "%.2f usec/pass" % (1000000 * t.timeit(number=100)/100)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -