-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmapfile.html
More file actions
394 lines (351 loc) · 30.1 KB
/
mapfile.html
File metadata and controls
394 lines (351 loc) · 30.1 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<!DOCTYPE html>
<html lang="en" 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>Mapfile Manipulation — 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=9a6d5eae"></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>
<link rel="icon" href="../_static/mapserver.ico"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="Querying" href="querying.html" />
<link rel="prev" title="MapScript Image Generation" href="imagery.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;">
<img src="../_static/flagicons/en.png" alt="en" title="en" border="0" width="18px" height="13px"/>
<a href="../ar/mapscript/mapfile.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../de/mapscript/mapfile.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../el/mapscript/mapfile.html"><img src="../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../es/mapscript/mapfile.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../fr/mapscript/mapfile.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../id/mapscript/mapfile.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../it/mapscript/mapfile.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../ja/mapscript/mapfile.html"><img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../nl_NL/mapscript/mapfile.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../pl/mapscript/mapfile.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../ru/mapscript/mapfile.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../sq/mapscript/mapfile.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../tr/mapscript/mapfile.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>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="querying.html" title="Querying"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="imagery.html" title="MapScript Image Generation"
accesskey="P">previous</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="">Mapfile Manipulation</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<span class="target" id="index-0"></span><section id="mapfile-manipulation">
<h1><a class="toc-backref" href="#contents" role="doc-backlink">Mapfile Manipulation</a><a class="headerlink" href="#mapfile-manipulation" 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>2026-03-29</p>
</dd>
</dl>
<nav class="contents" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#mapfile-manipulation" id="id1">Mapfile Manipulation</a></p>
<ul>
<li><p><a class="reference internal" href="#introduction" id="id2">Introduction</a></p></li>
<li><p><a class="reference internal" href="#mapfile-overview" id="id3">Mapfile Overview</a></p></li>
<li><p><a class="reference internal" href="#the-mapobj-class" id="id4">The mapObj Class</a></p></li>
<li><p><a class="reference internal" href="#children-of-mapobj" id="id5">Children of mapObj</a></p></li>
<li><p><a class="reference internal" href="#metadata" id="id6">Metadata</a></p></li>
</ul>
</li>
</ul>
</nav>
<section id="introduction">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>The MapScript HowTo docs are intended to complement the API reference with
examples of usage for specific subjects. All examples in this document refer
to the Mapfile and testing layers distributed with MapServer and found in source control
under <code class="docutils literal notranslate"><span class="pre">Mapserver/tests</span></code>.</p>
<p>The examples below are written in Python. All MapScript languages use the
same API, but will need to be rewritten using the relevant language’s syntax.</p>
</section>
<section id="mapfile-overview">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Mapfile Overview</a><a class="headerlink" href="#mapfile-overview" title="Link to this heading">¶</a></h2>
<p>By “Mapfile” here, I mean all the elements that can occur in (nearly)
arbitrary numbers within a MapScript mapObj: Layers, Classes, and Styles.</p>
</section>
<section id="the-mapobj-class">
<span id="index-1"></span><h2><a class="toc-backref" href="#contents" role="doc-backlink">The mapObj Class</a><a class="headerlink" href="#the-mapobj-class" title="Link to this heading">¶</a></h2>
<p>An instance of <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> is a parent for zero to many <a class="reference internal" href="mapscript-api/stub/mapscript.layerObj.html#mapscript.layerObj" title="mapscript.layerObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">layerObj</span></code></a> children.</p>
<section id="new-instances">
<h3>New instances<a class="headerlink" href="#new-instances" title="Link to this heading">¶</a></h3>
<p>The mapfile path argument to the <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> constructor is optional. The following
generates a default mapObj with no layers.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">empty_map</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">mapObj</span><span class="p">()</span>
</pre></div>
</div>
<p>A <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> is initialized from a Mapfile on disk in the usual manner:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">test_map</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="s1">'tests/test.map'</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note" id="index-2">
<p class="admonition-title">Note</p>
<p>If you receive the following error <code class="docutils literal notranslate"><span class="pre">msProcessProjection():</span> <span class="pre">Projection</span> <span class="pre">library</span> <span class="pre">error.</span>
<span class="pre">proj</span> <span class="pre">error</span> <span class="pre">"No</span> <span class="pre">such</span> <span class="pre">file</span> <span class="pre">or</span> <span class="pre">directory"</span> <span class="pre">for</span> <span class="pre">"init=epsg:4326"</span></code> then make sure you have
set the <code class="docutils literal notranslate"><span class="pre">PROJ_DATA</span></code> environment variable correctly</p>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Since the PROJ 9.1 release, the former <cite>PROJ_LIB</cite> variable has
been replaced with <cite>PROJ_DATA</cite></p>
</div>
</section>
<section id="cloning">
<h3>Cloning<a class="headerlink" href="#cloning" title="Link to this heading">¶</a></h3>
<p>An independent copy, less result and label caches, of a <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> can be produced
by the <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj.clone" title="mapscript.mapObj.clone"><code class="xref py py-func docutils literal notranslate"><span class="pre">mapObj.clone()</span></code></a> method:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">clone_map</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>the Java MapScript module implements a “cloneMap” method to avoid
conflict with the clone method of Java’s Object class.</p>
</div>
</section>
<section id="saving">
<span id="index-3"></span><h3>Saving<a class="headerlink" href="#saving" title="Link to this heading">¶</a></h3>
<p>A <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> can be saved to disk using the save method:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">clone_map</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'clone.map'</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>
<section id="children-of-mapobj">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Children of mapObj</a><a class="headerlink" href="#children-of-mapobj" title="Link to this heading">¶</a></h2>
<p>There is a common parent/child object API for Layers, Classes, and Styles in MapServer.</p>
<section id="referencing-a-child">
<h3>Referencing a Child<a class="headerlink" href="#referencing-a-child" title="Link to this heading">¶</a></h3>
<p>References to Layer, Class, and Style children are obtained by “getChild”-like
methods of their parent:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
<span class="n">layer_i</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayer</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="n">class_ij</span> <span class="o">=</span> <span class="n">layer_i</span><span class="o">.</span><span class="n">getClass</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>
<span class="n">style_ijk</span> <span class="o">=</span> <span class="n">class_ij</span><span class="o">.</span><span class="n">getStyle</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
<p>These references are for convenience only. MapScript doesn’t have any
reference counting, and you are certain to run into trouble if you try to use
these references after the parent <a class="reference internal" href="mapscript-api/stub/mapscript.mapObj.html#mapscript.mapObj" title="mapscript.mapObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">mapObj</span></code></a> has been deleted and freed from
memory.</p>
</section>
<section id="cloning-a-child">
<span id="index-4"></span><h3>Cloning a Child<a class="headerlink" href="#cloning-a-child" title="Link to this heading">¶</a></h3>
<p>A completely independent Layer, Class, or Style can be created using the clone
methods of <a class="reference internal" href="mapscript-api/stub/mapscript.layerObj.html#mapscript.layerObj" title="mapscript.layerObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">layerObj</span></code></a>, <a class="reference internal" href="mapscript-api/stub/mapscript.classObj.html#mapscript.classObj" title="mapscript.classObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">classObj</span></code></a>, and <a class="reference internal" href="mapscript-api/stub/mapscript.styleObj.html#mapscript.styleObj" title="mapscript.styleObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">styleObj</span></code></a>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">clone_layer</span> <span class="o">=</span> <span class="n">layer_i</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
</pre></div>
</div>
<p>This instance has no parent, and is self-owned.</p>
</section>
<section id="new-children">
<h3>New Children<a class="headerlink" href="#new-children" title="Link to this heading">¶</a></h3>
<p>Uninitialized instances of <a class="reference internal" href="mapscript-api/stub/mapscript.layerObj.html#mapscript.layerObj" title="mapscript.layerObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">layerObj</span></code></a>, <a class="reference internal" href="mapscript-api/stub/mapscript.classObj.html#mapscript.classObj" title="mapscript.classObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">classObj</span></code></a>, and
<a class="reference internal" href="mapscript-api/stub/mapscript.styleObj.html#mapscript.styleObj" title="mapscript.styleObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">styleObj</span></code></a> can be created with the new constructors:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">new_layer</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">layerObj</span><span class="p">()</span>
<span class="n">new_class</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">classObj</span><span class="p">()</span>
<span class="n">new_style</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">styleObj</span><span class="p">()</span>
</pre></div>
</div>
<p>They are added to a parent object using “insertChild”-like methods of the
parent which returns the index at which the child was inserted:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">li</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">insertLayer</span><span class="p">(</span><span class="n">new_layer</span><span class="p">)</span>
<span class="n">ci</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayer</span><span class="p">(</span><span class="n">li</span><span class="p">)</span><span class="o">.</span><span class="n">insertClass</span><span class="p">(</span><span class="n">new_class</span><span class="p">)</span>
<span class="n">si</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayer</span><span class="p">(</span><span class="n">li</span><span class="p">)</span><span class="o">.</span><span class="n">getClass</span><span class="p">(</span><span class="n">ci</span><span class="p">)</span><span class="o">.</span><span class="n">insertStyle</span><span class="p">(</span><span class="n">new_style</span><span class="p">)</span>
</pre></div>
</div>
<p>The insert* methods create a completely new copy of the object and stores it
in the parent with all ownership taken on by the parent. See the <a class="reference internal" href="mapscript-api/index.html#swig"><span class="std std-ref">SWIG API</span></a>
reference for more details.</p>
</section>
<section id="backwards-compatibility">
<h3>Backwards Compatibility<a class="headerlink" href="#backwards-compatibility" title="Link to this heading">¶</a></h3>
<p>The old style child object constructors with the parent object as a single
argument remain in MapServer:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">new_layer</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">layerObj</span><span class="p">(</span><span class="n">test_map</span><span class="p">)</span>
<span class="n">new_class</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">classObj</span><span class="p">(</span><span class="n">new_layer</span><span class="p">)</span>
<span class="n">new_style</span> <span class="o">=</span> <span class="n">mapscript</span><span class="o">.</span><span class="n">styleObj</span><span class="p">(</span><span class="n">new_class</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="removing-children">
<h3>Removing Children<a class="headerlink" href="#removing-children" title="Link to this heading">¶</a></h3>
<p>Child objects can be removed with “removeChild”-like methods of parents, which
return independent copies of the removed object:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># following from the insertion example ...</span>
<span class="c1"># remove the inserted style, returns a copy of the original new_style</span>
<span class="n">removed_style</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayer</span><span class="p">(</span><span class="n">li</span><span class="p">)</span><span class="o">.</span><span class="n">getClass</span><span class="p">(</span><span class="n">ci</span><span class="p">)</span><span class="o">.</span><span class="n">removeStyle</span><span class="p">(</span><span class="n">si</span><span class="p">)</span>
<span class="n">removed_class</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayer</span><span class="p">(</span><span class="n">li</span><span class="p">)</span><span class="o">.</span><span class="n">removeClass</span><span class="p">(</span><span class="n">ci</span><span class="p">)</span>
<span class="n">removed_layer</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">removeLayer</span><span class="p">(</span><span class="n">li</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>
<section id="metadata">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Metadata</a><a class="headerlink" href="#metadata" title="Link to this heading">¶</a></h2>
<p>Map, Layer, and Class metadata are the other arbitrarily numbered elements
(well, up to the built-in limit of 41) of a mapfile.</p>
<p>The metadata attributes of <a class="reference internal" href="mapscript-api/stub/mapscript.webObj.html#mapscript.webObj" title="mapscript.webObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">webObj</span></code></a>, <a class="reference internal" href="mapscript-api/stub/mapscript.layerObj.html#mapscript.layerObj" title="mapscript.layerObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">layerObj</span></code></a>, and <a class="reference internal" href="mapscript-api/stub/mapscript.classObj.html#mapscript.classObj" title="mapscript.classObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">classObj</span></code></a>
are instances of <a class="reference internal" href="mapscript-api/stub/mapscript.hashTableObj.html#mapscript.hashTableObj" title="mapscript.hashTableObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">hashTableObj</span></code></a>, a class which functions like a limited dictionary:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">layer</span> <span class="o">=</span> <span class="n">test_map</span><span class="o">.</span><span class="n">getLayerByName</span><span class="p">(</span><span class="s1">'POLYGON'</span><span class="p">)</span>
<span class="n">layer</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s1">'wms_name'</span><span class="p">,</span> <span class="s1">'foo'</span><span class="p">)</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">layer</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'wms_name'</span><span class="p">)</span> <span class="c1"># returns 'foo'</span>
</pre></div>
</div>
<p>You can iterate over all keys in a class:<cite>hashTableObj</cite> as follows:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">key</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">while</span> <span class="p">(</span><span class="mi">1</span><span class="p">):</span>
<span class="n">key</span> <span class="o">=</span> <span class="n">layer</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">nextKey</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">layer</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
</pre></div>
</div>
<p>Note in Python the <a class="reference internal" href="mapscript-api/stub/mapscript.hashTableObj.html#mapscript.hashTableObj" title="mapscript.hashTableObj"><code class="xref py py-class docutils literal notranslate"><span class="pre">hashTableObj</span></code></a> can be treated as a dictionary. See <a class="reference internal" href="python.html#python"><span class="std std-ref">Python MapScript Appendix</span></a>.</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">Quick search</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="Go" />
</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="#">Mapfile Manipulation</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#mapfile-overview">Mapfile Overview</a></li>
<li><a class="reference internal" href="#the-mapobj-class">The mapObj Class</a><ul>
<li><a class="reference internal" href="#new-instances">New instances</a></li>
<li><a class="reference internal" href="#cloning">Cloning</a></li>
<li><a class="reference internal" href="#saving">Saving</a></li>
</ul>
</li>
<li><a class="reference internal" href="#children-of-mapobj">Children of mapObj</a><ul>
<li><a class="reference internal" href="#referencing-a-child">Referencing a Child</a></li>
<li><a class="reference internal" href="#cloning-a-child">Cloning a Child</a></li>
<li><a class="reference internal" href="#new-children">New Children</a></li>
<li><a class="reference internal" href="#backwards-compatibility">Backwards Compatibility</a></li>
<li><a class="reference internal" href="#removing-children">Removing Children</a></li>
</ul>
</li>
<li><a class="reference internal" href="#metadata">Metadata</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="querying.html" title="Querying"
>next</a> |</li>
<li class="right" >
<a href="imagery.html" title="MapScript Image Generation"
>previous</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="">Mapfile Manipulation</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">Copyright</a> 2026, Open Source Geospatial Foundation.
Last updated on 2026-04-20.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>