forked from TileStache/TileStache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.html
2248 lines (1907 loc) · 61.2 KB
/
API.html
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
<!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; }
a.permalink
{
font-weight: normal;
text-decoration: none;
opacity: 0.35;
}
-->
</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 N.N.N</strong>.
</p>
<p>
See also <a href="http://tilestache.org/doc/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>
<li><a href="#mapnik-grid-provider">Mapnik Grid</a></li>
<li><a href="#sandwich-provider">Pixel Sandwich</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> <a href="#requesting-tiles" class="permalink">¶</a></h2>
<h3><a id="over-http" name="over-http">Over HTTP</a> <a href="#over-http" class="permalink">¶</a></h3>
<p>
TileStache URLs are based on a Google Maps-like 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> <a href="#in-code" class="permalink">¶</a></h3>
<h4><a id="tilestache-gettile" name="tilestache-gettile"><code>TileStache.getTile</code></a> <a href="#tilestache-gettile" class="permalink">¶</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="http://tilestache.org/doc/TileStache.html#-getTile">TileStache.getTile</a>
documentation for more information.
</p>
<h4><a id="tilestache-requesthandler" name="tilestache-requesthandler"><code>TileStache.requestHandler</code></a> <a href="#tilestache-requesthandler" class="permalink">¶</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="http://tilestache.org/doc/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>
<dt>script_name</dt>
<dd>
Optional script name corresponds to CGI environment variable <var>SCRIPT_NAME</var>, used to calculate correct 302 redirects.
</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="http://tilestache.org/doc/TileStache.html#-requestHandler">TileStache.requestHandler</a>
documentation for more information.
</p>
<h2><a id="serving-tiles" name="serving-tiles">Serving Tiles</a> <a href="#serving-tiles" class="permalink">¶</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> <a href="#wsgi" class="permalink">¶</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>The same configuration can be served with <a
href="http://projects.unbit.it/uwsgi/">uWSGI</a> like so. Note the
usage of the <tt>--eval</tt> option over <tt>--module</tt> as this latter
option does not support argument passing:
<pre>
$ uwsgi --http :8080 --eval 'import TileStache; \
application = TileStache.WSGITileServer("/path/to/tilestache.cfg")'
</pre>
<p>
See
<a href="http://tilestache.org/doc/TileStache.html#WSGITileServer"><code>TileStache.WSGITileServer</code></a>
documentation for more information.
</p>
<h4><a id="cgi" name="cgi">CGI</a> <a href="#cgi" class="permalink">¶</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="http://tilestache.org/doc/TileStache.html#-cgiHandler"><code>TileStache.cgiHandler</code></a>
documentation for more information.
</p>
<h4><a id="mod-python" name="mod-python">mod_python</a> <a href="#mod-python" class="permalink">¶</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>
<Directory /var/www/tiles>
AddHandler mod_python .py
PythonHandler TileStache::modpythonHandler
PythonOption config /etc/tilestache.cfg
</Directory>
</pre>
<p>
See
<a href="http://tilestache.org/doc/TileStache.html#-modPythonHandler"><code>TileStache.modPythonHandler</code></a>
documentation for more information.
</p>
<h2><a id="configuring-tilestache" name="configuring-tilestache">Configuring TileStache</a> <a href="#configuring-tilestache" class="permalink">¶</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> <a href="#caches" class="permalink">¶</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="http://tilestache.org/doc/TileStache.Goodies.Caches.html"><code>TileStache.Goodies.Caches</code></a>.
</p>
<p>
Jump to <a href="#test-cache">Test</a>, <a href="#disk-cache">Disk</a>,
<a href="#multi-cache">Multi</a>, <a href="#memcache-cache">Memcache</a>,
<a href="#redis-cache">Redis</a>,
or <a href="#s3-cache">S3</a> cache.
</p>
<h4><a id="test-cache" name="test-cache">Test</a> <a href="#test-cache" class="permalink">¶</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="http://tilestache.org/doc/TileStache.Caches.html#Test">TileStache.Caches.Test</a>
documentation for more information.
</p>
<h4><a id="disk-cache" name="disk-cache">Disk</a> <a href="#disk-cache" class="permalink">¶</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="http://tilestache.org/doc/TileStache.Caches.html#Disk">TileStache.Caches.Disk</a>
documentation for more information.
</p>
<h4><a id="multi-cache" name="multi-cache">Multi</a> <a href="#multi-cache" class="permalink">¶</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="http://tilestache.org/doc/TileStache.Caches.html#Multi">TileStache.Caches.Multi</a>
documentation for more information.
</p>
<h4><a id="memcache-cache" name="memcache-cache">Memcache</a> <a href="#memcache-cache" class="permalink">¶</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,
"key prefix": "unique-id"
}<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>
<dt>key prefix</dt>
<dd>
Optional string to prepend to Memcache generated key.
Useful when running multiple instances of TileStache
that share the same Memcache instance to avoid key
collisions. The key prefix will be prepended to the
key name. Defaults to <samp>""</samp>.
</dd>
</dl>
<p>
See
<a href="http://tilestache.org/doc/TileStache.Memcache.html#Cache">TileStache.Memcache.Cache</a>
documentation for more information.
</p>
<h4><a id="redis-cache" name="redis-cache">Redis</a> <a href="#redis-cache" class="permalink">¶</a></h4>
<p>
Caches tiles to <a href="http://redis.io/">Redis</a>,
requires <a href="https://pypi.python.org/pypi/redis/">redis-py</a> and <a href="http://redis.io/">redis server</a>.
</p>
<p>
Example configuration:
</p>
<pre>
<span class="bg">
{</span>
"cache": {
"name": "Redis",
"host": "localhost",
"port": 6379,
"db": 0,
"key prefix": "unique-id"
}<span class="bg">,
"layers": { … }
}</span>
</pre>
<p>
Redis cache parameters:
</p>
<dl>
<dt>host</dt>
<dd>
Defaults to <samp>"localhost"</samp> if omitted.
</dd>
<dt>port</dt>
<dd>
Integer; Defaults to <samp>6379</samp> if omitted.
</dd>
<dt>db</dt>
<dd>
Integer; Redis database number, defaults to <samp>0</samp> if omitted.
</dd>
<dt>key prefix</dt>
<dd>
Optional string to prepend to generated key.
Useful when running multiple instances of TileStache
that share the same Redis database to avoid key
collisions (though the prefered solution is to use a different
db number). The key prefix will be prepended to the
key name. Defaults to <samp>""</samp>.
</dd>
</dl>
<p>
See
<a href="http://tilestache.org/doc/TileStache.Redis.html#Cache">TileStache.Redis.Cache</a>
documentation for more information.
</p>
<h4><a id="s3-cache" name="s3-cache">S3</a> <a href="#s3-cache" class="permalink">¶</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": "<bucket name>",
"access": "<access key>",
"secret": "<secret key>"
"reduced_redundancy": False
}<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>
Optional 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>
Optional 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>
<dt>use_locks</dt>
<dd>
Optional boolean flag for whether to use the locking feature on S3.
<samp>True</samp> by default. A good reason to set this to
<samp>false</samp> would be the additional price and time required for each
lock set in S3.
</dd>
<dt>path</dt>
<dd>
Optional path under bucket to use as the cache directory. ex. <samp>'path': 'cache'</samp> will
put tiles under <samp>{bucket}/cache/</samp>
</dd>
<dt>reduced_redundancy</dt>
<dd>
Optional boolean specifying whether to use Reduced Redundancy Storage mode in S3.
Files stored with RRS incur less cost but have reduced redundancy in Amazon's storage
system.
</dd>
</dl>
<p>
When access or secret are not provided, the environment variables
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY will be used.
See <a href="http://docs.pythonboto.org/en/latest/s3_tut.html#creating-a-connection">Boto documentation</a>
for more information.
</p>
<p>
See
<a href="http://tilestache.org/doc/TileStache.S3.html#Cache">TileStache.S3.Cache</a>
documentation for more information.
</p>
<h4><a id="additional-caches" name="additional-caches">Additional Caches</a> <a href="#additional-caches" class="permalink">¶</a></h4>
<p>
New caches with functionality that’s not strictly core to TileStache first appear in
<a href="http://tilestache.org/doc/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="http://tilestache.org/doc/TileStache.Goodies.Caches.LimitedDisk.html">TileStache.Goodies.Caches.LimitedDisk</a>
for more information.
</p>
<h3><a id="layers" name="layers">Layers</a> <a href="#layers" class="permalink">¶</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": …,
"tile height": …,
"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>tile height</dt>
<dd>
An optional integer gives the height of the image tile in pixels. You
almost always want to leave this at the default value of <samp>256</samp>,
but you can use a value of <samp>512</samp> to create double-size,
double-resolution tiles for high-density phone screens.
</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), <var>palette256</var>
(boolean) and <var>optimize</var> (boolean).
</dd>
</dl>
<h3><a id="providers" name="providers">Providers</a> <a href="#providers" class="permalink">¶</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="http://tilestache.org/doc/TileStache.Goodies.Providers.html"><code>TileStache.Goodies.Providers</code></a>
</p>
<p>
Jump to <a href="#mapnik-provider">Mapnik (image)</a>, <a href="#proxy-provider">Proxy</a>,
<a href="#vector-provider">Vector</a>, <a href="#url-template-provider">URL Template</a>,
<a href="#mbtiles-provider">MBTiles</a>, <a href="#mapnik-grid-provider">Mapnik (grid)</a>,
or <a href="#sandwich-provider">Pixel Sandwich</a> provider.
</p>
<h4><a id="mapnik-provider" name="mapnik-provider">Mapnik</a> <a href="#mapnik-provider" class="permalink">¶</a></h4>
<p>
Built-in Mapnik provider, renders map images from Mapnik XML files.
</p>
<p>