-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjoin.html
More file actions
637 lines (591 loc) · 36.6 KB
/
join.html
File metadata and controls
637 lines (591 loc) · 36.6 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
<!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>JOIN — 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="LABEL" href="label.html" />
<link rel="prev" title="INCLUDE" href="include.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/mapfile/join.html"><img src="../_static/flagicons/ar.png" alt="ar" title="ar" border="0" /></a>
<a href="../de/mapfile/join.html"><img src="../_static/flagicons/de.png" alt="de" title="de" border="0" /></a>
<a href="../el/mapfile/join.html"><img src="../_static/flagicons/el.png" alt="el" title="el" border="0" /></a>
<a href="../es/mapfile/join.html"><img src="../_static/flagicons/es.png" alt="es" title="es" border="0" /></a>
<a href="../fr/mapfile/join.html"><img src="../_static/flagicons/fr.png" alt="fr" title="fr" border="0" /></a>
<a href="../id/mapfile/join.html"><img src="../_static/flagicons/id.png" alt="id" title="id" border="0" /></a>
<a href="../it/mapfile/join.html"><img src="../_static/flagicons/it.png" alt="it" title="it" border="0" /></a>
<a href="../ja/mapfile/join.html"><img src="../_static/flagicons/ja.png" alt="ja" title="ja" border="0" /></a>
<a href="../nl_NL/mapfile/join.html"><img src="../_static/flagicons/nl_NL.png" alt="nl_NL" title="nl_NL" border="0" /></a>
<a href="../pl/mapfile/join.html"><img src="../_static/flagicons/pl.png" alt="pl" title="pl" border="0" /></a>
<a href="../ru/mapfile/join.html"><img src="../_static/flagicons/ru.png" alt="ru" title="ru" border="0" /></a>
<a href="../sq/mapfile/join.html"><img src="../_static/flagicons/sq.png" alt="sq" title="sq" border="0" /></a>
<a href="../tr/mapfile/join.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="label.html" title="LABEL"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="include.html" title="INCLUDE"
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">Mapfile</a> »</li>
<li class="nav-item nav-item-this"><a href="">JOIN</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="join">
<span id="index-0"></span><span id="id1"></span><h1>JOIN<a class="headerlink" href="#join" title="Link to this heading">¶</a></h1>
<section id="description">
<span id="mapfile-join-layer"></span><h2>Description<a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
<p>Joins are defined within a <a class="reference internal" href="layer.html#layer"><span class="std std-ref">LAYER</span></a> object. It is important to understand
that JOINs are <em>ONLY</em> available once a query has been processed. You cannot
use joins to affect the look of a map. The primary purpose is to enable lookup
tables for coded data (e.g. 1 => Forest) but there are other possible uses.</p>
</section>
<section id="supported-formats">
<span id="index-1"></span><h2>Supported Formats<a class="headerlink" href="#supported-formats" title="Link to this heading">¶</a></h2>
<ul class="simple">
<li><p>DBF/XBase files</p></li>
<li><p>CSV (comma delimited text file)</p></li>
<li><p>PostgreSQL tables</p></li>
<li><p>MySQL tables</p></li>
</ul>
</section>
<section id="mapfile-parameters">
<h2>Mapfile Parameters:<a class="headerlink" href="#mapfile-parameters" title="Link to this heading">¶</a></h2>
<dl id="mapfile-join-connection">
<dt>CONNECTION [string]</dt><dd><p>Parameters required for the join table’s database connection (not required
for DBF or CSV joins). The following is an example connection for
<a class="reference internal" href="../input/vector/postgis.html#input-postgis"><span class="std std-ref">PostgreSQL</span></a>:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">CONNECTION</span> <span class="s">"host=127.0.0.1 port=5432 user=pg password=pg dbname=somename"</span>
<span class="k">CONNECTIONTYPE</span> <span class="nb">POSTGRESQL</span>
</pre></div>
</div>
</dd>
</dl>
<span id="index-3"></span><span id="index-2"></span><span id="mapfile-join-connectiontype"></span><dl class="simple" id="index-4">
<dt>CONNECTIONTYPE [csv|mysql|postgresql]</dt><dd><p>Type of connection (not required for DBF joins). For PostgreSQL
use <cite>postgresql</cite>, for CSV use <cite>csv</cite>, for MySQL use <cite>mysql</cite>.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-footer">
<dt>FOOTER [filename]</dt><dd><p>Template to use <em>after</em> a layer’s set of results have been sent. In other
words, this header HTML will be displayed after the contents of the
<cite>TEMPLATE</cite> HTML.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-from">
<dt>FROM [column]</dt><dd><p>Join column in the dataset. This is case sensitive.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-header">
<dt>HEADER [filename]</dt><dd><p>Template to use <em>before</em> a layer’s set of results have been sent. In other
words, this header HTML will be displayed before the contents of the
<cite>TEMPLATE</cite> HTML.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-name">
<dt>NAME [string]</dt><dd><p>Unique name for this join. Required.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-table">
<dt>TABLE [filename|tablename]</dt><dd><p>For file-based joins this is the name of XBase or comma delimited file
(relative to the location of the mapfile) to join TO. For PostgreSQL
support this is the name of the PostgreSQL table to join TO.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-template">
<dt>TEMPLATE [filename]</dt><dd><p>Template to use with one-to-many joins. The template is processed
once for each record and can only contain substitutions for
columns in the joined table. Refer to the column in the joined
table in your template like [joinname_columnname], where joinname
is the NAME specified for the JOIN object.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-to">
<dt>TO [column]</dt><dd><p>Join column in the table to be joined. This is case sensitive.</p>
</dd>
</dl>
<dl class="simple" id="mapfile-join-type">
<dt>TYPE [ONE-TO-ONE|ONE-TO-MANY]</dt><dd><p>The type of join. Default is one-to-one.</p>
</dd>
</dl>
</section>
<section id="example-1-join-from-shapefile-to-dbf-file">
<h2>Example 1: Join from Shapefile to DBF file<a class="headerlink" href="#example-1-join-from-shapefile-to-dbf-file" title="Link to this heading">¶</a></h2>
<section id="mapfile-layer">
<h3>Mapfile Layer<a class="headerlink" href="#mapfile-layer" title="Link to this heading">¶</a></h3>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">LAYER</span>
<span class="k">NAME</span> <span class="s">"prov_bound"</span>
<span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="k">STATUS</span> <span class="nb">DEFAULT</span>
<span class="k">DATA</span> <span class="s">"prov.shp"</span>
<span class="k">CLASS</span>
<span class="k">NAME</span> <span class="s">"Province"</span>
<span class="k">STYLE</span>
<span class="k">OUTLINECOLOR</span> <span class="mi">120</span> <span class="mi">120</span> <span class="mi">120</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">255</span> <span class="mi">0</span>
<span class="k">END</span>
<span class="k">END</span>
<span class="k">TEMPLATE</span> <span class="s">"../htdocs/cgi-query-templates/prov.html"</span>
<span class="k">HEADER</span> <span class="s">"../htdocs/cgi-query-templates/prov-header.html"</span>
<span class="k">FOOTER</span> <span class="s">"../htdocs/cgi-query-templates/footer.html"</span>
<span class="k">JOIN</span>
<span class="k">NAME</span> <span class="s">"test"</span>
<span class="k">TABLE</span> <span class="s">"../data/lookup.dbf"</span>
<span class="k">FROM</span> <span class="s">"ID"</span>
<span class="k">TO</span> <span class="s">"IDENT"</span>
<span class="k">TYPE</span> <span class="nb">ONE-TO-ONE</span>
<span class="k">END</span>
<span class="k">END</span> <span class="c1"># layer</span>
</pre></div>
</div>
</section>
<section id="ogrinfo">
<h3>Ogrinfo<a class="headerlink" href="#ogrinfo" title="Link to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>>ogrinfo lookup.dbf lookup -summary
INFO: Open of `lookup.dbf'
using driver `ESRI Shapefile' successful.
Layer name: lookup
Geometry: None
Feature Count: 12
Layer SRS WKT:
(unknown)
IDENT: Integer (2.0)
VAL: Integer (2.0)
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>>ogrinfo prov.shp prov -summary
INFO: Open of `prov.shp'
using driver `ESRI Shapefile' successful.
Layer name: prov
Geometry: Polygon
Feature Count: 12
Extent: (-2340603.750000, -719746.062500) - (3009430.500000, 3836605.250000)
Layer SRS WKT:
(unknown)
NAME: String (30.0)
ID: Integer (2.0)
</pre></div>
</div>
</section>
<section id="template">
<h3>Template<a class="headerlink" href="#template" title="Link to this heading">¶</a></h3>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">tr</span> <span class="na">bgcolor</span><span class="o">=</span><span class="s">"#EFEFEF"</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[NAME]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[test_VAL]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
</section>
</section>
<section id="example-2-join-from-shapefile-to-postgresql-table">
<h2>Example 2: Join from Shapefile to PostgreSQL table<a class="headerlink" href="#example-2-join-from-shapefile-to-postgresql-table" title="Link to this heading">¶</a></h2>
<section id="id2">
<h3>Mapfile Layer<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">LAYER</span>
<span class="k">NAME</span> <span class="s">"prov_bound"</span>
<span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="k">STATUS</span> <span class="nb">DEFAULT</span>
<span class="k">DATA</span> <span class="s">"prov.shp"</span>
<span class="k">CLASS</span>
<span class="k">NAME</span> <span class="s">"Province"</span>
<span class="k">STYLE</span>
<span class="k">OUTLINECOLOR</span> <span class="mi">120</span> <span class="mi">120</span> <span class="mi">120</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">255</span> <span class="mi">0</span>
<span class="k">END</span>
<span class="k">END</span>
<span class="k">TOLERANCE</span> <span class="mi">20</span>
<span class="k">TEMPLATE</span> <span class="s">"../htdocs/cgi-query-templates/prov.html"</span>
<span class="k">HEADER</span> <span class="s">"../htdocs/cgi-query-templates/prov-header.html"</span>
<span class="k">FOOTER</span> <span class="s">"../htdocs/cgi-query-templates/footer.html"</span>
<span class="k">JOIN</span>
<span class="k">NAME</span> <span class="s">"test"</span>
<span class="k">CONNECTION</span> <span class="s">"host=127.0.0.1 port=5432 user=pg password=pg dbname=join"</span>
<span class="k">CONNECTIONTYPE</span> <span class="nb">postgresql</span>
<span class="k">TABLE</span> <span class="s">"lookup"</span>
<span class="k">FROM</span> <span class="s">"ID"</span>
<span class="k">TO</span> <span class="s">"ident"</span>
<span class="k">TYPE</span> <span class="nb">ONE-TO-ONE</span>
<span class="k">END</span>
<span class="k">END</span> <span class="c1"># layer</span>
</pre></div>
</div>
</section>
<section id="id3">
<h3>Ogrinfo<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>>ogrinfo -ro PG:"host=127.0.0.1 port=5432 user=pg password=pg dbname=join"
lookup -summary
INFO: Open of `PG:host=127.0.0.1 port=5432 user=pg password=pg dbname=join'
using driver `PostgreSQL' successful.
Layer name: lookup
Geometry: Unknown (any)
Feature Count: 12
Layer SRS WKT:
(unknown)
ident: Integer (0.0)
val: Integer (0.0)
</pre></div>
</div>
</section>
<section id="id4">
<h3>Template<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cp"><!-- MapServer Template</span>
<span class="cp"><tr bgcolor="#EFEFEF"></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[NAME]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[test_val]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
</section>
</section>
<section id="example-3-join-from-shapefile-to-csv-file">
<h2>Example 3: Join from Shapefile to CSV file<a class="headerlink" href="#example-3-join-from-shapefile-to-csv-file" title="Link to this heading">¶</a></h2>
<section id="id5">
<h3>Mapfile Layer<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h3>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">LAYER</span>
<span class="k">NAME</span> <span class="s">"prov_bound"</span>
<span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="k">STATUS</span> <span class="nb">DEFAULT</span>
<span class="k">DATA</span> <span class="s">"prov.shp"</span>
<span class="k">CLASS</span>
<span class="k">NAME</span> <span class="s">"Province"</span>
<span class="k">STYLE</span>
<span class="k">OUTLINECOLOR</span> <span class="mi">120</span> <span class="mi">120</span> <span class="mi">120</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">255</span> <span class="mi">0</span>
<span class="k">END</span>
<span class="k">END</span>
<span class="k">TOLERANCE</span> <span class="mi">20</span>
<span class="k">TEMPLATE</span> <span class="s">"../htdocs/cgi-query-templates/prov.html"</span>
<span class="k">HEADER</span> <span class="s">"../htdocs/cgi-query-templates/prov-header.html"</span>
<span class="k">FOOTER</span> <span class="s">"../htdocs/cgi-query-templates/footer.html"</span>
<span class="k">JOIN</span>
<span class="k">NAME</span> <span class="s">"test"</span>
<span class="k">CONNECTIONTYPE</span> <span class="nb">CSV</span>
<span class="k">TABLE</span> <span class="s">"../data/lookup.csv"</span>
<span class="k">FROM</span> <span class="s">"ID"</span>
<span class="c1">#TO "IDENT" # see note below</span>
<span class="k">TO</span> <span class="s">"1"</span> <span class="c1"># see note below</span>
<span class="k">TYPE</span> <span class="nb">ONE-TO-ONE</span>
<span class="k">END</span>
<span class="k">END</span> <span class="c1"># layer</span>
</pre></div>
</div>
</section>
<section id="csv-file-structure">
<h3>CSV File Structure<a class="headerlink" href="#csv-file-structure" title="Link to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s2">"IDENT"</span><span class="p">,</span><span class="s2">"VAL"</span>
<span class="mi">1</span><span class="p">,</span><span class="mi">12</span>
<span class="mi">2</span><span class="p">,</span><span class="mi">11</span>
<span class="mi">3</span><span class="p">,</span><span class="mi">10</span>
<span class="mi">4</span><span class="p">,</span><span class="mi">9</span>
<span class="mi">5</span><span class="p">,</span><span class="mi">8</span>
<span class="mi">6</span><span class="p">,</span><span class="mi">7</span>
<span class="mi">7</span><span class="p">,</span><span class="mi">6</span>
<span class="mi">8</span><span class="p">,</span><span class="mi">5</span>
<span class="mi">9</span><span class="p">,</span><span class="mi">4</span>
<span class="mi">10</span><span class="p">,</span><span class="mi">3</span>
<span class="mi">11</span><span class="p">,</span><span class="mi">2</span>
<span class="mi">12</span><span class="p">,</span><span class="mi">1</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The CSV driver currently doesn’t read column names from the first
row. It just uses indexes (1, 2, … n) to reference the
columns. It’s ok to leave column names as the first row since they
likely won’t match anything but they aren’t used. Typically you’d
see something like TO “1” in the JOIN block. Then in the template
you’d use [name_1], [name_2], etc…</p>
</div>
</section>
<section id="id6">
<h3>Ogrinfo<a class="headerlink" href="#id6" title="Link to this heading">¶</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>>ogrinfo lookup.csv lookup -summary
INFO: Open of `lookup.csv'
using driver `CSV' successful.
Layer name: lookup
Geometry: None
Feature Count: 12
Layer SRS WKT:
(unknown)
IDENT: String (0.0)
VAL: String (0.0)
</pre></div>
</div>
</section>
<section id="template-prov-html">
<h3>Template (prov.html)<a class="headerlink" href="#template-prov-html" title="Link to this heading">¶</a></h3>
<p>Ideally this the template should look like this:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">tr</span> <span class="na">bgcolor</span><span class="o">=</span><span class="s">"#EFEFEF"</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[NAME]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[test_VAL]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
<p>But since attribute names are not supported for CSV files (see note
above), the following will have to be used:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">tr</span> <span class="na">bgcolor</span><span class="o">=</span><span class="s">"#EFEFEF"</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[NAME]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span> <span class="na">align</span><span class="o">=</span><span class="s">"left"</span><span class="p">></span>[test_2]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
</section>
</section>
<section id="example-4-join-from-shapefile-to-mysql">
<h2>Example 4: Join from Shapefile to MySQL<a class="headerlink" href="#example-4-join-from-shapefile-to-mysql" title="Link to this heading">¶</a></h2>
<section id="id7">
<h3>Mapfile Layer<a class="headerlink" href="#id7" title="Link to this heading">¶</a></h3>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">LAYER</span>
<span class="k">NAME</span> <span class="s">"prov_bound"</span>
<span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="k">STATUS</span> <span class="nb">DEFAULT</span>
<span class="k">DATA</span> <span class="s">"prov.shp"</span>
<span class="k">CLASS</span>
<span class="k">NAME</span> <span class="s">"Province"</span>
<span class="k">STYLE</span>
<span class="k">OUTLINECOLOR</span> <span class="mi">120</span> <span class="mi">120</span> <span class="mi">120</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">255</span> <span class="mi">0</span>
<span class="k">END</span> <span class="c1"># style</span>
<span class="k">END</span> <span class="c1"># class</span>
<span class="k">TOLERANCE</span> <span class="mi">20</span>
<span class="k">TEMPLATE</span> <span class="s">"../htdocs/cgi-query-templates/prov.html"</span>
<span class="k">HEADER</span> <span class="s">"../htdocs/cgi-query-templates/prov-header.html"</span>
<span class="k">FOOTER</span> <span class="s">"../htdocs/cgi-query-templates/footer.html"</span>
<span class="k">JOIN</span>
<span class="k">NAME</span> <span class="s">"mysql-join"</span>
<span class="k">CONNECTIONTYPE</span> <span class="nb">MYSQL</span>
<span class="k">CONNECTION</span> <span class="s">'server:user:password:database'</span>
<span class="k">TABLE</span> <span class="s">"mysql-tablename"</span>
<span class="k">FROM</span> <span class="s">"ID"</span>
<span class="k">TO</span> <span class="s">"mysql-column"</span>
<span class="k">TYPE</span> <span class="nb">ONE-TO-ONE</span>
<span class="k">END</span> <span class="c1"># join</span>
<span class="k">END</span> <span class="c1"># layer</span>
</pre></div>
</div>
</section>
</section>
<section id="example-5-one-to-many-join">
<h2>Example 5: One-to-many join<a class="headerlink" href="#example-5-one-to-many-join" title="Link to this heading">¶</a></h2>
<p>In a join of type <cite>ONE-TO-MANY</cite>, the <cite>JOIN</cite> object needs to contain a
<cite>TEMPLATE</cite>. This <cite>TEMPLATE</cite> is used for each matching record in the
join table. Columns in the join table are referenced using
<join_name>_<join_column_name>. Columns in the layer table are
referenced using <column_name>.</p>
<p>For a one-to-many join, the <cite>LAYER</cite> <cite>TEMPLATE</cite> file has to contain a
reference to the the <cite>JOIN</cite> object, as follows: [join_<join_name>].</p>
<p>In this example, it is assumed that the join table many.dbf contains
the columns MANYFIELD1 and MANYFIELD2 in addition to the join column
(IDENT).</p>
<p>Layer object:</p>
<div class="highlight-mapfile notranslate"><div class="highlight"><pre><span></span><span class="k">LAYER</span>
<span class="k">NAME</span> <span class="s">"joinonetomany"</span>
<span class="k">TYPE</span> <span class="nb">POLYGON</span>
<span class="k">STATUS</span> <span class="nb">DEFAULT</span>
<span class="k">DATA</span> <span class="s">"prov.shp"</span>
<span class="k">CLASS</span>
<span class="k">NAME</span> <span class="s">"Province"</span>
<span class="k">STYLE</span>
<span class="k">OUTLINECOLOR</span> <span class="mi">120</span> <span class="mi">120</span> <span class="mi">120</span>
<span class="k">COLOR</span> <span class="mi">255</span> <span class="mi">255</span> <span class="mi">0</span>
<span class="k">END</span> <span class="c1"># style</span>
<span class="k">END</span> <span class="c1"># class</span>
<span class="k">TEMPLATE</span> <span class="s">"oneToMany.html"</span>
<span class="k">HEADER</span> <span class="s">"oneToMany_header.html"</span>
<span class="k">FOOTER</span> <span class="s">"oneToMany_footer.html"</span>
<span class="k">JOIN</span>
<span class="k">NAME</span> <span class="s">"onetomanytest"</span>
<span class="k">TABLE</span> <span class="s">"many.dbf"</span>
<span class="k">FROM</span> <span class="s">"ID"</span>
<span class="k">TO</span> <span class="s">"IDENT"</span>
<span class="k">TYPE</span> <span class="nb">ONE-TO-MANY</span>
<span class="k">TEMPLATE</span> <span class="s">"oneToMany_join.html"</span>
<span class="k">END</span> <span class="c1"># join</span>
<span class="k">END</span> <span class="c1"># layer</span>
</pre></div>
</div>
<p>Template oneToMany_header.html:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">html</span><span class="p">></span>
<span class="p"><</span><span class="nt">head</span><span class="p">><</span><span class="nt">title</span><span class="p">></span>One to Many Join<span class="p"></</span><span class="nt">title</span><span class="p">></</span><span class="nt">head</span><span class="p">></span>
<span class="p"><</span><span class="nt">body</span><span class="p">></span>
<span class="p"><</span><span class="nt">h1</span><span class="p">></span>MapServer output<span class="p"></</span><span class="nt">h1</span><span class="p">></span>
<span class="p"><</span><span class="nt">table</span><span class="p">></span>
</pre></div>
</div>
<p>Template oneToMany.html:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">tr</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span><span class="p">><</span><span class="nt">strong</span><span class="p">></span>[ID]<span class="p"></</span><span class="nt">strong</span><span class="p">></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">table</span><span class="p">></span>
[join_onetomanytest]
<span class="p"></</span><span class="nt">table</span><span class="p">></span>
<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
<p>Template oneToMany_join.html:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"><</span><span class="nt">tr</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span><span class="p">></span>[NAME]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span><span class="p">></span>[onetomanytest_MANYFIELD1]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"><</span><span class="nt">td</span><span class="p">></span>[onetomanytest_MANYFIELD2]<span class="p"></</span><span class="nt">td</span><span class="p">></span>
<span class="p"></</span><span class="nt">tr</span><span class="p">></span>
</pre></div>
</div>
<p>Template oneToMany_footer.html:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="cm"><!-- MapServer Template --></span>
<span class="p"></</span><span class="nt">table</span><span class="p">></span>
<span class="p"></</span><span class="nt">body</span><span class="p">></span>
<span class="p"><</span><span class="nt">html</span><span class="p">></span>
</pre></div>
</div>
</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="#">JOIN</a><ul>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#supported-formats">Supported Formats</a></li>
<li><a class="reference internal" href="#mapfile-parameters">Mapfile Parameters:</a></li>
<li><a class="reference internal" href="#example-1-join-from-shapefile-to-dbf-file">Example 1: Join from Shapefile to DBF file</a><ul>
<li><a class="reference internal" href="#mapfile-layer">Mapfile Layer</a></li>
<li><a class="reference internal" href="#ogrinfo">Ogrinfo</a></li>
<li><a class="reference internal" href="#template">Template</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-2-join-from-shapefile-to-postgresql-table">Example 2: Join from Shapefile to PostgreSQL table</a><ul>
<li><a class="reference internal" href="#id2">Mapfile Layer</a></li>
<li><a class="reference internal" href="#id3">Ogrinfo</a></li>
<li><a class="reference internal" href="#id4">Template</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-3-join-from-shapefile-to-csv-file">Example 3: Join from Shapefile to CSV file</a><ul>
<li><a class="reference internal" href="#id5">Mapfile Layer</a></li>
<li><a class="reference internal" href="#csv-file-structure">CSV File Structure</a></li>
<li><a class="reference internal" href="#id6">Ogrinfo</a></li>
<li><a class="reference internal" href="#template-prov-html">Template (prov.html)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-4-join-from-shapefile-to-mysql">Example 4: Join from Shapefile to MySQL</a><ul>
<li><a class="reference internal" href="#id7">Mapfile Layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-5-one-to-many-join">Example 5: One-to-many join</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="label.html" title="LABEL"
>next</a> |</li>
<li class="right" >
<a href="include.html" title="INCLUDE"
>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" >Mapfile</a> »</li>
<li class="nav-item nav-item-this"><a href="">JOIN</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>