[go: up one dir, main page]

File: index.html

package info (click to toggle)
tilestache 1.31.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,016 kB
  • ctags: 928
  • sloc: python: 4,068; makefile: 10
file content (1910 lines) | stat: -rw-r--r-- 50,069 bytes parent folder | download
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
<!DOCTYPE html>
<html lang="en">
<head>
    <title>TileStache API</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <style type="text/css" title="text/css">
    <!--

    body
    {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px;
        line-height: 18px;
        color: black;
    }
    
    h2 { font-size: 1.5em; }
    h3 { font-size: 1.2em; }
    h4, h5 { font-size: 1em; }
    
    pre, p samp, dl samp, p code, dl code
    {
        font-family: Monaco, monospace;
        font-size: 0.9em;
    }

    pre { font-size: 0.8em; }
    
    body { margin-left: 56px; margin-bottom: 4em; }
    #intro { margin-left: -28px; }
    h1, h2, h3, h4 { margin: 1em 56px 1em -28px; }
    h5 { margin: 1em 0; }
    dd, li { margin-left: 14px; }
    ul { padding-left: 0; list-style-type: none; }
    #index { float: right; width: 20em; padding-bottom: 2em; }
    
    h2 { margin-top: 2em; border-top: 1px solid #ccc; padding-top: 1em;}

    body, #index { background-color: white; }
    pre .bg { color: #aaa; }

    p, dd, pre { width: 50em; }

    var, samp, code { white-space: nowrap; }
    samp, pre { background-color: #eee; }
    dt { display: inline; font-weight: bold; }
    var { background-color: #fe7; }

    dd dl { margin: 0; }

    samp, pre, var { padding: 0 2px; margin: 0 -2px; border-radius: 2px; }
    pre { margin: -4px 10px; padding: 4px; border: 1px solid #ddd; border-radius: 3px; }

    -->
    </style>
</head>
<body>

<h1>TileStache API</h1>

<div id="intro">

    <p>
    TileStache is a Python-based server application that can serve up map tiles
    based on rendered geographic data. You might be familiar with
    <a href="http://tilecache.org">TileCache</a> the venerable open source WMS
    server from MetaCarta. TileStache is similar, but we hope simpler and
    better-suited to the needs of designers and cartographers.
    </p>

    <p>
    <strong>This document covers TileStache version 1.31.0</strong>.
    </p>

    <p>
    See also <a href="TileStache.html">detailed module and class reference</a>.
    </p>

</div>

<ul id="index">
  <li>
    <a href="#requesting-tiles">Requesting Tiles</a>
    <ul>
      <li><a href="#over-http">Over HTTP</a></li>
      <li>
        <a href="#in-code">In Code</a>
<!-- 
        <ul>
          <li><a href="#tilestache-gettile"><code>TileStache.getTile</code></a></li>
          <li><a href="#tilestache-requesthandler"><code>TileStache.requestHandler</code></a></li>
        </ul>
 -->
      </li>
    </ul>
  </li>
  <li>
    <a href="#serving-tiles">Serving Tiles</a>
    <ul>
      <li><a href="#wsgi">WSGI</a></li>
      <li><a href="#cgi">CGI</a></li>
      <li><a href="#mod-python">mod_python</a></li>
    </ul>
  </li>
  <li>
    <a href="#configuring-tilestache">Configuring TileStache</a>
    <ul>
      <li>
        <a href="#caches">Caches</a>
<!-- 
        <ul>
          <li><a href="#test-cache">Test</a></li>
          <li><a href="#disk-cache">Disk</a></li>
          <li><a href="#multi-cache">Multi</a></li>
          <li><a href="#memcache-cache">Memcache</a></li>
          <li><a href="#s3-cache">S3</a></li>
        </ul>
 -->
      </li>
      <li><a href="#layers">Layers</a></li>
      <li>
        <a href="#providers">Providers</a>
<!-- 
        <ul>
          <li><a href="#mapnik-provider">Mapnik</a></li>
          <li><a href="#proxy-provider">Proxy</a></li>
          <li><a href="#url-template-provider">URL Template</a></li>
          <li><a href="#mbtiles-provider">MBTiles</a></li>
        </ul>
 -->
      </li>
      <li><a href="#projections">Projections</a></li>
      <li><a href="#metatiles">Metatiles</a></li>
      <li><a href="#preview">Preview</a></li>
      <li><a href="#index-page">Index Page</a></li>
      <li><a href="#logging">Logging</a></li>
    </ul>
  </li>
  <li>
    <a href="#extending-tilestache">Extending TileStache</a>
    <ul>
      <li>
        <a href="#custom-providers">Providers</a>
<!-- 
        <ul>
          <li><a href="#provider-rendertile"><code>provider.renderTile</code></a></li>
          <li><a href="#provider-renderarea"><code>provider.renderArea</code></a></li>
          <li><a href="#provider-gettypebyextension"><code>provider.getTypeByExtension</code></a></li>
        </ul>
 -->
      </li>
      <li><a href="#custom-caches">Caches</a></li>
      <li><a href="#custom-configuration">Configuration</a></li>
    </ul>
  </li>
</ul>

<h2><a id="requesting-tiles" name="requesting-tiles">Requesting Tiles</a></h2>

<h3><a id="over-http" name="over-http">Over HTTP</a></h3>

<p>
TileStache URLs are based on a simplified TMS scheme:
</p>

<pre>
/{layer name}/{zoom}/{column}/{row}.{extension}
</pre>

<p>
An example tile URL might look like this:
</p>

<pre>
http://example.org/path/tile.cgi/streets/12/656/1582.png
</pre>

<p>
For JSON responses such as those from the <a href="#vector-provider">Vector provider</a>, URLs
can include an optional callback for <a href="http://en.wikipedia.org/wiki/JSONP">JSONP</a> support:
</p>

<pre>
http://example.org/path/tile.cgi/streets/12/656/1582.json?callback=funcname
</pre>

<p>
Interactive, slippy-map previews of tiles are also available:
</p>

<pre>
/{layer name}/preview.html
</pre>

<h3><a id="in-code" name="in-code">In Code</a></h3>

<h4><a id="tilestache-gettile" name="tilestache-gettile"><code>TileStache.getTile</code></a></h4>

<p>
Get a type string and tile binary for a given request layer tile.
</p>
 
<p>
Arguments to <code>getTile</code>:
</p>

<dl>
    <dt>layer</dt>
    <dd>
    Instance of <code>Core.Layer</code> to render.
    </dd>

    <dt>coord</dt>
    <dd>
    One <code>ModestMaps.Core.Coordinate</code> corresponding to a single tile.
    </dd>

    <dt>extension</dt>
    <dd>
    Filename extension to choose response type, e.g. <samp>"png"</samp> or
    <samp>"jpg"</samp>.
    </dd>

    <dt>ignore_cached</dt>
    <dd>
    Optional boolean: always re-render the tile, whether it's in the cache or
    not. Default <samp>False</samp>.
    </dd>
</dl>
 
<p>
Return value of <code>getTile</code> is a tuple containing a mime-type string
such as <samp>"image/png"</samp> and a complete byte string representing the
rendered tile.
</p>

<p>
See
<a href="TileStache.html#-getTile">TileStache.getTile</a>
documentation for more information.
</p>

<h4><a id="tilestache-requesthandler" name="tilestache-requesthandler"><code>TileStache.requestHandler</code></a></h4>

<p>
Generate a mime-type and response body for a given request. This is the function
to use when creating new HTTP interfaces to TileStache.
</p>
 
<p>
Arguments to <code>requestHandler</code>:
</p>

<dl>
    <dt>config</dt>
    <dd>
    Required file path string for a JSON configuration file or a configuration
    object with <var>cache</var>, <var>layers</var>, and <var>dirpath</var>
    properties, such as
    <a href="TileStache.Config.html#Configuration"><code>TileStache.Config.Configuration</code></a>.
    </dd>

    <dt>path_info</dt>
    <dd>
    Required end portion of a request URL including the layer name and tile
    coordinate, e.g. <samp>"/roads/12/656/1582.png"</samp>.
    </dd>

    <dt>query_string</dt>
    <dd>
    Optional query string. Currently used only for JSONP callbacks.
    </dd>
</dl>
 
<p>
Return value of <code>requestHandler</code> is a tuple containing a mime-type string
such as <samp>"image/png"</samp> and a complete byte string representing the
rendered tile.
</p>

<p>
See
<a href="TileStache.html#-requestHandler">TileStache.requestHandler</a>
documentation for more information.
</p>

<h2><a id="serving-tiles" name="serving-tiles">Serving Tiles</a></h2>

<p>
We currently provide three scripts for serving tiles: one for a WSGI-based
webserver, one for a CGI-based webserver, and one for Apache <code>mod_python</code>.
</p>

<h4><a id="wsgi" name="wsgi">WSGI</a></h4>

<p>
TileStache comes with a WSGI application and a 
<a href="http://werkzeug.pocoo.org/">Werkzeug</a> web server. To use the
built-in server, run <tt>tilestache-server.py</tt>,
which (by default) looks for a config file named <tt>tilestache.cfg</tt>
in the current directory and then serves tiles on
<tt>http://127.0.0.1:8080/</tt>. Check <tt>tilestache-server.py --help</tt>
to change these defaults.
</p>

<p>Alternatively, any WSGI server can be pointed at an instance of
<tt>TileStache.WSGITileServer</tt>. Here’s how to use it with
<a href="http://gunicorn.org/">gunicorn</a>:
</p>

<pre>
$ gunicorn "TileStache:WSGITileServer('/path/to/tilestache.cfg')"
</pre>

<p>
See
<a href="TileStache.html#WSGITileServer"><code>TileStache.WSGITileServer</code></a>
documentation for more information.
</p>

<h4><a id="cgi" name="cgi">CGI</a></h4>

<p>
Using TileStache through CGI supports basic tile serving, and is useful for
simple testing and low-to-medium traffic websites. This is a complete, working
CGI script that looks for configuration in a local file called
<tt>tilestache.cfg</tt>:
</p>

<pre>
#!/usr/bin/python
import os, TileStache
TileStache.cgiHandler(os.environ, 'tilestache.cfg', debug=True)
</pre>

<p>
See
<a href="TileStache.html#-cgiHandler"><code>TileStache.cgiHandler</code></a>
documentation for more information.
</p>

<h4><a id="mod-python" name="mod-python">mod_python</a></h4>

<p>
Using TileStache through <code>mod_python</code> improves performance by
caching imported modules, but must be configured via the Apache webserver
config. This is a complete example configuration for a webserver publishing
tiles configured by a file in <code>/etc</code>:
</p>

<pre>
&lt;Directory /var/www/tiles&gt;
  AddHandler mod_python .py
  PythonHandler TileStache::modpythonHandler
  PythonOption config /etc/tilestache.cfg
&lt;/Directory&gt;
</pre>

<p>
See
<a href="TileStache.html#-modPythonHandler"><code>TileStache.modPythonHandler</code></a>
documentation for more information.
</p>

<h2><a id="configuring-tilestache" name="configuring-tilestache">Configuring TileStache</a></h2>

<p>
TileStache configuration is stored in JSON files, and is composed of two main
top-level sections: <samp>"cache"</samp> and <samp>"layers"</samp>. There are
examples of both in this minimal sample configuration:
</p>
 
<pre>
{
  "cache": {"name": "Test"},
  "layers": {
    "ex": {
        "provider": {"name": "mapnik", "mapfile": "style.xml"},
        "projection": "spherical mercator"
    } 
  }
}
</pre>

<h3><a id="caches" name="caches">Caches</a></h3>

<p>
A Cache is the part of TileStache that stores static files to speed up future
requests. A few default caches are shown here, with additional cache classes
defined in
<a href="TileStache.Goodies.Caches.html"><code>TileStache.Goodies.Caches</code></a>
</p>

<h4><a id="test-cache" name="test-cache">Test</a></h4>

<p>
Simple cache that doesn’t actually cache anything.
</p>
 
<p>
Activity is optionally logged, though.
</p>
 
<p>
Example configuration:
</p>

<pre>
<span class="bg">{</span>
  "cache": {
    "name": "Test",
    "verbose": True
  }<span class="bg">,
  "layers": { … }
}</span>
</pre>
 
<p>
Test cache parameters:
</p>

<dl>
    <dt>verbose</dt>
    <dd>
    Optional boolean flag to write cache activities to a logging function,
    defaults to <samp>False</samp> if omitted.
    </dd>
</dl>

<p>
See
<a href="TileStache.Caches.html#Test">TileStache.Caches.Test</a>
documentation for more information.
</p>

<h4><a id="disk-cache" name="disk-cache">Disk</a></h4>

<p>
Caches files to disk.
</p>
 
<p>
Example configuration:
</p>
 
<pre>
<span class="bg">{</span>
  "cache": {
    "name": "Disk",
    "path": "/tmp/stache",
    "umask": "0000",
    "dirs": "portable",
    "gzip": ["xml", "json"]
  }<span class="bg">,
  "layers": { … }
}</span>
</pre>
 
<p>
Disk cache parameters:
</p>

<dl>
    <dt>path</dt>
    <dd>
    Required local directory path where files should be stored.
    </dd>

    <dt>umask</dt>
    <dd>
    Optional string representation of octal permission mask for stored files.
    Defaults to <samp>"0022"</samp>.
    </dd>

    <dt>dirs</dt>
    <dd>
    Optional string saying whether to create cache directories that are safe or
    portable. For an example tile <samp>12/656/1582.png</samp>,
    <samp>"portable"</samp> creates matching directory trees while
    <samp>"safe"</samp> guarantees directories with fewer files, e.g.
    <samp>12/000/656/001/582.png</samp>. Defaults to <samp>"safe"</samp>.
    </dd>

    <dt>gzip</dt>
    <dd>
    Optional list of file formats that should be stored in a
    compressed form. Defaults to <samp>["txt", "text", "json", "xml"]</samp>.
    Provide an empty list in the configuration for no compression.
    </dd>
</dl>

<p>
If your configuration file is loaded from a remote location, e.g.
<samp>http://example.com/tilestache.cfg</samp>, the path <strong>must</strong>
be an unambiguous filesystem path, e.g. <samp>"file:///tmp/cache"</samp>.
</p>

<p>
See
<a href="TileStache.Caches.html#Disk">TileStache.Caches.Disk</a>
documentation for more information.
</p>

<h4><a id="multi-cache" name="multi-cache">Multi</a></h4>

<p>
Caches tiles to multiple, ordered caches.
</p>
 
<p>
Multi cache is well-suited for a speed-to-capacity gradient, for example a
combination of <a href="#memcache-cache">Memcache</a> and <a href="#s3-cache">S3</a>
to take advantage of the high speed of memcache and the high capacity of S3.
Each tier of caching is checked sequentially when reading from the cache, while
all tiers are used together for writing. Locks are only used with the first cache.
</p>
 
<p>
Example configuration:
</p>
 
<pre>
<span class="bg">{</span>
  "cache": {
    "name": "Multi",
    "tiers": [
        {
           "name": "Memcache",
           "servers": ["127.0.0.1:11211"]
        },
        {
           "name": "Disk",
           "path": "/tmp/stache"
        }
    ]
  }<span class="bg">,
  "layers": { … }
}</span>
</pre>
 
<p>
Multi cache parameters:
</p>

<dl>
    <dt>tiers</dt>
    <dd>
    Required list of cache configurations. The fastest, most local cache should
    be at the beginning of the list while the slowest or most remote cache
    should be at the end. Memcache and S3 together make a great pair.
    </dd>
</dl>

<p>
See
<a href="TileStache.Caches.html#Multi">TileStache.Caches.Multi</a>
documentation for more information.
</p>

<h4><a id="memcache-cache" name="memcache-cache">Memcache</a></h4>

<p>
Caches tiles to <a href="http://memcached.org/">Memcache</a>,
requires <a href="http://www.tummy.com/Community/software/python-memcached/">python-memcached</a>.
</p>
 
<p>
Example configuration:
</p>
 
<pre>
<span class="bg">{</span>
  "cache": {
    "name": "Memcache",
    "servers": ["127.0.0.1:11211"],
    "revision": 0
  }<span class="bg">,
  "layers": { … }
}</span>
</pre>
 
<p>
Memcache cache parameters:
</p>

<dl>
    <dt>servers</dt>
    <dd>
    Optional array of servers, list of <samp>"{host}:{port}"</samp> pairs.
    Defaults to <samp>["127.0.0.1:11211"]</samp> if omitted.
    </dd>

    <dt>revision</dt>
    <dd>
    Optional revision number for mass-expiry of cached tiles regardless of lifespan.
    Defaults to <samp>0</samp>.
    </dd>
</dl>

<p>
See
<a href="TileStache.Memcache.html#Cache">TileStache.Memcache.Cache</a>
documentation for more information.
</p>

<h4><a id="s3-cache" name="s3-cache">S3</a></h4>

<p>
Caches tiles to <a href="https://s3.amazonaws.com/">Amazon S3</a>,
requires <a href="http://pypi.python.org/pypi/boto">boto</a> (2.0+).
</p>
 
<p>
Example configuration:
</p>
 
<pre>
<span class="bg">{</span>
  "cache": {
    "name": "S3",
    "bucket": "&lt;bucket name&gt;",
    "access": "&lt;access key&gt;",
    "secret": "&lt;secret key&gt;"
  }<span class="bg">,
  "layers": { … }
}</span>
</pre>
 
<p>
S3 cache parameters:
</p>

<dl>
    <dt>bucket</dt>
    <dd>
    Required bucket name for S3. If it doesn’t exist, it will be created.
    </dd>

    <dt>access</dt>
    <dd>
    Required access key ID for your S3 account. You can find this under “Security
    Credentials” at your <a href="http://aws.amazon.com/account/">AWS account page</a>.
    </dd>

    <dt>secret</dt>
    <dd>
    Required secret access key for your S3 account. You can find this under “Security
    Credentials” at your <a href="http://aws.amazon.com/account/">AWS account page</a>.
    </dd>
</dl>

<p>
See
<a href="TileStache.S3.html#Cache">TileStache.S3.Cache</a>
documentation for more information.
</p>

<h4><a id="additional-caches" name="additional-caches">Additional Caches</a></h4>

<p>
New caches with functionality that’s not strictly core to TileStache first appear in
<a href="TileStache.Goodies.Caches.html">TileStache.Goodies.Caches</a>.
</p>

<h5>LimitedDisk</h5>

<p>
Cache that stores a limited amount of data. This is an example cache that uses
a SQLite database to track sizes and last-read times for cached tiles, and
removes least-recently-used tiles whenever the total size of the cache exceeds
a set limit. See
<a href="TileStache.Goodies.Caches.LimitedDisk.html">TileStache.Goodies.Caches.LimitedDisk</a>
for more information.
</p>

<h3><a id="layers" name="layers">Layers</a></h3>

<p>
A Layer represents a set of tiles in TileStache. It keeps references to
providers, projections, a Configuration instance, and other details required
for to the storage and rendering of a tile set.
</p>

<p>
Example layer configuration:
</p>
 
<pre>
<span class="bg">{
  "cache": …,
  "layers": 
  {</span>
    "example-name":
    {
      "provider": { … },
      "metatile": { … },
      "preview": { … },
      "stale lock timeout": …,
      "cache lifespan": …,
      "projection": …,
      "write cache": …,
      "bounds": { … },
      "allowed origin": …,
      "maximum cache age": …,
      "redirects": …,
      "jpeg options": …,
      "png options": …
    }
  <span class="bg">}
}</span>
</pre>
 
<p>
The public-facing URL of a single tile for this layer might look like this:
</p>
 
<pre>
http://example.com/tilestache.cgi/example-name/0/0/0.png
</pre>

<p>
Shared layer parameters:
</p>

<dl>
    <dt>provider</dt>
    <dd>
    Refers to a Provider, explained in detail under
    <a href="#providers">Providers</a>.
    </dd>

    <dt>metatile</dt>
    <dd>
    Optionally makes it possible for multiple individual tiles to be rendered
    at one time, for greater speed and efficiency. This is commonly used for
    bitmap providers such as Mapnik. See <a href="#metatiles">Metatiles</a>
    for more information.
    </dd>

    <dt>preview</dt>
    <dd>
    Optionally overrides the starting point for the built-in per-layer slippy
    map preview, useful for image-based layers where appropriate. See
    <a href="#preview">Preview</a> for more information.
    </dd>

    <dt>projection</dt>
    <dd>
    Names a geographic projection, explained in
    <a href="#projections">Projections</a>. If omitted, defaults to
    <samp>"spherical mercator"</samp>.
    </dd>

    <dt>stale lock timeout</dt>
    <dd>
    An optional number of seconds to wait before forcing a lock that might be
    stuck. This is defined on a per-layer basis, rather than for an entire
    cache at one time, because you may have different expectations for the
    rendering speeds of different layer configurations. Defaults to
    <samp>15</samp>.
    </dd>

    <dt>cache lifespan</dt>
    <dd>
    An optional number of seconds that cached tiles should be stored. This is
    defined on a per-layer basis. Defaults to forever if <samp>None</samp>,
    <samp>0</samp> or omitted.
    </dd>

    <dt>write cache</dt>
    <dd>
    An optional boolean value to allow skipping cache write altogether.
    This is defined on a per-layer basis. Defaults to true if omitted.
    </dd>
    
    <dt>bounds</dt>
    <dd>
    An optional dictionary of six tile boundaries to limit the rendered area:
    <var>low</var> (lowest zoom level), <var>high</var> (highest zoom level),
    <var>north</var>, <var>west</var>, <var>south</var>, and <var>east</var>
    (all in degrees). When any of these are omitted, default values are
    <samp>north=89</samp>, <samp>west=-180</samp>, <samp>south=-89</samp>,
    <samp>east=180</samp>, <samp>low=0</samp>, and <samp>high=31</samp>.
    A list of dictionaries will also be accepted, indicating a set of possible
    bounding boxes any one of which includes possible tiles.
    </dd>

    <dt>allowed origin</dt>
    <dd>
    An optional string that shows up in the response HTTP header
    <a href="http://www.w3.org/TR/cors/#access-control-allow-origin-response-hea">Access-Control-Allow-Origin</a>,
    useful for when you need to provide javascript direct access to response
    data such as GeoJSON or pixel values. The header is part of a
    <a href="http://www.w3.org/TR/cors/">W3C working draft</a>.
    Pro-tip: if you want to allow maximum permissions and minimal
    security headache, use a value of <samp>"*"</samp> for this.
    </dd>

    <dt>maximum cache age</dt>
    <dd>
    An optional number of seconds used to control behavior of downstream caches.
    Causes TileStache responses to include
    <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9">Cache-Control</a>
    and <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21">Expires</a>
    HTTP response headers. Useful when TileStache is itself hosted behind an HTTP
    cache such as Squid, Cloudfront, or Akamai.
    </dd>

    <dt>redirects</dt>
    <dd>
    An optional dictionary of per-extension HTTP redirects, treated as
    lowercase. Useful in cases where your tile provider can support many
    formats but you want to enforce limits to save on cache usage. If a request
    is made for a tile with an extension in the dictionary keys, a response can
    be generated that redirects the client to the same tile with another
    extension. For example, use the setting <samp>{"jpg": "png"}</samp>
    to force all requests for JPEG tiles to be redirected to PNG tiles.
    </dd>

    <dt>jpeg options</dt>
    <dd>
    An optional dictionary of JPEG creation options, passed through
    <a href="http://www.pythonware.com/library/pil/handbook/format-jpeg.htm">to PIL</a>.
    Valid options include <var>quality</var> (integer), <var>progressive</var>
    (boolean), and <var>optimize</var> (boolean).
    </dd>

    <dt>png options</dt>
    <dd>
    An optional dictionary of PNG creation options, passed through
    <a href="http://www.pythonware.com/library/pil/handbook/format-png.htm">to PIL</a>.
    Valid options include <var>palette</var> (URL or filename) and
    <var>optimize</var> (boolean).
    </dd>
</dl>

<h3><a id="providers" name="providers">Providers</a></h3>

<p>
A Provider is the part of TileStache that stores static files to speed up
future requests. A few default providers are shown here, with additional
provider classes defined in
<a href="TileStache.Goodies.Providers.html"><code>TileStache.Goodies.Providers</code></a>
</p>

<h4><a id="mapnik-provider" name="mapnik-provider">Mapnik</a></h4>

<p>
Built-in Mapnik provider, renders map images from Mapnik XML files.
</p>
 
<p>
Example Mapnik provider configuration:
</p>

<pre>
<span class="bg">{
  "cache": { … }.
  "layers":
  {
    "roads":
    {</span>
      "provider":
      {
        "name": "mapnik", 
        "mapfile": "style.xml"
      }
    <span class="bg">}
  }
}</span>
</pre>
 
<p>
Mapnik provider parameters:
</p>

<dl>
    <dt>mapfile</dt>
    <dd>
    Required local file path to Mapnik XML file.
    </dd>
</dl>

<p>
See
<a href="TileStache.Providers.html#Mapnik">TileStache.Providers.Mapnik</a>
for more information.
</p>

<h4><a id="proxy-provider" name="proxy-provider">Proxy</a></h4>

<p>
Proxy provider, to pass through and cache tiles from other places.
</p>
 
<p>
Example Proxy provider configuration:
</p>

<pre>
<span class="bg">{
  "cache": { … }.
  "layers":
  {
    "roads":
    {</span>
      "provider":
      {
        "name": "proxy", 
        "url": "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png"
      }
    <span class="bg">}
  }
}</span>
</pre>
 
<p>
Proxy provider parameters:
</p>

<dl>
    <dt>url</dt>
    <dd>
    Optional URL template for remote tiles, for example:
    <samp>"http://tile.openstreetmap.org/{Z}/{X}/{Y}.png"</samp>
    </dd>
    <dt>provider</dt>
    <dd>
    Optional provider name string from Modest Maps built-ins. See
    <code>ModestMaps.builtinProviders.keys()</code> for a list. Example:
    <samp>"OPENSTREETMAP"</samp>.
    </dd>
</dl>

<p>
See
<a href="TileStache.Providers.html#Proxy">TileStache.Providers.Proxy</a>
for more information.
</p>

<h4><a id="vector-provider" name="vector-provider">Vector</a></h4>

<p>
Provider that returns vector representation of features in a data source.
</p>

<p>
Currently two serializations and three encodings are supported for a total
of six possible kinds of output with these tile name extensions:
</p>

<dl>
    <dt>GeoJSON (<samp>.geojson</samp>)</dt>
    <dd>
    Conforms to the <a href="http://geojson.org/geojson-spec.html">GeoJSON specification</a>.
    </dd>
    <dt>Arc GeoServices JSON (<samp>.arcjson</samp>)</dt>
    <dd>
    Conforms to ESRI’s <a href="http://www.esri.com/library/whitepapers/pdfs/geoservices-rest-spec.pdf">GeoServices REST specification</a>.
    </dd>
    <dt>GeoBSON (<samp>.geobson</samp>) and Arc GeoServices BSON (<samp>.arcbson</samp>)</dt>
    <dd>
    <a href="http://bsonspec.org/#/specification">BSON-encoded</a> GeoJSON and Arc JSON.
    </dd>
    <dt>GeoAMF (<samp>.geoamf</samp>) and Arc GeoServices AMF (<samp>.arcamf</samp>)</dt>
    <dd>
    <a href="http://opensource.adobe.com/wiki/download/attachments/1114283/amf0_spec_121207.pdf">AMF0-encoded</a> GeoJSON and Arc JSON.
    </dd>
</dl>

<p>
Example Vector provider configurations:
</p>

<pre>
<span class="bg">{
  "cache": { … }.
  "layers":
  {
    "vector-postgis-points":
    {</span>
      "provider": {"name": "vector", "driver": "PostgreSQL",
                   "parameters": {"dbname": "geodata", "user": "geodata",
                                  "table": "planet_osm_point"}}
    <span class="bg">},
    "vector-shapefile-lines":
    {</span>
      "provider": {"name": "vector", "driver": "shapefile",
                   "parameters": {"file": "oakland-uptown-line.latlon.shp"},
                   "properties": {"NAME": "name", "HIGHWAY": "highway"}}
    <span class="bg">},
    "vector-sf-streets":
    {</span>
      "provider": {"name": "vector", "driver": "GeoJSON",
                   "parameters": {"file": "stclines.json"},
                   "properties": ["STREETNAME"]}
    <span class="bg">}
  }
}</span>
</pre>
 
<p>
Vector provider parameters:
</p>

<dl>
    <dt>driver</dt>
    <dd>
    String used to identify an OGR driver. Currently, only
    <samp>"ESRI Shapefile"</samp>, <samp>"PostgreSQL"</samp>, and
    <samp>"GeoJSON"</samp> are supported as data source drivers, with
    <samp>"postgis"</samp> and <samp>"shapefile"</samp> accepted as
    synonyms. Not case-sensitive.
    </dd>
    <dt>parameters</dt>
    <dd>
    Dictionary of parameters for each driver.
    <br>
    <dl>
        <dt>PostgreSQL</dt>
        <dd>
        <samp>"dbname"</samp> parameter is required, with name of database.
        <samp>"host"</samp>, <samp>"user"</samp>, and <samp>"password"</samp>
        are optional connection parameters. One of <samp>"table"</samp> or
        <samp>"query"</samp> is required, with a table name in the first case
        and a complete SQL query in the second.
        </dd>
        <dt>Shapefile and GeoJSON</dt>
        <dd>
        <samp>"file"</samp> parameter is required, with filesystem path to
        data file.
        </dd>
    </dl>
    </dd>
    <dt>properties</dt>
    <dd>
    Optional list or dictionary of case-sensitive output property names.
    <br>
    If omitted, all fields from the data source will be included in response.
    If a list, treated as a whitelist of field names to include in response.
    If a dictionary, treated as a whitelist and re-mapping of field names.
    </dd>
    <dt>clipped</dt>
    <dd>
    Default is <samp>true</samp>.
    <br>
    Boolean flag for optionally clipping the output geometries to the
    bounds of the enclosing tile, or the string value <samp>"padded"</samp>
    for clipping to the bounds of the tile plus 5%. This results in incomplete
    geometries, dramatically smaller file sizes, and improves performance and
    compatibility with <a href="http://polymaps.org">Polymaps</a>.
    </dd>
    <dt>projected</dt>
    <dd>
    Default is <samp>false</samp>.
    <br>
    Boolean flag for optionally returning geometries in projected rather than
    geographic coordinates. Typically this means <samp>EPSG:900913</samp> a.k.a.
    spherical mercator projection. Stylistically a poor fit for GeoJSON, but
    useful when returning Arc GeoServices responses.
    </dd>
    <dt>precision</dt>
    <dd>
    Default is <samp>6</samp>.
    <br>
    Optional number of decimal places to use for floating point values.
    </dd>
    <dt>spacing</dt>
    <dd>
    Optional number of tile pixels for spacing geometries in responses. Used
    to cut down on the number of returned features by ensuring that only those
    features at least this many pixels apart are returned. Order of features
    in the data source matters: early features beat out later features.
    </dd>
    <dt>verbose</dt>
    <dd>
    Default is <samp>false</samp>.
    <br>
    Boolean flag for optionally expanding output with additional whitespace
    for readability. Results in larger but more readable GeoJSON responses.
    </dd>
</dl>

<p>
See
<a href="TileStache.Vector.html">TileStache.Vector</a>
for more information.
</p>

<h4><a id="url-template-provider" name="url-template-provider">URL Template</a></h4>

<p>
Templated URL provider, to pass through and cache tiles from WMS servers.
</p>
 
<p>
Example UrlTemplate provider configuration:
</p>

<pre>
<span class="bg">{
  "cache": { … }.
  "layers":
  {
    "roads":
    {</span>
      "provider":
      {
        "name": "url template", 
        "template": "http://example.com/?bbox=$xmin,$ymin,$xmax,$ymax"
      }
    <span class="bg">}
  }
}</span>
</pre>
 
<p>
UrlTemplate provider parameters:
</p>

<dl>
    <dt>template</dt>
    <dd>
    String with substitutions suitable for use in
    <a href="http://docs.python.org/library/string.html#string.Template">string.Template</a>.
    The variables available for substitution are <var>width</var>,
    <var>height</var> (in pixels), <var>srs</var> (in
    <a href="http://trac.osgeo.org/proj/wiki/GenParms">PROJ.4 format</a>),
    <var>xmin</var>, <var>ymin</var>, <var>xmax</var>, <var>ymax</var> (in
    projected map units), and <var>zoom</var>.
    Example:
    <samp>"http://example.com/?bbox=$xmin,$ymin,$xmax,$ymax&bboxSR=102113&size=$width,$height&imageSR=102113&format=jpg&f=image"</samp>.
    </dd>
    <dt>referer</dt>
    <dd>
    Optional string with HTTP Referer URL to send to WMS server.
    Some WMS servers use the Referer request header to authenticate requests;
    this parameter provides one.
    </dd>
</dl>

<p>
See
<a href="TileStache.Providers.html#UrlTemplate">TileStache.Providers.UrlTemplate</a>
for more information.
</p>

<h4><a id="mbtiles-provider" name="mbtiles-provider">MBTiles</a></h4>

<p>
Provider that reads stored images from <a href="http://mbtiles.org/">MBTiles tilesets</a>.
</p>
 
<p>
Example MBTiles provider configuration:
</p>

<pre>
<span class="bg">{
  "cache": { … }.
  "layers":
  {
    "roads":
    {</span>
      "provider":
      {
        "name": "mbtiles", 
        "tileset": "collection.mbtiles"
      }
    <span class="bg">}
  }
}</span>
</pre>
 
<p>
MBTiles provider parameters:
</p>

<dl>
    <dt>tileset</dt>
    <dd>
    Required local file path to MBTiles tileset file, a SQLite 3 database file.
    </dd>
</dl>

<p>
See
<a href="TileStache.MBTiles.html#Provider">TileStache.MBTiles.Provider</a>
for more information.
</p>

<h4><a id="additional-providers" name="additional-providers">Additional Providers</a></h4>

<p>
New providers with functionality that’s not strictly core to TileStache first appear in
<a href="TileStache.Goodies.Providers.html">TileStache.Goodies.Providers</a>.
</p>

<h5>Grid</h5>

<p>
Grid rendering for TileStache. UTM provider draws gridlines in tiles,
in transparent images suitable for use as map overlays. See
<a href="TileStache.Goodies.Providers.Grid.html">TileStache.Goodies.Providers.Grid</a>
for more information.
</p>

<h5>PostGeoJSON</h5>

<p>
Provider that returns GeoJSON data responses from PostGIS queries. This is an
example of a provider that does not return an image, but rather queries a
database for raw data and replies with a string of GeoJSON. For example, it’s
possible to retrieve data for locations of OpenStreetMap points of interest
based on a query with a bounding box intersection. See
<a href="TileStache.Goodies.Providers.PostGeoJSON.html">TileStache.Goodies.Providers.PostGeoJSON</a>
for more information.
</p>

<h5>SolrGeoJSON</h5>

<p>
Provider that returns GeoJSON data responses from Solr spatial queries. This is
an example of a provider that does not return an image, but rather queries a
Solr instance for raw data and replies with a string of GeoJSON. See
<a href="TileStache.Goodies.Providers.SolrGeoJSON.html">TileStache.Goodies.Providers.SolrGeoJSON</a>
for more information.
</p>

<h5>Composite</h5>

<p>
Layered, composite rendering for TileStache. See
<a href="TileStache.Goodies.Providers.Composite.html">TileStache.Goodies.Providers.Composite</a>
for more information.
</p>

<h5>MirrorOSM</h5>

<p>
Requests for tiles have the side effect of running
<a href="http://wiki.openstreetmap.org/wiki/Osm2pgsql">osm2pgsql</a> to populate
a PostGIS database of OpenStreetMap data from a remote API source. It would be
normal to use this provider outside the regular confines of a web server,
perhaps with a call to <code>tilestache-seed.py</code> governed by a cron job or
some other out-of-band process. See
<a href="TileStache.Goodies.Providers.MirrorOSM.html">TileStache.Goodies.Providers.MirrorOSM</a>
for more information.
</p>

<h3><a id="projections" name="projections">Projections</a></h3>

<p>
A Projection defines the relationship between the rendered tiles and the
underlying geographic data. Generally, just one popular projection is used for
most web maps, <samp>"spherical mercator"</samp>.
</p>

<p>
Provided projections:
</p>

<dl>
    <dt>spherical mercator</dt>
    <dd>
    Projection for most commonly-used web map tile scheme, equivalent to
    <code>EPSG:900913</code>. The simplified projection used here is described
    in greater detail at
    <a href="http://trac.openlayers.org/wiki/SphericalMercator">openlayers.org</a>.
    </dd>
    
    <dt>WGS84</dt>
    <dd>
    Unprojected projection for the other commonly-used web map tile scheme,
    equivalent to <code>EPSG:4326</code>.
    </dd>
</dl>

<p>
You can define your own projection, with a module and object name as arguments:
</p>

<pre>
<span class="bg">"layer-name": {
    ...</span>
    "projection": "Module:Object",
<span class="bg">}</span>
</pre>

<p>
The object must include methods that convert between coordinates, points, and
locations. See the included mercator and WGS84 implementations for example.
You can also instantiate a projection class using this syntax:
</p>

<pre>
<span class="bg">"layer-name": {
    ...</span>
    "projection": "Module:Object()"
<span class="bg">}</span>
</pre>

<p>
See
<a href="TileStache.Geography.html">TileStache.Geography</a>
for more information.
</p>

<h4><a id="metatiles" name="metatiles">Metatiles</a></h4>

<p>
Metatiles are larger areas to be rendered at one time, often used because it’s
more efficient to render a large number of contiguous tiles at once than each
one separately.
</p>
 
<p>
Example metatile configuration:
</p>

<pre>
<span class="bg">{
  "cache": …,
  "layers": 
  {
    "example-name":
    {
      "provider": { … },</span>
      "metatile": 
      {
        "rows": 4,
        "columns": 4,
        "buffer": 64
      }
    <span class="bg">}
  }
}</span>
</pre>

<p>
This example metatile is four rows tall and four columns wide with a buffer
of 64 pixels, for a total bitmap size of 4 × 256 + 64 × 2 = <strong>1152</strong>.
</p>

<p>
Metatile parameters:
</p>

<dl>
    <dt>rows</dt>
    <dd>
    Height of the metatile measured in tiles.
    </dd>

    <dt>columns</dt>
    <dd>
    Width of the metatile measured in tiles.
    </dd>

    <dt>buffer</dt>
    <dd>
    Buffer area around the metatile, measured in pixels. This is useful for
    providers with labels or icons, where it’s necessary to draw a bit extra
    around the edges to ensure that text is not cut off.
    </dd>
</dl> 

<h4><a id="preview" name="preview">Preview</a></h4>

<p>
TileStache includes a built-in slippy map preview, that can be viewed in a
browser using the URL <samp>/{layer name}/preview.html</samp>, e.g.
<samp>http://example.org/example-name/preview.html</samp>. The settings for
this preview are completely optional, but can be set on a per-layer basis
for control over starting location and file extension.
</p>
 
<p>
Example preview configuration:
</p>

<pre>
<span class="bg">{
  "cache": …,
  "layers": 
  {
    "example-name":
    {
      "provider": { … },</span>
      "preview": 
      {
        "lat": 37.80439,
        "lon": -122.27127,
        "zoom": 15,
        "ext": "jpg"
      }
    <span class="bg">}
  }
}</span>
</pre>

<p>
This example preview displays JPG tiles, and is centered on
<a href="http://osm.org/go/TZNQsg5C--">37.80439, -122.27127 at zoom 15</a>.
</p>

<p>
Preview parameters:
</p>

<dl>
    <dt>lat</dt>
    <dd>
    Starting latitude in degrees.
    </dd>

    <dt>lon</dt>
    <dd>
    Starting longitude in degrees.
    </dd>

    <dt>zoom</dt>
    <dd>
    Starting zoom level.
    </dd>

    <dt>ext</dt>
    <dd>
    Filename extension, e.g. <samp>"png"</samp>.
    </dd>
</dl> 

<h4><a id="index-page" name="index-page">Index Page</a></h4>

<p>
TileStache supports configurable index pages for the front page of an instance.
A custom index can be specified as a filename relative to the configuration
location. Typically an HTML document would be given here, but other kinds of
files such as images can be used, with MIME content-type headers determined by
<a href="http://docs.python.org/library/mimetypes.html#mimetypes.guess_type">mimetypes.guess_type</a>.
A simple text greeting is displayed if no index is provided.
</p>
 
<p>
Example index page configuration:
</p>

<pre>
<span class="bg">{
  "cache": …,
  "layers": …,</span>
  "index": "filename.html"
  <span class="bg">}
}</span>
</pre>

<p>
Example index page configuration using a remote image:
</p>

<pre>
<span class="bg">{
  "cache": …,
  "layers": …,</span>
  "index": "http://tilestache.org/mustaches.jpg"
  <span class="bg">}
}</span>
</pre>

<h4><a id="logging" name="logging">Logging</a></h4>

<p>
TileStache includes basic support for Python’s built-in
<a href="http://docs.python.org/library/logging.html">logging system</a>, with
a logging level settable in the main configuration file. Possible logging levels
include <samp>"debug"</samp>, <samp>"info"</samp>, <samp>"warning"</samp>,
<samp>"error"</samp> and <samp>"critical"</samp>, described in the
<a href="http://docs.python.org/howto/logging.html">basic logging tutorial</a>.
</p>
 
<p>
Example logging configuration:
</p>

<pre>
<span class="bg">{
  "cache": …,
  "layers": …,</span>
  "logging": "debug"
  <span class="bg">}
}</span>
</pre>

<h2><a id="extending-tilestache" name="extending-tilestache">Extending TileStache</a></h2>

<p>
TileStache relies on <a href="http://en.wikipedia.org/wiki/Duck_typing">duck typing</a>
rather than inheritance for extensibility, so all guidelines for customization
below explain what methods and properties must be defined on objects for them
to be valid as providers, caches, and configurations.
</p>

<h3><a id="custom-providers" name="custom-providers">Providers</a></h3>

<p>
Example external provider configuration:
</p>
 
<pre>
<span class="bg">{
  "cache": …,
  "layers": 
  {
    "example-name":
    {</span>
      "provider":
      {
        "class": "Module:Classname",
        "kwargs": {"frob": "yes"}
      }
    <span class="bg">}
  }
}</span>
</pre>

<p>
The <var>class</var> value is split up into module and classname, and
dynamically included. If this doesn’t work for some reason, TileStache will
fail loudly to let you know. The <var>kwargs</var> value is fed to the class
constructor as a dictionary of keyword args. If your defined class doesn’t
accept any of these keyword arguments, TileStache will throw an exception.
</p>

<p>
A provider must offer at least one of two methods for rendering map areas:
<code>renderTile</code> or <code>renderArea</code>. A provider must also accept
an instance of <code>Layer</code> as the first argument to its constructor.
</p>

<p>
Return value of both <code>renderTile</code> and <code>renderArea</code> is an
object with a <code>save</code> method that can accept a file-like object and
a format name, typically an instance of the <code>PIL.Image</code> object but
allowing for creation of providers that save text, raw data or other non-image
response.
</p>

<p>
A minimal provider stub class:
</p>

<pre>
class ProviderStub:

  def __init__(self, layer):
    # create a new provider for a layer
    raise NotImplementedError
    
  def renderTile(self, width, height, srs, coord):
    # return an object with a PIL-like save() method for a tile
    raise NotImplementedError
    
  def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
    # return an object with a PIL-like save() method for an area
    raise NotImplementedError
</pre>

<p>
In cases where a provider generates a response that should not be cached,
<code>renderTile</code> and <code>renderArea</code> may raise the
<a href="TileStache.Core.html#NoTileLeftBehind">Core.NoTileLeftBehind</a>
exception in lieu of a normal response. The exception is constructed using the
intended response object, but nothing will be written to cache. This feature
might useful in cases where a full tileset is being rendered for static
hosting, and you don’t want millions of identical ocean tiles.
</p>

<p>
See
<a href="TileStache.Providers.html">TileStache.Providers</a>
for more information on custom providers and
<a href="TileStache.Goodies.Providers.html">TileStache.Goodies.Providers</a>
for examples of custom providers.
</p>

<h4><a id="provider-rendertile" name="provider-rendertile"><code>provider.renderTile</code></a></h4>

<p>
Draws a single tile at a time.
</p>

<p>
Arguments to <code>renderTile</code>:
</p>

<dl>
    <dt>width</dt>
    <dd>
    Pixel width of tile, typically <samp>256</samp>.
    </dd>
    
    <dt>height</dt>
    <dd>
    Pixel height of tile, typically <samp>256</samp>.
    </dd>
    
    <dt>srs</dt>
    <dd>
    Projection as Proj4 string.
    <samp>"+proj=longlat +ellps=WGS84 +datum=WGS84"</samp> is an example, see
    <a href="TileStache.Geography.html">TileStache.Geography</a>
    for actual values.
    </dd>
    
    <dt>coord</dt>
    <dd>
    Coordinate object representing a single tile.
    </dd>
</dl>

<p>
Return value of <code>renderTile</code> is a
<a href="http://www.pythonware.com/library/pil/handbook/image.htm#Image.save"><code>PIL.Image</code></a>
or other saveable object, used like this:
</p>

<pre>
provider.renderTile(…).save(file, "XML")
</pre>
 
<h4><a id="provider-renderarea" name="provider-renderarea"><code>provider.renderArea</code></a></h4>

<p>
Draws a variably-sized area, and is used when drawing metatiles.
</p>

<p>
Non-image providers and metatiles do not mix. If your provider returns JSON,
plaintext, XML, or some other non-PIL format, implement only the
<code>renderTile</code> method.
</p>

<p>
Arguments to <code>renderArea</code>:
</p>

<dl>
    <dt>width</dt>
    <dd>
    Pixel width of tile, typically <samp>256</samp>.
    </dd>
    
    <dt>height</dt>
    <dd>
    Pixel height of tile, typically <samp>256</samp>.
    </dd>
    
    <dt>srs</dt>
    <dd>
    Projection as Proj4 string.
    <samp>"+proj=longlat +ellps=WGS84 +datum=WGS84"</samp> is an example, see
    <a href="TileStache.Geography.html">TileStache.Geography</a>
    for actual values.
    </dd>
    
    <dt>xmin</dt>
    <dd>
    Minimum <var>x</var> boundary of rendered area in projected coordinates.
    </dd>
    
    <dt>ymin</dt>
    <dd>
    Minimum <var>y</var> boundary of rendered area in projected coordinates.
    </dd>
    
    <dt>xmax</dt>
    <dd>
    Maximum <var>x</var> boundary of rendered area in projected coordinates.
    </dd>
    
    <dt>ymax</dt>
    <dd>
    Maximum <var>y</var> boundary of rendered area in projected coordinates.
    </dd>
    
    <dt>zoom</dt>
    <dd>
    Zoom level of final map. Technically this can be derived from the other
    arguments, but that’s a hassle so we’ll pass it in explicitly.
    </dd>
</dl>

<p>
Return value of <code>renderArea</code> is a
<a href="http://www.pythonware.com/library/pil/handbook/image.htm#Image.save"><code>PIL.Image</code></a>
or other saveable object, used like this:
</p>

<pre>
provider.renderArea(…).save(file, "PNG")
</pre>

<h4><a id="provider-gettypebyextension" name="provider-gettypebyextension"><code>provider.getTypeByExtension</code></a></h4>

<p>
A provider may offer a method for custom response types,
<code>getTypeByExtension</code>. This method returns a tuple with two strings:
a mime-type and a format.
</p>

<p>
Arguments to <code>getTypeByExtension</code>:
</p>

<dl>
    <dt>extension</dt>
    <dd>
    Filename extension string, e.g. <samp>"png"</samp>, <samp>"json"</samp>, etc.
    </dd>
</dl>

<h3><a id="custom-caches" name="custom-caches">Caches</a></h3>

<p>
Example external provider configuration:
</p>
 
<pre>
<span class="bg">{</span>
  "cache":
  {
    "class": "Module:Classname",
    "kwargs": {"frob": "yes"}
  },
  <span class="bg">"layers": { … }
}</span>
</pre>

<p>
The <var>class</var> value is split up into module and classname, and
dynamically included. If this doesn’t work for some reason, TileStache will
fail loudly to let you know. The <var>kwargs</var> value is fed to the class
constructor as a dictionary of keyword args. If your defined class doesn’t
accept any of these keyword arguments, TileStache will throw an exception.
</p>

<p>
A cache must provide all of these five methods: <code>lock</code>,
<code>unlock</code>, <code>remove</code>, <code>read</code>, and <code>save</code>.
</p>

<p>
Each method requires three arguments:
</p>

<dl>
    <dt>layer</dt>
    <dd>
    Instance of a layer.
    </dd>

    <dt>coord</dt>
    <dd>
    Single Coordinate that represents a tile.
    </dd>

    <dt>format</dt>
    <dd>
    String like <samp>"png"</samp> or <samp>"jpg"</samp> that is used as a
    filename extension.
    </dd>
</dl>
 
<p>
The <code>save</code> method accepts an additional argument <i>before the others</i>:
</p>
 
<dl>
    <dt>body</dt>
    <dd>
    Raw content to save to the cache.
    </dd>
</dl>

<p>
A minimal cache stub class:
</p>

<pre>
class CacheStub:

  def lock(self, layer, coord, format):
    # lock a tile
    raise NotImplementedError

  def unlock(self, layer, coord, format):
    # unlock a tile
    raise NotImplementedError

  def remove(self, layer, coord, format):
    # remove a tile
    raise NotImplementedError

  def read(self, layer, coord, format):
    # return raw tile content from cache
    raise NotImplementedError
  
  def save(self, body, layer, coord, format):
    # save raw tile content to cache
    raise NotImplementedError
</pre>

<p>
See
<a href="TileStache.Caches.html">TileStache.Caches</a>
for more information on custom caches and
<a href="TileStache.Goodies.Caches.html">TileStache.Goodies.Caches</a>
for examples of custom caches.
</p>

<h3><a id="custom-configuration" name="custom-configuration">Configuration</a></h3>

<p>
A complete configuration object includes <var>cache</var>,
<var>layers</var>, and <var>dirpath</var> properties and
optional <var>index</var> property:
</p>
 
<dl>
    <dt>cache</dt>
    <dd>
    Cache instance, e.g.
    <code><a href="TileStache.Caches.html#Disk">TileStache.Caches.Disk</a></code>
    etc. See
    <a href="TileStache.Caches.html">TileStache.Caches</a>
    for details on what makes a usable cache.
    </dd>

    <dt>layers</dt>
    <dd>
    Dictionary of layers keyed by name. 
    </dd>

    <dt>dirpath</dt>
    <dd>
    Local filesystem path for this configuration, useful for expanding relative
    paths.
    </dd>

    <dt>index</dt>
    <dd>
    Two-element tuple with mime-type and content for installation index page.
    </dd>
</dl>

<p>
When creating a custom <var>layers</var> dictionary, e.g. for dynamic layer
collections backed by some external configuration, these
<a href="http://docs.python.org/library/stdtypes.html#mapping-types-dict">dictionary methods</a>
must be provided for a complete collection of layers:
</p>
 
<dl>
    <dt>keys</dt>
    <dd>
    Return list of layer name strings.
    </dd>

    <dt>items</dt>
    <dd>
    Return list of (name, layer) pairs.
    </dd>

    <dt>__contains__</dt>
    <dd>
    Return boolean true if given key is an existing layer.
    </dd>

    <dt>__getitem__</dt>
    <dd>
    Return existing layer object for given key or raise <code>KeyError</code>.
    </dd>
</dl>

<p>
A minimal layers dictionary stub class:
</p>

<pre>
class LayersStub:

  def keys(self):
    # return a list of key strings
    raise NotImplementedError

  def items(self):
    # return a list of (key, layer) tuples
    raise NotImplementedError

  def __contains__(self, key):
    # return True if the key is here
    raise NotImplementedError
  
  def __getitem__(self, key):
    # return the layer named by the key
    raise NotImplementedError
</pre>

</body>
</html>