(scene, tile_z, tile_x, tile_y, tileformat)
return ('OK', f'image/{tileformat}', str_img)
Handle tile requests
Handle tile requests
Handle tile requests
def tile(scene, tile_z, tile_x, tile_y, tileformat):
    """Handle tile requests
    """
    if tileformat == 'jpg':
        tileformat = 'jpeg'

    query_args = APP.current_request.query_params
    query_args = query_args if isinstance(query_args, dict) else {}

    bands = query_args.get('rgb', '4,3,2')
    bands = tuple(re.findall(r'\d+', bands))

    histoCut = query_args.get('histo', ';'.join(['0,16000'] * len(bands)))
    histoCut = re.findall(r'\d+,\d+', histoCut)
    histoCut = list(map(lambda x: list(map(int, x.split(','))), histoCut))

    if len(bands) != len(histoCut):
        raise LandsatTilerError('The number of bands doesn\'t match the number of histogramm values')

    tilesize = query_args.get('tile', 256)
    tilesize = int(tilesize) if isinstance(tilesize, str) else tilesize

    pan = True if query_args.get('pan') else False
    tile, mask = landsat8.tile(scene, tile_x, tile_y, tile_z, bands, pan=pan, tilesize=tilesize)

    rtile = np.zeros((len(bands), tilesize, tilesize), dtype=np.uint8)
    for bdx in range(len(bands)):
        rtile[bdx] = np.where(mask, linear_rescale(tile[bdx], in_range=histoCut[bdx], out_range=[0, 255]), 0)
    img = array_to_img(rtile, mask=mask)
    str_img = b64_encode_img(img, tileformat)
    return ('OK', f'image/{tileformat}', str_img)
def tile ( scene , tile_z , tile_x , tile_y , tileformat ) : if tileformat == 'jpg' : tileformat = 'jpeg' query_args = APP . current_request . query_params query_args = query_args if isinstance ( query_args , dict ) else { } bands = query_args . get ( 'rgb' , '4,3,2' ) bands = tuple ( re . findall ( r'\d+' , bands ) ) histoCut = query_args . get ( 'histo' , ';' . join ( [ '0,16000' ] * len ( bands ) ) ) histoCut = re . findall ( r'\d+,\d+' , histoCut ) histoCut = list ( map ( lambda x : list ( map ( int , x . split ( ',' ) ) ) , histoCut ) ) if len ( bands ) != len ( histoCut ) : raise LandsatTilerError ( 'The number of bands doesn\'t match the number of histogramm values' ) tilesize = query_args . get ( 'tile' , 256 ) tilesize = int ( tilesize ) if isinstance ( tilesize , str ) else tilesize pan = True if query_args . get ( 'pan' ) else False tile , mask = landsat8 . tile ( scene , tile_x , tile_y , tile_z , bands , pan = pan , tilesize = tilesize ) rtile = np . zeros ( ( len ( bands ) , tilesize , tilesize ) , dtype = np . uint8 ) for bdx in range ( len ( bands ) ) : rtile [ bdx ] = np . where ( mask , linear_rescale ( tile [ bdx ] , in_range = histoCut [ bdx ] , out_range = [ 0 , 255 ] ) , 0 ) img = array_to_img ( rtile , mask = mask ) str_img = b64_encode_img ( img , tileformat ) return ( 'OK' , f'image/{tileformat}' , str_img )