def makeJobTile(self, ll, zoom, style): #create a tile x, y, z = xyFromLatLng(ll, zoom, self.projection) tile = {"x": x, "y": y, "z": z, "gid": 0, "clientid": 0, "priority":0 , "style": style} job = RenderTask.RenderTask(None, tile) tile = Tile(job, self.projection) return job, tile
def timeZoomLevel(self, style, zoom): #get center tile x, y, z = xyFromLatLng(self.testCenter, zoom, self.projection) #increase test size based on zoom level testSize = int((zoom + 1) / 4) #calculate first and last meta tile in range minMeta = (int(x / 8) - int(math.ceil(testSize / 2.0) - 1), int(y / 8) - int(math.ceil(testSize / 2.0) - 1)) maxMeta = (int(x / 8) + int(testSize / 2), int(y / 8) + int(testSize / 2)) #print (int(x / 8), int(y / 8)), testSize, minMeta, maxMeta tileCount = 0 totalTime = 0 minTime = 999999999 maxTime = 0 for my in range(minMeta[1], maxMeta[1] + 1): for mx in range(minMeta[0], maxMeta[0] + 1): renderTime = self.timeTileRender(style, mx * 8, my * 8, zoom) tileCount += 1 totalTime += renderTime minTime = min(renderTime, minTime) maxTime = max(renderTime, maxTime) #return avg. render time, num tiles rendered, and total render time return (totalTime / tileCount if tileCount > 0 else 0), minTime, maxTime, tileCount, totalTime
def BoundingBoxToXYRange(ul, lr, zoom, snapToMeta = False, projection = Mercator(18+1)): x1, y1, z = xyFromLatLng(ul, zoom, projection) x2, y2, z = xyFromLatLng(lr, zoom, projection) #clamp to valid range x1 = max(x1, 0) y1 = max(y1, 0) #if we only want the upper left tile of the metatile if snapToMeta: x1 &= ~(METATILE - 1) y1 &= ~(METATILE - 1) x2 &= ~(METATILE - 1) y2 &= ~(METATILE - 1) #+1 because range is not inclusive last = 1 if z == 0 else int(2 ** z) x2 = min(x2 + 1, last) y2 = min(y2 + 1, last) return x1, y1, x2, y2
def test_tile(self): #we'll go with zuerich ll = (47.376957, 8.539893) #for each zoom for z in range(0, 19): #get the tile coords x, y, z = xyFromLatLng(ll, z, self.projection) #the tile we want tile = {'x': x, 'y': y, 'z': z, 'gid': 0, 'clientid': 0, 'priority':0 , 'style': 'map'} print 'input: ' + str(tile) #convert to mapware tile tile = Tile(RenderTask.RenderTask(None, tile), self.projection) print 'calc tile: ' + str(tile) tile.scale = calculateScale(tile) print 'calc scale: ' + str(tile)
def test_tile(self): # we'll go with saramento (west coast bias) ll = (38.555556, -121.468889) # for each zoom for z in range(0, 19): # get the tile coords x, y, z = xyFromLatLng(ll, z, self.projection) print "Tile info", x, y, z # the tile we want tile = {"x": x, "y": y, "z": z, "gid": 0, "clientid": 0, "priority": 0, "style": "map"} print "input: " + str(tile) # convert to mapware tile tile = Tile(RenderTask.RenderTask(None, tile), self.projection) print "calc tile: " + str(tile) tile.scale = calculateScale(tile) print "calc scale: " + str(tile)
def test_tile(self): #we'll go with saramento (west coast bias) ll = (38.555556, -121.468889) #for each zoom for z in range(0, 19): #get the tile coords x, y, z = xyFromLatLng(ll, z, self.projection) print "Tile info", x, y, z #the tile we want tile = {'x': x, 'y': y, 'z': z, 'gid': 0, 'clientid': 0, 'priority':0 , 'style': 'map'} print 'input: ' + str(tile) #convert to mapware tile tile = Tile(RenderTask.RenderTask(None, tile), self.projection) print 'calc tile: ' + str(tile) tile.scale = calculateScale(tile) print 'calc scale: ' + str(tile)
def getTiles(self, renderer, ll, zooms): #get a tile at each zoom level for Berlin for zoom in zooms: #get the tile coords x, y, z = xyFromLatLng(ll, zoom, self.projection) #make a job job = {"x": x, "y": y, "z": z, "gid": 0, "clientid": 0, "priority":0 , "style": 'map'} #convert it to a tile tile = Tile(RenderTask.RenderTask(None, job), self.projection) #rasterize the tile try: t = time() image, meta = renderer.process(tile) sec = time() - t print '%s took %s seconds' % ((x, y, z), sec) except Exception as detail: print 'failed to get %s with exception %s' % (job, detail)
def test_tileFetch(self): # we'll go with saramento (west coast bias) ll = (38.555556, -121.468889) # for each zoom for z in range(10, 15): # get the tile coords x, y, z = xyFromLatLng(ll, z, self.projection) print "Tile info", x, y, z # the tile we want tile = {"x": x, "y": y, "z": z, "gid": 0, "clientid": 0, "priority": 0, "style": "ter"} print "input: " + str(tile) # convert to mapware tile tile = Tile(RenderTask.RenderTask(None, tile), self.projection) renderer = Renderer("../../conf/dc_ter.conf", None, "ter") results = renderer.process(tile) results[0].save("test_%0d_%0d_%0d.jpg" % (tile.x, tile.y, tile.z), "jpeg")
def test_tileFetch(self): #we'll go with saramento (west coast bias) ll = (38.555556, -121.468889) #for each zoom for z in range(10, 15): #get the tile coords x, y, z = xyFromLatLng(ll, z, self.projection) print "Tile info", x, y, z #the tile we want tile = {'x': x, 'y': y, 'z': z, 'gid': 0, 'clientid': 0, 'priority':0 , 'style': 'map'} print 'input: ' + str(tile) #convert to mapware tile tile = Tile(RenderTask.RenderTask(None, tile), self.projection) renderer = Renderer( "../../conf/dc_sat.conf", None, "sat" ) results = renderer.process( tile ) results[0].save( "test_%0d_%0d_%0d.jpg" % ( tile.x, tile.y, tile.z ), "jpeg" )
def setUp(self): logging.basicConfig() #load the coverages self.coverageManager = coveragemanager.CoverageManager() self.coverageManager.load_coverage('../../../copyright_service_data/coverage/map/', False, 'map') self.coverageManager.load_coverage('../../../copyright_service_data/coverage/hyb/', False, 'hyb') self.coverageManager.load_coverage('../../../copyright_service_data/coverage/sat/', False, 'sat') self.coverageManager.load_coverage('../../../copyright_service_data/coverage/ter/', False, 'ter') #create a coverage checker config = { 'map': '../../../copyright_service_data/coverage/map/', 'hyb': '../../../copyright_service_data/coverage/hyb/', 'sat': '../../../copyright_service_data/coverage/sat/', 'ter': '../../../copyright_service_data/coverage/ter/' } self.checker = CoverageChecker(config) #locations whose coverages we should check self.locations = {} self.locations['north america'] = (40, -100) self.locations['south america'] = (-17, -55) self.locations['africa'] = (10, 20) self.locations['united kingdom'] = (55, -5) self.locations['western europe'] = (47, 5) self.locations['eastern europe'] = (50, 20) self.locations['asia'] = (45, 85) self.locations['ociana'] = (-25, 140) projection = Mercator(18+1) zooms = range(0, 19) #for each ll for name, location in self.locations.iteritems(): tiles = [] #through each zoom for zoom in zooms: #make a tile object x, y, z = xyFromLatLng(location, zoom, projection) tile = {"x": x, "y": y, "z": z, "gid": 0, "clientid": 0, "priority":0 , "style": 'map'} tiles.append(Tile(RenderTask.RenderTask(None, tile), projection)) #overwrite the ll with the list of tiles per zoom level self.locations[name] = tiles