def wsgiApp(environ, start_response): global theService cfgs = cfgfiles if not theService: theService = Service.load(cfgs) return wsgiHandler(environ, start_response, theService)
def main(): usage = "usage: %prog <layer> [<zoom start> <zoom stop>]" parser = OptionParser(usage=usage, version="%prog $Id$") parser.add_option("-f","--force", action="store_true", dest="force", default = False, help="force recreation of tiles even if they are already in cache") parser.add_option("-b","--bbox",action="store", type="string", dest="bbox", default = None, help="restrict to specified bounding box") parser.add_option("-c","--config", action="store", type="string", dest="tilecacheconfig", help="path to configuration file") parser.add_option("-p","--padding",action="store", type="int", dest="padding", default = 0, help="extra margin tiles to seed around target area. Defaults to 0 "+ "(some edge tiles might be missing). A value of 1 ensures all tiles "+ "will be created, but some tiles may be wholly outside your bbox") parser.add_option("-r","--reverse", action="store_true", dest="reverse", default = False, help="Reverse order of seeding tiles") parser.add_option("-a", "--all", action="store_false", dest="skip_empty", default = True, help="Generate all the tiles, the default is to skip the empty tiles if the "+ "layer is a vector and mapserver layer.") parser.add_option("", "--data-projection", action="store", type="string", dest="dataProjectionString", default=None, help="Proj4 string to force the data projection.") parser.add_option("", "--tiles-projection", action="store", type="string", dest="tilesProjectionString", default=None, help="Proj4 string to force the tiles projection.") (options, args) = parser.parse_args() if len(args) > 3: parser.error("Incorrect number of arguments. bbox and padding are now options (-b and -p)") cfgs = cfgfiles if options.tilecacheconfig: cfgs = cfgs + (options.tilecacheconfig,) svc = Service.load(*cfgs) if options.bbox: bboxlist = map(float, options.bbox.split(",")) else: bboxlist = None if len(args) > 1: levels = map(int, args[1:3]) else: # not level given, generate all levels = None if len(args) == 0: parser.print_help() sys.exit(-1) for key in fnmatch.filter(svc.layers.keys(), args[0]): seed(svc, svc.layers[key], levels=levels, bbox=bboxlist, skip_empty=options.skip_empty, padding=options.padding, force = options.force, reverse = options.reverse, dataProjectionString = options.dataProjectionString, tilesProjectionString = options.tilesProjectionString) svc.teardown()
def __init__(self): TC_CONFIG = TC_CONFIG_IN[:-len(".in")] new_content = open(TC_CONFIG_IN).read().replace("@@DATA_PATH@@", DATA_PATH) f = open(TC_CONFIG, "w") f.write(new_content) f.close() self.tc_service = Service.load(TC_CONFIG)
def render_location_tile(location, layer='osm', version='1.0.0', zoom=17, extension='png', host='http://localhost'): latitude = location.geom.centroid.y longitude = location.geom.centroid.x service = Service.load(settings.TILECACHE_CONFIG) (xtile,ytile) = deg2num(latitude, longitude, zoom) #settings.TILE_ZOOM) path_info = '/%s/%s/%d/%d/%d.%s' % (version, layer, zoom, xtile, ytile, extension) tile = TMS(service).parse({}, path_info, host) return service.renderTile(tile)
def load_tilecache_config(settings): """ Load the TileCache config. This function calls ``TileCache.Service.Service.load`` and stores the return value in a private global variable. Arguments: * ``settings``: a dict with a ``tilecache.cfg`` key whose value provides the path to TileCache configuratio file. """ global _service _service = Service.load(settings.get('tilecache.cfg'))
def run(config_path="config.cfg", path_info=None, **kwargs): global template_lookup c = ConfigParser.ConfigParser() c.read(config_path) tc_path = c.get("config", "tilecache_config") s = Service.load(tc_path) template_path = c.get("config", "template_path") tilecache_location = None if c.has_option('config', "tilecache_location"): tilecache_location = c.get("config", "tilecache_location") template_lookup = TemplateLookup(directories=template_path.split(",")) additional_metadata = [] try: additional_metadata = [i[0] for i in c.items("properties")] except ConfigParser.NoSectionError: pass if s.metadata.has_key('exception'): data = [ "Current TileCache config is invalid.", "Exception: %s" % s.metadata['exception'], "Traceback: \n %s" % s.metadata['traceback'] ] return ['text/plain', "\n".join(data)] data = "" stripped = path_info.strip("/") stripped_split = stripped.split("/") if dispatch_urls.has_key(stripped_split[0]): data = dispatch_urls[stripped_split[0]]( s, parts=stripped_split[1:], additional_keys=additional_metadata, tilecache_location=tilecache_location, **kwargs) if isinstance(data, list) or isinstance(data, Response): return data return ['text/html', str(data)]
def run(config_path = "config.cfg", path_info = None, **kwargs): global template_lookup c = ConfigParser.ConfigParser() c.read(config_path) tc_path = c.get("config", "tilecache_config") s = Service.load(tc_path) template_path = c.get("config", "template_path") tilecache_location = None if c.has_option('config', "tilecache_location"): tilecache_location = c.get("config", "tilecache_location") template_lookup = TemplateLookup(directories=template_path.split(",")) additional_metadata = [] try: additional_metadata = [i[0] for i in c.items("properties")] except ConfigParser.NoSectionError: pass if s.metadata.has_key('exception'): data = [ "Current TileCache config is invalid.", "Exception: %s" % s.metadata['exception'], "Traceback: \n %s" % s.metadata['traceback'] ] return ['text/plain', "\n".join(data)] data = "" stripped = path_info.strip("/") stripped_split = stripped.split("/") if dispatch_urls.has_key(stripped_split[0]): data = dispatch_urls[stripped_split[0]](s, parts=stripped_split[1:], additional_keys = additional_metadata, tilecache_location = tilecache_location, **kwargs) if isinstance(data, list) or isinstance(data, Response): return data return ['text/html', str(data)]
def load_tilecache_config(settings): # pragma: no cover """ Load the TileCache config. This function calls ``TileCache.Service.Service.load`` and stores the return value in a private global variable. Arguments: * ``settings``: a dict with a ``tilecache.cfg`` key whose value provides the path to TileCache configuratio file. """ from TileCache.Service import Service global _service _service = Service.load(settings.get('tilecache.cfg')) if 'traceback' in _service.metadata: print 'Tilecache loading error: ' print _service.metadata['exception'] print _service.metadata['traceback']
def load_tilecache_config(settings): """ Load the TileCache config. This function calls ``TileCache.Service.Service.load`` and stores the return value in a private global variable. Arguments: * ``settings``: a dict with a ``tilecache.cfg`` key whose value provides the path to TileCache configuratio file. """ from TileCache.Service import Service global _service _service = Service.load(settings.get('tilecache.cfg')) if 'traceback' in _service.metadata: print 'Tilecache loading error: ' print _service.metadata['exception'] print _service.metadata['traceback']
class TilecacheController(BaseController): service = Service.load(config.get('tilecache.cfg')) def tilecache(self, environ, start_response): try: expiration = self.service.config.getint('cache', 'expire') except NoOptionError: expiration = DEFAULT_EXPIRATION # custom_start_response adds cache headers to the response def custom_start_response(status, headers, exc_info=None): headers.append( ('Cache-Control', 'public, max-age=%s' % expiration)) headers.append(('Expires', email.Utils.formatdate(time.time() + expiration, False, True))) return start_response(status, headers, exc_info) return wsgiHandler(environ, custom_start_response, self.service)
def get_eb_layer(name): svc = Service.load(settings.TILECACHE_CONFIG) return svc.layers[name]
def application(environ, start_response): """Go service.""" if not theService["app"]: theService["app"] = Service.load(cfgfiles) return wsgiHandler(environ, start_response, theService["app"])