def parse(self, fields, path, host): # /1.0.0/global_mosaic/0/0/0.jpg parts = filter(lambda x: x != "", path.split("/")) if not host[-1] == "/": host = host + "/" if len(parts) < 1: return self.serverCapabilities(host) elif len(parts) < 2: return self.serviceCapabilities(host, self.service.layers) else: layer = self.getLayer(parts[1]) if len(parts) < 3: return self.layerCapabilities(host, layer) else: parts[-1] = parts[-1].split(".")[0] tile = None if layer.tms_type == "google" or (fields.has_key('type') and fields['type'] == 'google'): res = layer.resolutions[int(parts[2])] maxY = int( round((layer.bbox[3] - layer.bbox[1]) / (res * layer.size[1]))) - 1 tile = Layer.Tile(layer, int(parts[3]), maxY - int(parts[4]), int(parts[2])) else: tile = Layer.Tile(layer, int(parts[3]), int(parts[4]), int(parts[2])) return tile
def getMap(self, param): layer = self.getLayer(param["dataset"]) level = int(param["level"]) y = float(param["y"]) x = float(param["x"]) tile = Layer.Tile(layer, x, y, level) return tile
def getMap(self, param): layer = self.getLayer(param["layer"]) level = int(param["zoom"]) level = 17 - level x = float(param["x"]) y = float(param["y"]) res = layer.resolutions[level] maxY = int( round((layer.bbox[3] - layer.bbox[1]) / (res * layer.size[1]))) - 1 tile = Layer.Tile(layer, x, maxY - y, level) return tile
def parse (self, fields, path, host): """Take in VETMS params and return a tile.""" for key in ['layer', 'tile']: if fields.has_key(key.upper()): fields[key] = fields[key.upper()] elif not fields.has_key(key): fields[key] = "" layer = self.getLayer(fields['layer']) tilenumber = str(fields['tile']) quadkey = tilenumber.split(".")[0] tile = None cell = self.unquad(quadkey) tile = Layer.Tile(layer, cell[0], cell[1], cell[2]) return tile
def parse(self, fields, path, host): # /1.0.0/global_mosaic/0/0/0.jpg parts = list(filter(lambda x: x != "", path.split("/"))) if not host[-1] == "/": host = host + "/" if len(parts) < 1: return self.serverCapabilities(host) elif len(parts) < 2: return self.serviceCapabilities(host, self.service.layers) else: layer = self.getLayer(parts[1]) if len(parts) < 3: return self.layerCapabilities(host, layer) if parts[2] == "{z}": raise TileCacheException("{z} was provided instead of value.") parts[-1] = parts[-1].split(".")[0] tile = None if layer.tms_type == "google" or fields.get("type") == "google": res = layer.resolutions[int(parts[2])] maxY = ( int( round( (layer.bbox[3] - layer.bbox[1]) / (res * layer.size[1]) ) ) - 1 ) tile = Layer.Tile( layer, int(parts[3]), maxY - int(parts[4]), int(parts[2]) ) else: tile = Layer.Tile( layer, int(parts[3]), int(parts[4]), int(parts[2]) ) return tile
def parse (self, fields, path, host): for key in ['scale','layer','tilerow','tilecol']: if fields.has_key(key.upper()): fields[key] = fields[key.upper()] elif not fields.has_key(key): fields[key] = "" layer = self.getLayer(fields['layer']) if not layer.units: raise TileCacheException("No units were specified on the layer. WMTS support requires units to be defined for the layer.") res = .00028 * float(fields['scale']) / self.meters_per_unit[layer.units] z = layer.getLevel(res, layer.size) tile = None maxY = int( round( (layer.bbox[3] - layer.bbox[1]) / (res * layer.size[1]) ) ) - 1 tile = Layer.Tile(layer, int(fields['tilecol']), maxY - int(fields['tilerow']), z) return tile
def parse(self, fields, path, host): # /1.0/main/0/0/0.png version, layername, z, x, y, extension = self._parse_path(path) layer = self.getLayer(layername) return Layer.Tile(layer, int(x)-1, int(y)-1, int(z)-1)
def parse(self, fields, path, host): # /1.0/main/0/0,0.png -> /version/layername/z/x,y.ext version, layername, z, x, y, extension = self._parse_path(path) layer = self.getLayer(layername) return Layer.Tile(layer, int(x), int(y), int(z))
def generate_kml_doc(self, tile, base_path="", include_wrapper=True): tiles = [ Layer.Tile(tile.layer, tile.x << 1, tile.y << 1, tile.z + 1), Layer.Tile(tile.layer, (tile.x << 1) + 1, tile.y << 1, tile.z + 1), Layer.Tile(tile.layer, (tile.x << 1) + 1, (tile.y << 1) + 1, tile.z + 1), Layer.Tile(tile.layer, tile.x << 1, (tile.y << 1) + 1, tile.z + 1) ] network_links = [] for single_tile in tiles: if single_tile.z >= len(tile.layer.resolutions): continue b = single_tile.bounds() network_links.append( """<NetworkLink> <name>tile</name> <Region> <Lod> <minLodPixels>256</minLodPixels><maxLodPixels>-1</maxLodPixels> </Lod> <LatLonAltBox> <north>%s</north><south>%s</south> <east>%s</east><west>%s</west> </LatLonAltBox> </Region> <Link> <href>%s/1.0.0/%s/%s/%s/%s.kml</href> <viewRefreshMode>onRegion</viewRefreshMode> </Link> </NetworkLink>""" % (b[3], b[1], b[2], b[0], base_path, single_tile.layer.name, single_tile.z, single_tile.x, single_tile.y)) b = tile.bounds() kml = [] if include_wrapper: kml.append("""<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.1">""") if tile.z == len(tile.layer.resolutions) - 1: max_lod_pixels = -1 else: max_lod_pixels = 512 kml.append(""" <Document> <Region> <Lod> <minLodPixels>256</minLodPixels><maxLodPixels>%d</maxLodPixels> </Lod> <LatLonAltBox> <north>%s</north><south>%s</south> <east>%s</east><west>%s</west> </LatLonAltBox> </Region> <GroundOverlay> <drawOrder>%s</drawOrder> <Icon> <href>%s/1.0.0/%s/%s/%s/%s</href> </Icon> <LatLonBox> <north>%s</north><south>%s</south> <east>%s</east><west>%s</west> </LatLonBox> </GroundOverlay> %s """ % (max_lod_pixels, b[3], b[1], b[2], b[0], tile.z, base_path, tile.layer.name, tile.z, tile.x, tile.y, b[3], b[1], b[2], b[0], "\n".join(network_links))) if include_wrapper: kml.append("""</Document></kml>""") kml = "\n".join(kml) return kml