TileStache.Config module¶
The configuration bits of TileStache.
TileStache configuration is stored in JSON files, and is composed of two main top-level sections: “cache” and “layers”. There are examples of both in this minimal sample configuration:
- {
“cache”: {“name”: “Test”}, “layers”: {
- “example”: {
- “provider”: {“name”: “mapnik”, “mapfile”: “examples/style.xml”},, “projection”: “spherical mercator”
}
}
}
The contents of the “cache” section are described in greater detail in the TileStache.Caches module documentation. Here is a different sample:
- “cache”: {
- “name”: “Disk”, “path”: “/tmp/stache”, “umask”: “0000”
}
The “layers” section is a dictionary of layer names which are specified in the URL of an individual tile. More detail on the configuration of individual layers can be found in the TileStache.Core module documentation. Another sample:
- {
“cache”: ..., “layers”: {
“example-name”: {
“provider”: { ... }, “metatile”: { ... }, “preview”: { ... }, “stale lock timeout”: ..., “projection”: ...}
}
}
Configuration also supports these additional settings:
- “logging”: one of “debug”, “info”, “warning”, “error” or “critical”, as described in Python’s logging module: http://docs.python.org/howto/logging.html
- “index”: 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 mimetypes.guess_type. A simple text greeting is displayed if no index is provided.
In-depth explanations of the layer components can be found in the module documentation for TileStache.Providers, TileStache.Core, and TileStache.Geography.
-
class
TileStache.Config.Bounds(upper_left_high, lower_right_low)¶ Coordinate bounding box for tiles.
-
excludes(tile)¶ Check a tile Coordinate against the bounds, return true/false.
-
-
class
TileStache.Config.BoundsList(bounds)¶ Multiple coordinate bounding boxes for tiles.
-
excludes(tile)¶ Check a tile Coordinate against the bounds, return false if none match.
-
-
class
TileStache.Config.Configuration(cache, dirpath)¶ A complete site configuration, with a collection of Layer objects.
Attributes:
- cache:
- Cache instance, e.g. TileStache.Caches.Disk etc. See TileStache.Caches for details on what makes a usable cache.
- layers:
Dictionary of layers keyed by name.
When creating a custom layers dictionary, e.g. for dynamic layer collections backed by some external configuration, these dictionary methods must be provided for a complete collection of layers:
- keys():
- Return list of layer name strings.
- items():
- Return list of (name, layer) pairs.
- __contains__(key):
- Return boolean true if given key is an existing layer.
- __getitem__(key):
- Return existing layer object for given key or raise KeyError.
- dirpath:
- Local filesystem path for this configuration, useful for expanding relative paths.
Optional attribute:
- index:
- Mimetype, content tuple for default index response.
-
TileStache.Config.buildConfiguration(config_dict, dirpath='.')¶ Build a configuration dictionary into a Configuration object.
The second argument is an optional dirpath that specifies where in the local filesystem the parsed dictionary originated, to make it possible to resolve relative paths. It might be a path or more likely a full URL including the “file://” prefix.
-
TileStache.Config.enforcedLocalPath(relpath, dirpath, context='Path')¶ Return a forced local path, relative to a directory.
Throw an error if the combination of path and directory seems to specify a remote path, e.g. “/path” and “http://example.com”.
Although a configuration file can be parsed from a remote URL, some paths (e.g. the location of a disk cache) must be local to the server. In cases where we mix a remote configuration location with a local cache location, e.g. “http://example.com/tilestache.cfg”, the disk path must include the “file://” prefix instead of an ambiguous absolute path such as “/tmp/tilestache”.