source: TI02-CSML/trunk/services/3rdParty/tilecache-1.4/HACKING @ 2202

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/tilecache-1.4/HACKING@2202
Revision 2202, 3.4 KB checked in by lawrence, 13 years ago (diff)

Adding tilecache to the "interesting" OGC services already implemented
in python.

Line 
1Handlers
2========
3There are two handlers for requests: a cgiHandler and a modPythonHandler.
4These two handlers allow the TileCache tool to be set up under CGI or
5mod_python. A handler accepts a Service as an argument. 
6
7Services
8========
9The service request does dispatching to a Request handler, passing on
10the neccesary information to the parser and renderers of the request.
11The Service contains information about the cache and layers that are
12supported, and uses methods on the Request to generate data which
13is returned to the handlers.
14
15The Service makes a heuristic determination as to which Request handler
16is appropriate. 
17
18Requests
19========
20Request objects define a single 'parse' function, which is used to
21accept PATH_INFO and QUERY_STRING data from the Service, and convert
22it to tiles.
23
24Cache
25=====
26Cache objects are simple interfaces to cache storage mechanisms. They
27support three functions: get, set, and delete. These three functions
28are used to control the cache
29 
30 * get accepts a tile object, and is expected to return image data
31   or 'None'
32 * set accepts a tile object and data, and is expected to store this
33   data.
34 * delete accepts a tile object, and should cause future gets for
35   that tile to return None (until set again)
36
37Layers
38======
39You can create a layer:
40
41>>> from TileCache.Layer import Layer
42>>> l = Layer("Test")
43>>> type(l)
44<class 'TileCache.Layer.Layer'>
45
46There are a number of defaults on the layer. These defaults conform to the
47unprojected global profile described by the WMS Tiling Client Recommendations:
48
49>>> l.name
50'Test'
51>>> l.layers
52'Test'
53>>> l.bbox
54(-180, -90, 180, 90)
55>>> l.resolutions[0]
560.703125
57>>> l.srs
58'EPSG:4326'
59>>> l.size
60(256, 256)
61
62By default, the Layer supports up to 20 resolutions, or 'zoom levels'. 
63>>> len(l.resolutions)
6420
65
66However, you can create a layer which overrides these parameters:
67
68>>> l = Layer("Test 2", layers="foo,bar,baz", levels=10)
69>>> l.layers
70'foo,bar,baz'
71>>> len(l.resolutions)
7210
73
74There are a number of subclasses of layer, which add additional properties
75for the layers. Subclasses of layer define a rendering mechanism through which
76tiles are actually created.
77
78To create a subclass of layer, you must define a 'render' function. 
79Render is passed a 'self' object of the layer, and a Tile object, described
80later in this document. Refer to the existing layers for examples of how to
81create a subclass of layer.
82
83Layers have the ability to get a tile cell based on a bounding box: this
84calculation can be exact or it can round to the nearest cell. This is used
85internally when creating tiles, but can also be used directly by calling
86the layer with a bounding box.
87
88>>> cell = l.getCell((-157.5, -45.0, -135.0, -22.5))
89>>> cell
90(1, 2, 3)
91
92This fails, because it's not an exact tile:
93
94>>> l.debug = False
95>>> cell = l.getCell((-180, -90.0, 0, 85))
96>>> l.debug = True
97>>> cell == None
98True
99
100However, this succeeds, because the 'exact' parameter is set to 'False',
101so calculations are rounded to the nearest cell:
102 
103>>> cell = l.getCell((-180, -90.0, 0, 85), exact=False)
104>>> cell
105(0, 0, 0)
106
107
108Tiles
109=====
110Tiles store information about where in the world you are requesting, based
111on the layer and x,y,z information. Tiles give access to X, Y, and Z value, as
112well as a bounds() and bbox() method.
113
114
115>>> from TileCache.Layer import Tile
116>>> t = Tile(l, x=1, y=2, z=3)
117>>> t.bbox()
118'-157.5,-45.0,-135.0,-22.5'
119>>> t.bounds()
120(-157.5, -45.0, -135.0, -22.5)
Note: See TracBrowser for help on using the repository browser.