【发布时间】:2015-04-21 13:27:28
【问题描述】:
我在 Windows 7 上使用 pycharm (python) (和 mapnik),我只是想测试安装后是否一切就绪。我在这里使用了网上的一个例子,我有一个框架错误。会不会是安装问题?编译器??我对python很陌生。提前感谢您的宝贵时间。
"""
This is a simple wxPython application demonstrates how to
integrate mapnik, it do nothing but draw the map from the World Poplulation XML
example:
https://github.com/mapnik/mapnik/wiki/GettingStartedInXML
Victor Lin. (bornstub@gmail.com)
Blog http://blog.ez2learn.com
"""
import mapnik
import wx
class Frame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, size=(800, 500) ,*args, **kwargs)
self.Bind(wx.EVT_PAINT, self.onPaint)
self.mapfile = "population.xml"
self.width = 800
self.height = 500
self.createMap()
self.drawBmp()
def createMap(self):
"""Create mapnik object
"""
self.map = mapnik.Map(self.width, self.height)
mapnik.load_map(self.map, self.mapfile)
bbox = mapnik.Envelope(mapnik.Coord(-180.0, -75.0), mapnik.Coord(180.0, 90.0))
self.map.zoom_to_box(bbox)
def drawBmp(self):
"""Draw map to Bitmap object
"""
# create a Image32 object
image = mapnik.Image(self.width, self.height)
# render map to Image32 object
mapnik.render(self.map, image)
# load raw data from Image32 to bitmap
self.bmp = wx.BitmapFromBufferRGBA(self.width, self.height, image.tostring())
def onPaint(self, event):
dc = wx.PaintDC(self)
memoryDC = wx.MemoryDC(self.bmp)
# draw map to dc
dc.Blit(0, 0, self.width, self.height, memoryDC, 0, 0)
if __name__ == '__main__':
app = wx.App()
frame = frame(None, title="wxPython Mapnik Demo")
frame.Show()
app.MainLoop()
这里是错误信息:
Traceback (most recent call last):
File "C:/Python27/example.py", line 16, in <module>
class Frame(wx.Frame):
File "C:/Python27/example.py", line 56, in Frame
frame = frame(None, title="wxPython Mapnik Demo")
NameError: name 'frame' is not defined
Process finished with exit code 1
【问题讨论】:
-
您正在调用一个名为
frame的函数。frame未定义。你期待它吗? (也许你的意思是Frame?)Python 是一种区分大小写的语言,就像大多数语言一样。 -
哪个框架?节目里有很多
-
您创建了一个名为
Frame的类,它是wx.Frame的子类。然后你尝试实例化它,但你拼错了。
标签: python wxpython pycharm mapnik