-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython.html
More file actions
370 lines (302 loc) · 21.5 KB
/
python.html
File metadata and controls
370 lines (302 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<!DOCTYPE html>
<html lang="ja" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Python MapScript Appendix — MapServer 8.6.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx.css?v=48f05237" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx_collapse.css?v=226d88b4" />
<link rel="stylesheet" type="text/css" href="../_static/custom.css?v=dd298242" />
<link rel="stylesheet" type="text/css" href="../_static/ribbon.css?v=ea091bf4" />
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=0377e500"></script>
<script src="../_static/doctools.js?v=fd6eb6e6"></script>
<script src="../_static/sphinx_highlight.js?v=6ffebe34"></script>
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../_static/copybutton.js?v=f281be69"></script>
<script src="../_static/translations.js?v=4755f45a"></script>
<link rel="icon" href="../_static/mapserver.ico"/>
<link rel="author" title="このドキュメントについて" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="検索" href="../search.html" />
<link rel="copyright" title="著作権" href="../copyright.html" />
<link rel="next" title="MapScript Image Generation" href="imagery.html" />
<link rel="prev" title="By Example" href="php/by_example.html" />
</head><body>
<!-- for main branch only, do not backport this -->
<table width="100%" style="width: 100%; background-color: white;">
<tr>
<td rowspan="2" style="padding: 10px 0px 10px 10px;">
<a href="../index.html" title="Home"><img src="../_static/banner.png" alt="MapServer banner" border="0" /></a>
</td>
<td style="padding: 10px 10px 0px 0px; text-align: right; vertical-align: top;">
<a href="../index.html" title="Home">Home</a> |
<a href="../products.html" title="Products (MapServer core, MapCache, TinyOWS">Products</a> |
<a href="https://github.com/mapserver/mapserver/issues/" title="Issue Tracker (MapServer core)">Issue Tracker</a> |
<a href="../community/service_providers.html" title="Professional Service Providers">Service Providers</a> |
<a href="../faq.html" title="Frequently Asked Questions">FAQ</a> |
<a href="https://fosstodon.org/@mapserver" title="Mastodon" target="_blank">Mastodon</a> |
<a href="../download.html" title="Download Source or Binaries">Download </a> |
<a class="badge" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KRJ2X44N3HA6U&source=url" target="_blank">
<img src="https://img.shields.io/badge/donate-%E2%9D%A4%C2%A0-ff69b4.svg?style=flat" alt="Donate to MapServer">
</a>
</td>
</tr>
<tr>
<td style="padding: 0px 10px 0px 0px; text-align: right; vertical-align: bottom;">
<a href="../../mapscript/python.html"><img src="../_static/flagicons/en.png" alt="en" title="en" border="0" /></a>
<a href="../../ar/mapscript/python.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../../de/mapscript/python.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../../el/mapscript/python.html"><img src="../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../../es/mapscript/python.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../../fr/mapscript/python.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../../id/mapscript/python.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../../it/mapscript/python.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" width="18px" height="13px"/>
<a href="../../nl_NL/mapscript/python.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../../pl/mapscript/python.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../../ru/mapscript/python.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../../sq/mapscript/python.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../../tr/mapscript/python.html"><img src="../_static/flagicons/tr.png" alt="tr" title="tr" border="0" /></a>
</td>
</tr>
</table>
<div class="related" role="navigation" aria-label="Related">
<h3>ナビゲーション</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="総合索引"
accesskey="I">索引</a></li>
<li class="right" >
<a href="imagery.html" title="MapScript Image Generation"
accesskey="N">次へ</a> |</li>
<li class="right" >
<a href="php/by_example.html" title="By Example"
accesskey="P">前へ</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.2 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" accesskey="U">MapScript</a> »</li>
<li class="nav-item nav-item-this"><a href="">Python MapScript Appendix</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="python-mapscript-appendix">
<span id="python"></span><h1><a class="toc-backref" href="#id1" role="doc-backlink">Python MapScript Appendix</a><a class="headerlink" href="#python-mapscript-appendix" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Sean Gillies</p>
</dd>
<dt class="field-even">Author<span class="colon">:</span></dt>
<dd class="field-even"><p>Seth Girvin</p>
</dd>
<dt class="field-odd">Contact<span class="colon">:</span></dt>
<dd class="field-odd"><p>sethg at geographika.co.uk</p>
</dd>
<dt class="field-even">Last Updated<span class="colon">:</span></dt>
<dd class="field-even"><p>2021-05-24</p>
</dd>
</dl>
<nav class="contents" id="id1">
<p class="topic-title">目次</p>
<ul class="simple">
<li><p><a class="reference internal" href="#python-mapscript-appendix" id="id2">Python MapScript Appendix</a></p>
<ul>
<li><p><a class="reference internal" href="#introduction" id="id3">Introduction</a></p></li>
<li><p><a class="reference internal" href="#classes" id="id4">Classes</a></p></li>
<li><p><a class="reference internal" href="#exception-handling" id="id5">Exception Handling</a></p></li>
</ul>
</li>
</ul>
</nav>
<section id="introduction">
<span id="index-0"></span><h2><a class="toc-backref" href="#id1" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>The Python MapScript module contains some class extension methods that have
not yet been implemented for other languages.</p>
</section>
<section id="classes">
<span id="index-1"></span><h2><a class="toc-backref" href="#id1" role="doc-backlink">Classes</a><a class="headerlink" href="#classes" title="Link to this heading">¶</a></h2>
<p>References to sections below will be added here as the documentation grows.</p>
<section id="imageobj">
<span id="index-2"></span><h3>imageObj<a class="headerlink" href="#imageobj" title="Link to this heading">¶</a></h3>
<p>Pillow (a fork of the Python Imaging Library), <a class="reference external" href="https://pillow.readthedocs.io/">https://pillow.readthedocs.io/</a>, is an
indispensable tool for image manipulation. The extensions to <code class="xref py py-class docutils literal notranslate"><span class="pre">imageObj</span></code> are
all geared towards better integration of Pillow in MapScript applications.</p>
<section id="imageobj-extended-methods">
<h4>imageObj Extended Methods<a class="headerlink" href="#imageobj-extended-methods" title="Link to this heading">¶</a></h4>
<ul class="simple">
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">imageObj.write()</span></code> - write image data to a Python file-like object. Default is stdout.</p></li>
</ul>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">url</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s1">'https://mapserver.org/_static/banner.png'</span><span class="p">)</span>
<span class="n">ms_image</span> <span class="o">=</span> <span class="n">imageObj</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="s1">'AGG/JPEG'</span><span class="p">)</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="imagery.html#ms-imagery"><span class="std std-ref">MapScript Image Generation</span></a> for further examples.</p>
</section>
</section>
<section id="pointobj">
<span id="index-3"></span><h3>pointObj<a class="headerlink" href="#pointobj" title="Link to this heading">¶</a></h3>
<section id="pointobj-methods">
<h4>pointObj Methods<a class="headerlink" href="#pointobj-methods" title="Link to this heading">¶</a></h4>
<dl>
<dt>__str__()<span class="classifier">string</span></dt><dd><p>Return a string formatted like</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s1">'x'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">,</span> <span class="s1">'y'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span><span class="p">,</span> <span class="s1">'z'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">}</span>
</pre></div>
</div>
<p>with the coordinate values substituted appropriately. Usage example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">pointObj</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">{ 'x': 1 , 'y': 1, 'z': 1 }</span>
</pre></div>
</div>
<p>Note that the return value can be conveniently eval'd into a Python
dictionary:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">p_dict</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">p_dict</span><span class="p">[</span><span class="s1">'x'</span><span class="p">]</span>
<span class="go">1</span>
</pre></div>
</div>
</dd>
</dl>
</section>
</section>
<section id="rectobj">
<span id="index-4"></span><h3>rectObj<a class="headerlink" href="#rectobj" title="Link to this heading">¶</a></h3>
<section id="rectobj-methods">
<h4>rectObj Methods<a class="headerlink" href="#rectobj-methods" title="Link to this heading">¶</a></h4>
<dl>
<dt>__contains__( pointObj point )<span class="classifier">boolean</span></dt><dd><p>Returns True if <em>point</em> is inside the rectangle, otherwise returns False.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">rectObj</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">pointObj</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># outside</span>
<span class="gp">>>> </span><span class="n">p</span> <span class="ow">in</span> <span class="n">r</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="n">p</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">r</span>
<span class="go">True</span>
</pre></div>
</div>
</dd>
<dt>__str__()<span class="classifier">string</span></dt><dd><p>Return a string formatted like</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s1">'minx'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">,</span> <span class="s1">'miny'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">,</span> <span class="s1">'maxx'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">,</span> <span class="s1">'maxy'</span><span class="p">:</span> <span class="o">%</span><span class="n">f</span> <span class="p">}</span>
</pre></div>
</div>
<p>with the bounding values substituted appropriately. Usage example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">rectObj</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="go">{ 'minx': 0 , 'miny': 0 , 'maxx': 1 , 'maxy': 1 }</span>
</pre></div>
</div>
<p>Note that the return value can be conveniently eval'd into a Python
dictionary:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">r_dict</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">r</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">r_dict</span><span class="p">[</span><span class="s1">'minx'</span><span class="p">]</span>
<span class="go">0</span>
</pre></div>
</div>
</dd>
</dl>
</section>
</section>
</section>
<section id="exception-handling">
<span id="index-5"></span><h2><a class="toc-backref" href="#id1" role="doc-backlink">Exception Handling</a><a class="headerlink" href="#exception-handling" title="Link to this heading">¶</a></h2>
<p>The Python MapScript module maps a few MapServer errors into Python exceptions.
Attempting to load a non-existent mapfile raises an 'IOError', for example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">mapscript</span>
<span class="gp">>>> </span><span class="n">mapfile</span> <span class="o">=</span> <span class="s1">'/no/such/file.map'</span>
<span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">mapObj</span><span class="p">(</span><span class="n">mapfile</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n">?</span>
File <span class="nb">"/usr/lib/python2.3/site-packages/mapscript.py"</span>, line <span class="m">799</span>, in <span class="n">__init__</span>
<span class="w"> </span><span class="n">newobj</span> <span class="o">=</span> <span class="n">_mapscript</span><span class="o">.</span><span class="n">new_mapObj</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
<span class="gr">IOError</span>: <span class="n">msLoadMap(): Unable to access file. (/no/such/file.map)</span>
<span class="gp">>>></span>
</pre></div>
</div>
<p>The message of the error is written by 'msSetError' and so is the same message that
CGI mapserv users see in error logs.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">クイック検索</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="検索" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script><h3>Navigation</h3>
<p>
<a href="../about.html" title="About">About</a><br>
<a href="../products.html" title="Products">Products</a><br>
<a href="../community/index.html" title="Community">Community</a><br>
<a href="../development/index.html" title="Development">Development</a><br>
<a href="../download.html" title="Downloads">Downloads</a><br>
<a href="../documentation.html" title="Documentation">Documentation</a><br>
<a href="../faq.html" title="FAQ">FAQ</a><br>
<a href="../psc.html" title="PSC">PSC</a><br>
<a href="https://fosstodon.org/@mapserver" title="Mastodon">Mastodon</a>
</p>
<h3>Current Table Of Contents</h3>
<ul>
<li><a class="reference internal" href="#">Python MapScript Appendix</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#classes">Classes</a><ul>
<li><a class="reference internal" href="#imageobj">imageObj</a><ul>
<li><a class="reference internal" href="#imageobj-extended-methods">imageObj Extended Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pointobj">pointObj</a><ul>
<li><a class="reference internal" href="#pointobj-methods">pointObj Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#rectobj">rectObj</a><ul>
<li><a class="reference internal" href="#rectobj-methods">rectObj Methods</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#exception-handling">Exception Handling</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>ナビゲーション</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="総合索引"
>索引</a></li>
<li class="right" >
<a href="imagery.html" title="MapScript Image Generation"
>次へ</a> |</li>
<li class="right" >
<a href="php/by_example.html" title="By Example"
>前へ</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Home</a> »</li>
<li class="nav-item nav-item-1"><a href="../documentation.html" >MapServer 8.6.2 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" >MapScript</a> »</li>
<li class="nav-item nav-item-this"><a href="">Python MapScript Appendix</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">著作権</a> 2026, Open Source Geospatial Foundation.
最終更新: 2026-04-20
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>