python mapscript附录¶
- 作者
肖恩吉利斯
- 作者
赛斯·吉文
- 联系
Sethg在gegraph ika.co.uk网站上
- 最后更新
2021-05-24
介绍¶
python mapscript模块包含一些尚未为其他语言实现的类扩展方法。
Classes¶
随着文档的增长,将在此处添加对以下部分的引用。
图像对象¶
Pillow(是Python图像库的一个分支),https://pillow.readthedocs.io/,是图像处理不可或缺的工具。的扩展 imageObj
都是为了更好地将Pillow集成到MapScrip应用程序中。
ImageObj扩展方法¶
imageObj.write()
将图像数据写入类似-1f25 Python-1文件的对象。默认设置为stdout。
url = urllib.urlopen('https://mapserver.org/_static/banner.png')
ms_image = imageObj(url, 'AGG/JPEG')
看见 MapScript图像生成 了解更多的例子。
彭波托基¶
PointObj方法¶
- α-Struth*()一串
返回格式为的字符串
{ 'x': %f , 'y': %f, 'z': %f }
适当替换坐标值。使用实例:
>>> p = mapscript.pointObj(1, 1, 1) >>> str(p) { 'x': 1 , 'y': 1, 'z': 1 }
请注意,返回值可以方便地转换为python字典:
>>> p_dict = eval(str(p)) >>> p_dict['x'] 1
雷克托布杰¶
ReCbTJ方法¶
- _包含点obj point布尔
返回true point 在矩形内,否则返回false。
>>> r = mapscript.rectObj(0, 0, 1, 1) >>> p = mapscript.pointObj(2, 0) # outside >>> p in r False >>> p not in r True
- α-Struth*()一串
返回格式为的字符串
{ 'minx': %f , 'miny': %f , 'maxx': %f , 'maxy': %f }
适当替换边界值。使用实例:
>>> r = mapscript.rectObj(0, 0, 1, 1) >>> str(r) { 'minx': 0 , 'miny': 0 , 'maxx': 1 , 'maxy': 1 }
请注意,返回值可以方便地转换为python字典:
>>> r_dict = eval(str(r)) >>> r_dict['minx'] 0
异常处理¶
Python MapScript模块将几个MapServer错误映射到Python异常。例如,尝试加载不存在的映射文件会引发‘ioerror’
>>> import mapscript
>>> mapfile = '/no/such/file.map'
>>> m = mapscript.mapObj(mapfile)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/site-packages/mapscript.py", line 799, in __init__
newobj = _mapscript.new_mapObj(*args)
IOError: msLoadMap(): Unable to access file. (/no/such/file.map)
>>>
错误消息是由“mssterror”编写的,CGI MapServ用户在错误日志中看到的消息也是如此。