def dispatchRequest( self, params, path_info="/", req_method="GET", host="http://example.com/", ): """dispatch the request!""" if "exception" in self.metadata: raise TileCacheException( "%s\n%s" % (self.metadata["exception"], self.metadata["traceback"])) if path_info.find("crossdomain.xml") != -1: return self.generate_crossdomain_xml() # We currently are just supporting TMS or WMS REquests if ("service" in params or "SERVICE" in params or "REQUEST" in params and params["REQUEST"] == "GetMap" or "request" in params and params["request"] == "GetMap"): tile = WMS(self).parse(params, path_info, host) else: tile = TMS(self).parse(params, path_info, host) if not hasattr(tile, "layer"): return "text/xml", tile.data.encode("utf-8") return self.renderTile(tile, "FORCE" in params)
def dispatchRequest (self, params, path_info="/", req_method="GET", host="http://example.com/"): if self.metadata.has_key('exception'): raise TileCacheException("%s\n%s" % (self.metadata['exception'], self.metadata['traceback'])) if path_info.find("crossdomain.xml") != -1: return self.generate_crossdomain_xml() if path_info.split(".")[-1] == "kml": from TileCache.Services.KML import KML return KML(self).parse(params, path_info, host) if params.has_key("scale") or params.has_key("SCALE"): from TileCache.Services.WMTS import WMTS tile = WMTS(self).parse(params, path_info, host) elif params.has_key("service") or params.has_key("SERVICE") or \ params.has_key("REQUEST") and params['REQUEST'] == "GetMap" or \ params.has_key("request") and params['request'] == "GetMap": from TileCache.Services.WMS import WMS tile = WMS(self).parse(params, path_info, host) elif params.has_key("L") or params.has_key("l") or \ params.has_key("request") and params['request'] == "metadata": from TileCache.Services.WorldWind import WorldWind tile = WorldWind(self).parse(params, path_info, host) elif params.has_key("interface"): from TileCache.Services.TileService import TileService tile = TileService(self).parse(params, path_info, host) elif params.has_key("v") and \ (params['v'] == "mgm" or params['v'] == "mgmaps"): from TileCache.Services.MGMaps import MGMaps tile = MGMaps(self).parse(params, path_info, host) elif params.has_key("tile"): from TileCache.Services.VETMS import VETMS tile = VETMS(self).parse(params, path_info, host) elif params.has_key("format") and params['format'].lower() == "json": from TileCache.Services.JSON import JSON return JSON(self).parse(params, path_info, host) else: from TileCache.Services.TMS import TMS tile = TMS(self).parse(params, path_info, host) if isinstance(tile, Layer.Tile): if req_method == 'DELETE': self.expireTile(tile) return ('text/plain', 'OK') else: return self.renderTile(tile, params.has_key('FORCE')) else: return (tile.format, tile.data)
def dispatchRequest(self, params, path_info="/", req_method="GET", host="http://example.com/"): """dispatch the request!""" if 'exception' in self.metadata: raise TileCacheException("%s\n%s" % (self.metadata['exception'], self.metadata['traceback'])) if path_info.find("crossdomain.xml") != -1: return self.generate_crossdomain_xml() if path_info.split(".")[-1] == "kml": from TileCache.Services.KML import KML return KML(self).parse(params, path_info, host) # A shortcut for the most common usage case of a TMS call # any empty dict is False if bool(params) is False: from TileCache.Services.TMS import TMS tile = TMS(self).parse(params, path_info, host) elif "scale" in params or "SCALE" in params: from TileCache.Services.WMTS import WMTS tile = WMTS(self).parse(params, path_info, host) elif ("service" in params or "SERVICE" in params or "REQUEST" in params and params['REQUEST'] == "GetMap" or "request" in params and params['request'] == "GetMap"): from TileCache.Services.WMS import WMS tile = WMS(self).parse(params, path_info, host) elif ("L" in params or "l" in params or "request" in params and params['request'] == "metadata"): from TileCache.Services.WorldWind import WorldWind tile = WorldWind(self).parse(params, path_info, host) elif "interface" in params: from TileCache.Services.TileService import TileService tile = TileService(self).parse(params, path_info, host) elif ("v" in params and (params['v'] == "mgm" or params['v'] == "mgmaps")): from TileCache.Services.MGMaps import MGMaps tile = MGMaps(self).parse(params, path_info, host) elif "tile" in params: from TileCache.Services.VETMS import VETMS tile = VETMS(self).parse(params, path_info, host) elif "format" in params and params['format'].lower() == "json": from TileCache.Services.JSON import JSON return JSON(self).parse(params, path_info, host) else: from TileCache.Services.TMS import TMS tile = TMS(self).parse(params, path_info, host) if isinstance(tile, Layer.Tile): if req_method == 'DELETE': self.expireTile(tile) return ('text/plain', 'OK') else: return self.renderTile(tile, 'FORCE' in params) elif isinstance(tile, list): if req_method == 'DELETE': [self.expireTile(t) for t in tile] return ('text/plain', 'OK') else: try: import PIL.Image as Image except ImportError: raise Exception("Combining multiple layers requires Python Imaging Library.") try: import cStringIO as StringIO except ImportError: import StringIO result = None for t in tile: (format, data) = self.renderTile(t, params.has_key('FORCE')) image = Image.open(StringIO.StringIO(data)) if not result: result = image else: try: result.paste(image, None, image) except Exception, E: raise Exception("Could not combine images: Is it possible that some layers are not \n8-bit transparent images? \n(Error was: %s)" % E) buffer = StringIO.StringIO() result.save(buffer, result.format) buffer.seek(0) return (format, buffer.read())
def dispatchRequest(self, params, path_info="/", req_method="GET", host="http://example.com/"): ##### loop over the config instances and ##### ##### check for warnings and exceptions ##### for conf in self.configs: if conf.metadata.has_key('exception'): raise TileCacheException( "%s\n%s" % (conf.metadata['exception'], conf.metadata['traceback'])) elif conf.metadata.has_key('warn'): sys.stderr.write( "%s\n%s" % (conf.metadata['warn'], conf.metadata['traceback'])) if path_info.find("crossdomain.xml") != -1: return self.generate_crossdomain_xml() if path_info.split(".")[-1] == "kml": from TileCache.Services.KML import KML return KML(self).parse(params, path_info, host) if params.has_key("scale") or params.has_key("SCALE"): from TileCache.Services.WMTS import WMTS tile = WMTS(self).parse(params, path_info, host) elif params.has_key("service") or params.has_key("SERVICE") or \ params.has_key("REQUEST") and params['REQUEST'] == "GetMap" or \ params.has_key("request") and params['request'] == "GetMap": from TileCache.Services.WMS import WMS tile = WMS(self).parse(params, path_info, host) elif params.has_key("L") or params.has_key("l") or \ params.has_key("request") and params['request'] == "metadata": from TileCache.Services.WorldWind import WorldWind tile = WorldWind(self).parse(params, path_info, host) elif params.has_key("interface"): from TileCache.Services.TileService import TileService tile = TileService(self).parse(params, path_info, host) elif params.has_key("v") and \ (params['v'] == "mgm" or params['v'] == "mgmaps"): from TileCache.Services.MGMaps import MGMaps tile = MGMaps(self).parse(params, path_info, host) elif params.has_key("tile"): from TileCache.Services.VETMS import VETMS tile = VETMS(self).parse(params, path_info, host) elif params.has_key("format") and params['format'].lower() == "json": from TileCache.Services.JSON import JSON return JSON(self).parse(params, path_info, host) else: from TileCache.Services.TMS import TMS tile = TMS(self).parse(params, path_info, host) #if hasattr(tile, "data"): # duck-typing for Layer.Tile #if isinstance(tile, Layer.Tile): ##### Capabilities object ##### if hasattr(tile, "format"): # return ( TileCache.Service.Capabilities.format, # TileCache.Service.Capabilities.data # ) return (tile.format, tile.data) ##### single tile object ##### elif not isinstance(tile, list): if req_method == 'DELETE': self.expireTile(tile) return ('text/plain', 'OK') else: return self.renderTile(tile, params.has_key('FORCE')) ##### list of tile objects ##### elif isinstance(tile, list): if req_method == 'DELETE': [self.expireTile(t) for t in tile] return ('text/plain', 'OK') else: try: import PIL.Image as Image except ImportError: raise Exception( "Combining multiple layers requires Python Imaging Library." ) try: import cStringIO as StringIO except ImportError: import StringIO ##### calc image size ##### xoff = 0 yoff = 0 prev = None xmax = 0 ymax = 0 for t in tile: xincr = t.layer.size[0] yincr = t.layer.size[1] if prev: if t.x < prev.x: xoff = 0 elif t.x > prev.x: xoff += xincr if t.y < prev.y: yoff = 0 elif t.y > prev.y: yoff += yincr xmax = max(xmax, xoff + xincr) ymax = max(ymax, yoff + yincr) prev = t ##### build an image from the tiles ##### result = None xoff = 0 yoff = ymax - yincr prev = None for t in tile: xincr = t.layer.size[0] yincr = t.layer.size[1] if prev: if t.x < prev.x: xoff = 0 elif t.x > prev.x: xoff += xincr if t.y < prev.y: yoff = ymax - yincr elif t.y > prev.y: yoff -= yincr (format, data) = self.renderTile(t, params.has_key('FORCE')) image = Image.open(StringIO.StringIO(data)) if not result: result = Image.new(image.mode, (xmax, ymax)) imformat = image.format try: result.paste(image, (xoff, yoff), image) except Exception, E: raise Exception( "Could not combine images: Is it possible that some layers are not \n8-bit transparent images? \n(Error was: %s)" % E) prev = t buffer = StringIO.StringIO() result.save(buffer, imformat) buffer.seek(0) return (format, buffer.read())