-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmapfile.html
More file actions
638 lines (594 loc) · 46.1 KB
/
mapfile.html
File metadata and controls
638 lines (594 loc) · 46.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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<!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 Tuning & Management — MapServer 8.6.1 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/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=ad95d4c4"></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="Raster Management & Optimization" href="raster.html" />
<link rel="prev" title="Limit Mapfile Access" href="limit_mapfile_access.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/optimization/mapfile.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../de/optimization/mapfile.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../el/optimization/mapfile.html"><img src="../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../es/optimization/mapfile.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../fr/optimization/mapfile.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../id/optimization/mapfile.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../it/optimization/mapfile.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../ja/optimization/mapfile.html"><img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../nl_NL/optimization/mapfile.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../pl/optimization/mapfile.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../ru/optimization/mapfile.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../sq/optimization/mapfile.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../tr/optimization/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="raster.html" title="Raster Management & Optimization"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="limit_mapfile_access.html" title="Limit Mapfile Access"
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.1 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Optimization</a> »</li>
<li class="nav-item nav-item-this"><a href="">Mapfile Tuning & Management</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="mapfile-tuning-management">
<span id="mapfile-tuning"></span><span id="index-0"></span><h1><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Mapfile Tuning & Management</a><a class="headerlink" href="#mapfile-tuning-management" 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>David Fawcett</p>
</dd>
<dt class="field-even">Contact<span class="colon">:</span></dt>
<dd class="field-even"><p>david.fawcett at gmail.com</p>
</dd>
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Jeff McKenna</p>
</dd>
<dt class="field-even">Contact<span class="colon">:</span></dt>
<dd class="field-even"><p>jmckenna at gatewaygeomatics.com</p>
</dd>
<dt class="field-odd">Last Updated<span class="colon">:</span></dt>
<dd class="field-odd"><p>2026-03-29</p>
</dd>
</dl>
<nav class="contents" id="table-of-contents">
<p class="topic-title">Table of Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#mapfile-tuning-management" id="id1">Mapfile Tuning & Management</a></p>
<ul>
<li><p><a class="reference internal" href="#introduction" id="id2">Introduction</a></p></li>
<li><p><a class="reference internal" href="#steps-to-possibly-review" id="id3">Steps to Possibly Review</a></p>
<ul>
<li><p><a class="reference internal" href="#use-a-mapserver-syntax-file-for-your-favorite-text-editor" id="id4">1. Use a MapServer Syntax file for your Favorite Text Editor</a></p></li>
<li><p><a class="reference internal" href="#testing-your-mapfile-for-speed" id="id5">2. Testing your Mapfile for Speed</a></p></li>
<li><p><a class="reference internal" href="#use-the-various-config-settings-for-debugging" id="id6">3. Use the various CONFIG settings for debugging</a></p></li>
<li><p><a class="reference internal" href="#test-the-full-map-request-through-the-mapserv-executable" id="id7">4. Test the full Map Request through the mapserv Executable</a></p></li>
<li><p><a class="reference internal" href="#projections" id="id8">5. Projections</a></p></li>
<li><p><a class="reference internal" href="#use-includes" id="id9">6. Use INCLUDEs</a></p></li>
<li><p><a class="reference internal" href="#layers" id="id10">7. Layers</a></p></li>
<li><p><a class="reference internal" href="#yes-data-formats-matter" id="id11">8. Yes Data Formats Matter</a></p></li>
<li><p><a class="reference internal" href="#enable-caching-through-mapcache" id="id12">9. Enable Caching through MapCache</a></p></li>
<li><p><a class="reference internal" href="#symbols" id="id13">10. Symbols</a></p></li>
<li><p><a class="reference internal" href="#fonts" id="id14">11. Fonts</a></p></li>
<li><p><a class="reference internal" href="#use-mapscript" id="id15">12. Use MapScript</a></p></li>
<li><p><a class="reference internal" href="#don-t-expose-your-map-path" id="id16">13. Don’t expose your MAP path</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<section id="introduction">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Introduction</a><a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>The contents of a .map file (‘mapfile’) are used by MapServer for configuration, data
access, projection, and more. Because the mapfile is parsed every time a map
image is requested, it is important to think about what you include in the
file in order to optimize performance. The optimal mapfile is one that
doesn’t include or reference anything that isn’t needed. The following steps will
help you both manage and optimize your mapfiles.</p>
<div class="admonition note" id="index-1">
<p class="admonition-title">Note</p>
<p>As you optimize your setup, it is strongly recommended to review the security steps
for the <em>MAP=</em> call to the MapServer executable, by setting <em>MS_MAP_PATTERN</em> or
<em>MS_MAP_NO_PATH</em> or hiding the <em>MAP=</em> parameter on public servers,
as recommended in the document <a class="reference internal" href="limit_mapfile_access.html#limit-mapfile-access"><span class="std std-ref">Limit Mapfile Access</span></a>. All possible
environment variables to secure your server are listed in <a class="reference internal" href="environment_variables.html#environment-variables"><span class="std std-ref">Environment Variables</span></a>.</p>
</div>
</section>
<section id="steps-to-possibly-review">
<h2><a class="toc-backref" href="#table-of-contents" role="doc-backlink">Steps to Possibly Review</a><a class="headerlink" href="#steps-to-possibly-review" title="Link to this heading">¶</a></h2>
<section id="use-a-mapserver-syntax-file-for-your-favorite-text-editor">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">1. Use a MapServer Syntax file for your Favorite Text Editor</a><a class="headerlink" href="#use-a-mapserver-syntax-file-for-your-favorite-text-editor" title="Link to this heading">¶</a></h3>
<p>Although it’s maybe not be classed as an ‘optimization’, using a syntax
file to add color-coding to MapServer mapfile parameters in your text editor,
can help save you time and make your MapServer-mapfile-management-life
much easier. You can find a helpful list of these syntax color-coding tools for
MapServer listed on the page at <a class="reference internal" href="../development/editing/index.html#editing"><span class="std std-ref">Mapfile Editing</span></a>.</p>
<img alt="../_images/mapfile-color-syntax.png" class="no-scaled-link" height="294" src="../_images/mapfile-color-syntax.png" width="500" />
</section>
<section id="testing-your-mapfile-for-speed">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">2. Testing your Mapfile for Speed</a><a class="headerlink" href="#testing-your-mapfile-for-speed" title="Link to this heading">¶</a></h3>
<p>If optimization and performance are important to you, then get to know and love
the MapServer commandline utility <a class="reference internal" href="../utilities/map2img.html#map2img"><span class="std std-ref">map2img</span></a>. <em>map2img</em> will verify that your
mapfile creates a valid map image, but it can also display draw times (length of
time it takes MapServer to process each layer and the final map image) with the
<em>-map_debug 3</em> setting:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">map2img</span> <span class="o">-</span><span class="n">m</span> <span class="n">osm</span><span class="o">.</span><span class="n">map</span> <span class="o">-</span><span class="n">o</span> <span class="n">ttt</span><span class="o">.</span><span class="n">png</span> <span class="o">-</span><span class="n">map_debug</span> <span class="mi">3</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">rendering</span> <span class="n">using</span> <span class="n">outputformat</span> <span class="n">named</span> <span class="n">png</span> <span class="p">(</span><span class="n">AGG</span><span class="o">/</span><span class="n">PNG</span><span class="p">)</span><span class="o">.</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">WMS</span><span class="o">/</span><span class="n">WFS</span> <span class="nb">set</span><span class="o">-</span><span class="n">up</span> <span class="ow">and</span> <span class="n">query</span><span class="p">,</span> <span class="mf">0.000</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">95</span> <span class="p">(</span><span class="n">land13</span><span class="p">),</span> <span class="mf">0.001</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">96</span> <span class="p">(</span><span class="n">landuse13</span><span class="p">),</span> <span class="mf">0.051</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">97</span> <span class="p">(</span><span class="n">transport_areas13</span><span class="p">),</span> <span class="mf">0.002</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">98</span> <span class="p">(</span><span class="n">waterarea13</span><span class="p">),</span> <span class="mf">0.003</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">99</span> <span class="p">(</span><span class="n">waterways13</span><span class="p">),</span> <span class="mf">0.002</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">100</span> <span class="p">(</span><span class="n">railways13</span><span class="p">),</span> <span class="mf">0.003</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">101</span> <span class="p">(</span><span class="n">roads13</span><span class="p">),</span> <span class="mf">0.024</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">102</span> <span class="p">(</span><span class="n">aeroways13</span><span class="p">),</span> <span class="mf">0.002</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">103</span> <span class="p">(</span><span class="n">buildings13</span><span class="p">),</span> <span class="mf">0.245</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">104</span> <span class="p">(</span><span class="n">borders13</span><span class="p">),</span> <span class="mf">0.197</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">105</span> <span class="p">(</span><span class="n">places13</span><span class="p">),</span> <span class="mf">0.078</span><span class="n">s</span>
<span class="n">msDrawLabelCache</span><span class="p">():</span> <span class="n">labelcache_map_edge_buffer</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Drawing</span> <span class="n">Label</span> <span class="n">Cache</span><span class="p">,</span> <span class="mf">0.020</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">()</span> <span class="n">total</span> <span class="n">time</span><span class="p">:</span> <span class="mf">0.772</span><span class="n">s</span>
<span class="n">msSaveImage</span><span class="p">(</span><span class="n">ttt</span><span class="o">.</span><span class="n">png</span><span class="p">)</span> <span class="n">total</span> <span class="n">time</span><span class="p">:</span> <span class="mf">0.056</span><span class="n">s</span>
</pre></div>
</div>
<p>The above example generates a map image in <em>0.772 seconds</em>.</p>
<p>Hint: If you want maximum (verbose) messages, try the <em>-all_debug 5</em> setting
instead.</p>
<p>You can also just get draw times for a single layer with the <em>-l layername</em> switch,
such as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">map2img</span> <span class="o">-</span><span class="n">m</span> <span class="n">osm</span><span class="o">.</span><span class="n">map</span> <span class="o">-</span><span class="n">o</span> <span class="n">ttt</span><span class="o">.</span><span class="n">png</span> <span class="o">-</span><span class="n">map_debug</span> <span class="mi">3</span> <span class="o">-</span><span class="n">l</span> <span class="n">buildings13</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">rendering</span> <span class="n">using</span> <span class="n">outputformat</span> <span class="n">named</span> <span class="n">png</span> <span class="p">(</span><span class="n">AGG</span><span class="o">/</span><span class="n">PNG</span><span class="p">)</span><span class="o">.</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">WMS</span><span class="o">/</span><span class="n">WFS</span> <span class="nb">set</span><span class="o">-</span><span class="n">up</span> <span class="ow">and</span> <span class="n">query</span><span class="p">,</span> <span class="mf">0.000</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Layer</span> <span class="mi">103</span> <span class="p">(</span><span class="n">buildings13</span><span class="p">),</span> <span class="mf">0.119</span><span class="n">s</span>
<span class="n">msDrawLabelCache</span><span class="p">():</span> <span class="n">labelcache_map_edge_buffer</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">msDrawMap</span><span class="p">():</span> <span class="n">Drawing</span> <span class="n">Label</span> <span class="n">Cache</span><span class="p">,</span> <span class="mf">0.001</span><span class="n">s</span>
<span class="n">msDrawMap</span><span class="p">()</span> <span class="n">total</span> <span class="n">time</span><span class="p">:</span> <span class="mf">0.120</span><span class="n">s</span>
<span class="n">msSaveImage</span><span class="p">(</span><span class="n">ttt</span><span class="o">.</span><span class="n">png</span><span class="p">)</span> <span class="n">total</span> <span class="n">time</span><span class="p">:</span> <span class="mf">0.016</span><span class="n">s</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><a class="reference internal" href="../utilities/map2img.html#map2img"><span class="std std-ref">map2img</span></a> should be included in your
MapServer installation (<a class="reference external" href="https://ms4w.com">MS4W</a> users
need to execute <em>setenv.bat</em> before using the utility).</p>
</div>
</section>
<section id="use-the-various-config-settings-for-debugging">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">3. Use the various CONFIG settings for debugging</a><a class="headerlink" href="#use-the-various-config-settings-for-debugging" title="Link to this heading">¶</a></h3>
<p>Review the <a class="reference internal" href="debugging.html#debugging"><span class="std std-ref">Debugging MapServer</span></a> document and try setting the CONFIG parameter
at the MAP-level in your mapfile, to hopefully get more information
from various sources such as from the PROJ library, GDAL library, etc.</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">MAP</span>
<span class="p">...</span>
<span class="k">CONFIG</span> <span class="s">"CPL_DEBUG"</span> <span class="s">"ON"</span>
<span class="k">CONFIG</span> <span class="s">"PROJ_DEBUG"</span> <span class="s">"ON"</span>
<span class="p">...</span>
<span class="k">LAYER</span>
<span class="p">...</span>
<span class="k">END</span>
<span class="k">END</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>You can set <em>“CPL_DEBUG” “PROJ”</em> to restrict the information returned to PROJ
(and not GDAL in general)</p>
</div>
</section>
<section id="test-the-full-map-request-through-the-mapserv-executable">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">4. Test the full Map Request through the mapserv Executable</a><a class="headerlink" href="#test-the-full-map-request-through-the-mapserv-executable" title="Link to this heading">¶</a></h3>
<p>There are times when your mapfile generates a valid map image with a local
map2img command, but then the same mapfile will cause an error in a map
request through the web server, such as Apache. It is these times when
you should try the same request, that was sent through your web server, at
the commandline with the actual <em>mapserv</em> (or on Windows, the <em>mapserv.exe</em>)
utility.</p>
<p>The following request will take a full <em>MAP=…&MODE=map</em> request, and try to save
the request to an image, or report an error:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapserv</span> <span class="o">-</span><span class="n">nh</span> <span class="s2">"QUERY_STRING=MAP=/ms4w/apps/local-demo/local.map&MODE=map"</span> <span class="o">></span> <span class="n">test</span><span class="o">.</span><span class="n">png</span>
</pre></div>
</div>
<p>You can use this to also test problematic WMS GetMap requests as well:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapserv</span> <span class="o">-</span><span class="n">nh</span> <span class="s2">"QUERY_STRING=SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=41.42710000000000292,-173.4329999999999927,83.74660000000000082,-13.04809999999999981&CRS=EPSG:4326&WIDTH=369&HEIGHT=98&LAYERS=park&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"</span> <span class="o">></span> <span class="n">test</span><span class="o">.</span><span class="n">png</span>
</pre></div>
</div>
<p><strong>Note:</strong> Besides checking your web server logs, you can also use QGIS to get the exact
request to your OWS (WMS/WFS etc.) service: see <a class="reference external" href="https://github.com/MapServer/MapServer/wiki/Get-the-Raw-WMS-Request-Generated-by-QGIS">https://github.com/MapServer/MapServer/wiki/Get-the-Raw-WMS-Request-Generated-by-QGIS</a></p>
<img alt="../_images/qgis-network-logger.png" class="no-scaled-link" height="207" src="../_images/qgis-network-logger.png" width="800" />
</section>
<section id="projections">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">5. Projections</a><a class="headerlink" href="#projections" title="Link to this heading">¶</a></h3>
<p>There are two ways to define projections in a mapfile. You can either use
inline projection parameters or specify an EPSG code for that projection. If
you use the <a class="reference internal" href="../glossary.html#term-EPSG"><span class="xref std std-term">EPSG</span></a> code method, <a class="reference internal" href="../glossary.html#term-PROJ"><span class="xref std std-term">PROJ</span></a> looks up the projection
parameters in the PROJ database using the EPSG code as an ID. This database
lookup takes significantly more resources than when the projection parameters
are defined inline. This lookup takes place for each projection definition
using EPSG codes in a mapfile.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../mapfile/projection.html#projection"><span class="std std-ref">PROJECTION</span></a></p>
</div>
<p><strong>Projection defined using inline projection parameters</strong></p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">PROJECTION</span>
<span class="s">"proj=utm"</span>
<span class="s">"ellps=GRS80"</span>
<span class="s">"datum=NAD83"</span>
<span class="s">"zone=15"</span>
<span class="s">"units=m"</span>
<span class="s">"north"</span>
<span class="s">"no_defs"</span>
<span class="k">END</span>
</pre></div>
</div>
<p><strong>Projection defined using EPSG Code</strong></p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">PROJECTION</span>
<span class="s">"init=epsg:26915"</span>
<span class="k">END</span>
</pre></div>
</div>
<p><strong>Optimization Suggestions</strong></p>
<ul>
<li><p>Use inline projection parameter definitions in place of EPSG codes.</p></li>
<li><p>It should be stated that for optimal performance you could have MapServer
not do any projections on-demand (in other words, have all of your source
data in the same projection, and have MapServer output requests in that
same projection) but obviously this is not always possible for all scenarios.</p></li>
<li><p>If you want to use EPSG codes, remove all unneeded projection definition
records from the PROJ <a class="reference internal" href="../glossary.html#term-EPSG"><span class="xref std std-term">EPSG</span></a> database.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This was a common trick for PROJ versions <6 (and its <em>epsg</em> file),
but for PROJ >= 6 a <em>proj.db</em> SQLite database is used to store
these EPSG lookup codes, and optimizations for that will take some
time to be developed and shared).</p>
</div>
</li>
</ul>
</section>
<section id="use-includes">
<span id="index-2"></span><h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">6. Use INCLUDEs</a><a class="headerlink" href="#use-includes" title="Link to this heading">¶</a></h3>
<p>Implemented back in MapServer 4.10, the mapfile <a class="reference internal" href="../mapfile/include.html#include"><span class="std std-ref">INCLUDE</span></a> parameter is
possibly one of the best ways to help manage your large mapfiles (you might
argue that this is not ‘optimization’ for speed again, but for it is very
important for managing large mapfiles with many layers).</p>
<p>Any part of the mapfile can be referenced through an INCLUDE, besides the
obvious layers.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Common file extensions for includes are: <em>.lyr</em>, <em>.include</em>, or even <em>.map</em>
. You can name them any file extension that you wish.</p>
</div>
<p>You could have something like:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">MAP</span>
<span class="p">...</span>
<span class="k">WEB</span>
<span class="k">INCLUDE</span> <span class="s">"metadata.include"</span>
<span class="k">END</span>
<span class="p">...</span>
<span class="k">INCLUDE</span> <span class="s">"elevation.lyr"</span>
<span class="k">INCLUDE</span> <span class="s">"country.lyr"</span>
<span class="k">INCLUDE</span> <span class="s">"city.lyr"</span>
<span class="p">...</span>
<span class="k">END</span>
</pre></div>
</div>
<p>Where <em>metadata.include</em> could contain:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">METADATA</span>
<span class="s">"wms_title"</span> <span class="s">"WMS Demo Server"</span> <span class="c">##required</span>
<span class="s">"wms_onlineresource"</span> <span class="s">"http://yourpath/cgi-bin/mapserv.exe?"</span> <span class="c">##required</span>
<span class="s">"wms_srs"</span> <span class="s">"EPSG:3857 EPSG:4326 EPSG:4269 EPSG:3978"</span> <span class="c">##recommended</span>
<span class="s">"wms_enable_request"</span> <span class="s">"*"</span> <span class="c">##necessary</span>
<span class="k">END</span>
</pre></div>
</div>
</section>
<section id="layers">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">7. Layers</a><a class="headerlink" href="#layers" title="Link to this heading">¶</a></h3>
<p>For every layer in a mapfile that has a status of ON or DEFAULT, MapServer
will load that layer and prepare it for display, even if that layer never gets
displayed.</p>
<p><strong>Optimization Suggestions</strong></p>
<ul class="simple">
<li><p>Build lean mapfiles, only include layers that you plan to use.</p></li>
<li><p>Turn off unnecessary layers; the more layers MapServer is displaying, the
more time it takes. Have your opening map view show only the minimum
necessary to orient the user, and allow them to turn on additional layers as
needed. This is particularly true of remote WMS or very large rasters.</p></li>
<li><p>Related to turning off layers, is turning them on but using MINSCALEDENOM
and MAXSCALEDENOM to determine at what zoomlevels the layer is available. If
a map’s display is outside of the layer’s MINSCALEDENOM and MAXSCALEDENOM
range, then MapServer can skip processing that layer. It also makes for a
really cool effect, that the national boundaries magically change to state
boundaries.</p></li>
<li><p>If you have a complex application, consider using multiple simple and
specific mapfiles in place of one large ‘do everything’ mapfile.</p></li>
<li><p>In a similar vein, each class also supports MINSCALEDENOM and MAXSCALEDENOM.
If your dataset has data that are relevant at different zoomlevels, then you
may find this a very handy trick. For example, give a MINSCALEDENOM of
1:1000000, county roads a MINSCALEDENOM of 1:100000, and streets a
MAXSCALEDENOM of 1:50000. You get the cool effect of new data magically
appearing, but you don’t have MapServer trying to draw the nation’s roads
when the entire nation is in view!</p></li>
<li><p>Classes are processed in order, and a feature is assigned to the first class
that matches. So try placing the most commonly-used classes at the top of
the class list, so MapServer doesn’t have to try as many classes before
finding a match. For example, if you wanted to highlight the single state of
Wyoming, you would probably do this:</p></li>
</ul>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">CLASS</span>
<span class="k">EXPRESSION</span> <span class="p">(</span><span class="s">'[NAME]'</span> <span class="ow">eq</span> <span class="s">'WY'</span><span class="p">])</span>
<span class="k">STYLE</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="k">END</span>
<span class="k">END</span>
<span class="k">CLASS</span>
<span class="k">STYLE</span>
<span class="k">COLOR</span> <span class="mi">128</span> <span class="mi">128</span> <span class="mi">128</span>
<span class="k">END</span>
<span class="k">END</span>
</pre></div>
</div>
<p>But it would be a lot more efficient to do this, since 98% of cases will be
matched on the first try:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">CLASS</span>
<span class="k">EXPRESSION</span> <span class="p">(</span><span class="s">'[NAME]'</span> <span class="ow">ne</span> <span class="s">'WY'</span><span class="p">])</span>
<span class="k">STYLE</span>
<span class="k">COLOR</span> <span class="mi">128</span> <span class="mi">128</span> <span class="mi">128</span>
<span class="k">END</span>
<span class="k">END</span>
<span class="k">CLASS</span>
<span class="k">STYLE</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="k">END</span>
<span class="k">END</span>
</pre></div>
</div>
<ul class="simple">
<li><p>Use <a class="reference internal" href="tileindex.html#tileindex"><span class="std std-ref">tile indexes</span></a> instead of multiple layers.</p></li>
</ul>
</section>
<section id="yes-data-formats-matter">
<span id="index-3"></span><h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">8. Yes Data Formats Matter</a><a class="headerlink" href="#yes-data-formats-matter" title="Link to this heading">¶</a></h3>
<p>This is often not written in documents, yet is often taught in hands-on
workshops (as maybe readers or developers can be reading the document here
and become offended if it differs in their thinking or the purpose of
their software design, as some formats may be deemed ‘uncool’ by some crowds,
but in reality, we don’t care about coolness here, we care about making MapServer
fast). So the following advice is by the authors of this
document (disclaimer), and may offend some readers, therefore ‘viewer discretion
is advised’.</p>
<p>Although MapServer can read any GDAL supported <a class="reference external" href="https://gdal.org/drivers/vector/index.html">vector</a>
or <a class="reference external" href="https://gdal.org/drivers/raster/index.html">raster</a> source (and the
fact that not all users will be setting up tile caching beforehand), the following
is still recommended for MapServer for optimal performance in terms of data formats.</p>
<p><strong>Optimization Suggestions</strong></p>
<ul class="simple">
<li><p>The best/optimal data sources for MapServer in terms of speed-of-display
is <a class="reference external" href="https://gdal.org/drivers/vector/shapefile.html#vector-shapefile">.shp</a>
(for vectors) and <a class="reference external" href="https://gdal.org/drivers/raster/gtiff.html">GeoTIFF</a>
(for rasters).</p></li>
<li><p>For databases, MapServer displays <a class="reference external" href="https://gdal.org/drivers/vector/pg.html">PostGIS</a>
layers very fast, and some custom tricks are included in the MapServer source
specifically for PostGIS + MapServer draw speed. PostGIS is therefore recommended.</p></li>
<li><p><a class="reference external" href="https://gdal.org/drivers/vector/sqlite.html">SpatiaLite</a> is recommended
for those who require a portable format, and works very well with MapServer.</p></li>
<li><p>For whatever formats you choose, definitely review the associated GDAL format
(driver) page for that specific format, and enable indexing (spatial or also attribute
indexing).</p></li>
<li><p>Rasters, and of course GeoTIFFs, should also have overviews included, through the
<a class="reference external" href="https://gdal.org/programs/gdaladdo.html">gdaladdo</a> utility.</p></li>
<li><p>Raster layers can also include various <a class="reference internal" href="../input/raster.html#raster-processing-directives"><span class="std std-ref">PROCESSING directives</span></a>,
specific to raster display in MapServer (such as displaying specific bands, or choosing a
resampling method, but for resampling do experiment with the fastest display option
versus display quality).</p></li>
<li><p>If you do use .shp files (and many still do) you must always enable fast quadtree
index lookups in MapServer through the <a class="reference internal" href="../utilities/shptree.html#shptree"><span class="std std-ref">shptree</span></a> utility.</p></li>
<li><p>Wherever possible, making your source dataset as lightweight as possible, will
assist MapServer in processing your data (for vectors, this could mean removing
unused data fields).</p></li>
<li><p>As mentioned earlier, if you must display various rasters or vectors as a ‘mosaic’
together, implement <a class="reference internal" href="tileindex.html#tileindex"><span class="std std-ref">Tile Indexes</span></a>, to implement the mosaic as a single layer
in MapServer.</p></li>
<li><p>GDAL’s virtual format (VRT) is very
powerful also for mosaicing or transforming data on-demand, and has specific VRT
driver instructions for <a class="reference external" href="https://gdal.org/drivers/vector/vrt.html">vector</a>
and <a class="reference external" href="https://gdal.org/drivers/raster/vrt.html#raster-vrt">raster</a> .</p></li>
<li><p>There are times when splitting .shp files (shapefiles) into smaller files, make it
more efficient to display in MapServer; the <a class="reference external" href="https://github.com/woodbri/imaptools.com">shp2tile</a>
utility is a wonderful commandline tool for this.</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>For Windows users, <a class="reference external" href="https://ms4w.com">MS4W</a> includes the shp2tile utility, and
all utilities mentioned above.</p>
</div>
</section>
<section id="enable-caching-through-mapcache">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">9. Enable Caching through MapCache</a><a class="headerlink" href="#enable-caching-through-mapcache" title="Link to this heading">¶</a></h3>
<p>If your mapfile serves any OGC-related service (such as WMS, WFS, etc.) you should
consider enabling <a class="reference internal" href="../mapcache/index.html#mapcache"><span class="std std-ref">MapCache</span></a>, an Apache module, for your services. Caching
common map results (as an image file, or inside a SQLite db for example) for common
map extents, will obviously drastically improve speed, and cancel-out any format
discussions/benefits/arguments mentioned above.</p>
</section>
<section id="symbols">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">10. Symbols</a><a class="headerlink" href="#symbols" title="Link to this heading">¶</a></h3>
<p>When the mapfile is loaded, each raster symbol listed in the symbols file is
located on the filesystem and loaded.</p>
<p><strong>Optimization Suggestions</strong></p>
<ul class="simple">
<li><p>Only include raster symbols in your symbols file if you know that they will
be used by your application.</p></li>
</ul>
</section>
<section id="fonts">
<span id="index-4"></span><h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">11. Fonts</a><a class="headerlink" href="#fonts" title="Link to this heading">¶</a></h3>
<p>To load a font, MapServer opens up a lookup file (often named fonts.list or fonts.txt)
<a class="reference internal" href="../mapfile/fontset.html#fontset"><span class="std std-ref">FONTSET</span></a> which contains an alias for the font and the path for that font file. If you have a
fonts.list file with a long list of fonts, it will take more time for
MapServer to locate and load the font that you need.</p>
<p><strong>Optimization Suggestions</strong></p>
<ul class="simple">
<li><p>Limit the entries in fonts.list to fonts that you actually use.</p></li>
</ul>
</section>
<section id="use-mapscript">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">12. Use MapScript</a><a class="headerlink" href="#use-mapscript" title="Link to this heading">¶</a></h3>
<p>MapScript, in your favorite language such as PHP or Python, can be used to manipulate
mapfiles on-the-fly. Some common use cases are:</p>
<ul class="simple">
<li><p>adding a layer into an existing mapfile</p></li>
<li><p>modifying an existing layer</p></li>
<li><p>generating a new mapfile/service on-demand</p></li>
</ul>
<p>The options here are limitless, for what you can do with MapScript. The full list
of available parameters and functions (methods) are listed in the <a class="reference internal" href="../mapscript/mapscript-api/index.html#swig"><span class="std std-ref">SWIG MapScript API Reference</span></a>.</p>
</section>
<section id="don-t-expose-your-map-path">
<h3><a class="toc-backref" href="#table-of-contents" role="doc-backlink">13. Don’t expose your MAP path</a><a class="headerlink" href="#don-t-expose-your-map-path" title="Link to this heading">¶</a></h3>
<p>This is more obvious if your mapfile serves OGC services, such as set in the
<em>wms_onlineresource</em> metadata parameter in your WEB object, which by default
must contain the <em>MAP=path/to/your/mapfile</em>, but exposing paths on your public
server can open you to possible malicious attacks on your filesystem. You should
take some time to review the possible steps in the document <a class="reference internal" href="limit_mapfile_access.html#limit-mapfile-access"><span class="std std-ref">Limit Mapfile Access</span></a>.</p>
<p>At the minimum, you should enable the <em>MS_MAPFILE</em> <a class="reference internal" href="environment_variables.html#environment-variables"><span class="std std-ref">environment variable</span></a>
so that your CGI mapserv requests, and your onlineresource OGC requests, do not require
a visible MAP= path. The WMS Server document has several <a class="reference internal" href="../ogc/wms_server.html#online-resource-wms"><span class="std std-ref">examples</span></a>
of how to enable these environment variables.</p>
</section>
</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 Tuning & Management</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#steps-to-possibly-review">Steps to Possibly Review</a><ul>
<li><a class="reference internal" href="#use-a-mapserver-syntax-file-for-your-favorite-text-editor">1. Use a MapServer Syntax file for your Favorite Text Editor</a></li>
<li><a class="reference internal" href="#testing-your-mapfile-for-speed">2. Testing your Mapfile for Speed</a></li>
<li><a class="reference internal" href="#use-the-various-config-settings-for-debugging">3. Use the various CONFIG settings for debugging</a></li>
<li><a class="reference internal" href="#test-the-full-map-request-through-the-mapserv-executable">4. Test the full Map Request through the mapserv Executable</a></li>
<li><a class="reference internal" href="#projections">5. Projections</a></li>
<li><a class="reference internal" href="#use-includes">6. Use INCLUDEs</a></li>
<li><a class="reference internal" href="#layers">7. Layers</a></li>
<li><a class="reference internal" href="#yes-data-formats-matter">8. Yes Data Formats Matter</a></li>
<li><a class="reference internal" href="#enable-caching-through-mapcache">9. Enable Caching through MapCache</a></li>
<li><a class="reference internal" href="#symbols">10. Symbols</a></li>
<li><a class="reference internal" href="#fonts">11. Fonts</a></li>
<li><a class="reference internal" href="#use-mapscript">12. Use MapScript</a></li>
<li><a class="reference internal" href="#don-t-expose-your-map-path">13. Don’t expose your MAP path</a></li>
</ul>
</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="raster.html" title="Raster Management & Optimization"
>next</a> |</li>
<li class="right" >
<a href="limit_mapfile_access.html" title="Limit Mapfile Access"
>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.1 Documentation</a> »</li>
<li class="nav-item nav-item-2"><a href="index.html" >Optimization</a> »</li>
<li class="nav-item nav-item-this"><a href="">Mapfile Tuning & Management</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">Copyright</a> 2026, Open Source Geospatial Foundation.
Last updated on 2026-03-30.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
</div>
</body>
</html>