Exemple #1
0
def get_tile(layer, z, x, y, map_object=None, layer_obj=None):
    """Get tile Endpoint"""
    #logging.info(f"[Layer Router]: made it to router. {z}/{x}/{y}")
    try:
        layer_config = layer_obj.get('layerConfig')
        layer_type = layer_obj.get('provider')
    except Exception as e:
        logging.error(str(e))
        return error(status=500, detail='Error grabbing layer data: ' + str(e))
    # IF Carto type of layer
    if layer_type == 'cartodb':
        #logging.info(f"[Layer Router] Carto type: {layer_type}")
        tmp_url = get_carto_url(layer_config)
        url = tmp_url.replace("{z}/{x}/{y}", f"{z}/{x}/{y}")
        #logging.info(f"[Layer Router]: URL.{url}")
    # IF EE type of layer
    if layer_type == 'gee':
        #logging.info(f"[Layer Router] EE type: {layer_type}")
        try:
            if map_object is None:
                logging.info('Generating mapid')
                style_type = layer_config.get('body').get('styleType')
                image = None
                if 'isImageCollection' not in layer_config or not layer_config.get(
                        'isImageCollection'):
                    image = ee.Image(layer_config.get('assetId'))
                else:
                    position = layer_config.get('position')
                    image_col = ee.ImageCollection(layer_config.get('assetId'))
                    if 'filterDates' in layer_config:
                        dates = layer_config.get('filterDates')
                        image_col = image_col.filterDate(dates[0], dates[1])
                    if position == 'first':
                        logging.info('Obtaining first')
                        image = ee.Image(
                            image_col.sort('system:time_start', True).first())
                    else:
                        logging.info('Obtaining last')
                        image = ee.Image(
                            image_col.sort('system:time_start', False).first())
                if style_type == 'sld':
                    style = layer_config.get('body').get('sldValue')
                    map_object = image.sldStyle(style).getMapId()
                else:
                    map_object = image.getMapId(layer_config.get('body'))
                RedisService.set_layer_mapid(layer, map_object.get('mapid'),
                                             map_object.get('token'))
        except Exception as e:
            logging.error(str(e))
            return error(status=500, detail='Error generating tile: ' + str(e))
        try:
            url = ee.data.getTileUrl(map_object, int(x), int(y), int(z))
        except Exception as e:
            logging.error(str(e))
            return error(status=404, detail='Tile Not Found')
    # Return back the url of the individual tile either from EE or Carto
    return redirect(url)
Exemple #2
0
def analyze(year, z, x, y, map_object):
    """Generate Landsat tile url for a requested YEAR"""
    try:
        data = LandsatTiles.analyze(year, z, x, y, map_object)
    except LandsatTilesError as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')
    return redirect(data['url'])
Exemple #3
0
 def wrapper(*args, **kwargs):
     try:
         layer = kwargs['layer']
         #logging.info(f'[MIDDLEWARE get_layer] Getting layer: {layer}')
         url = f"https://api.skydipper.com/v1/layer/{layer}"
         r = requests.get(url)
         if r.status_code == 200:
             kwargs["layer_obj"] = r.json().get('data').get('attributes')
             return func(*args, **kwargs)
     except LayerNotFound as e:
         return error(status=404, detail=e.message)
     except Exception as e:
         return error(detail='Generic error')
Exemple #4
0
 def wrapper(*args, **kwargs):
     years = ['2012', '2013', '2014', '2015', '2016', '2017']
     year = kwargs['year']
     if year not in years:
         return error(status=400, detail='Year is not valid')
     return func(*args, **kwargs)
Exemple #5
0
def internal_server_error(e):
    return error(status=500, detail='Internal Server Error')
Exemple #6
0
def gone(e):
    return error(status=410, detail='Gone')
Exemple #7
0
def method_not_allowed(e):
    return error(status=405, detail='Method Not Allowed')
Exemple #8
0
def page_not_found(e):
    return error(status=404, detail='Not Found')
Exemple #9
0
def forbidden(e):
    return error(status=403, detail='Forbidden')