Beispiel #1
0
 def wrapper(*args, **kwargs):
     if request.method == 'GET':
         #logging.info(f'[decorater - geom]: Getting area by GET {request}')
         geojson = request.args.get('geojson')
         if not geojson:
             return error(status=400, detail='geojson is required')
     elif request.method == 'POST':
         geojson = request.get_json().get(
             'geojson', None) if request.get_json() else None
     try:
         area_ha = AreaService.tabulate_area(geojson)
     except Exception as e:
         return error(status=500, detail=str(e))
     kwargs["geojson"] = geojson
     kwargs['area_ha'] = area_ha
     return func(*args, **kwargs)
Beispiel #2
0
 def wrapper(*args, **kwargs):
     if request.method == 'GET':
         geostore = request.args.get('geostore')
         if not geostore:
             return error(status=400, detail='Geostore is required')
         try:
             geojson, area_ha = GeostoreService.get(geostore)
         except GeostoreNotFound:
             return error(status=404, detail='Geostore not found')
     elif request.method == 'POST':
         geojson = request.get_json().get(
             'geojson', None) if request.get_json() else None
         try:
             area_ha = AreaService.tabulate_area(geojson)
         except Exception as e:
             logging.info(f"[middleware geo hash] Exception")
             return error(status=500, detail=str(e))
     kwargs["geojson"] = geojson
     kwargs["area_ha"] = area_ha
     return func(*args, **kwargs)
def analyze(geojson, area_ha):
    """Call Geodescriber"""
    try:
        app = request.args.get('app', 'geodescriber')
        lang = request.args.get('lang', 'en')
        template = request.args.get('template', '').lower() in ['t', 'true']
        gd_result = GeodescriberService.analyze(geojson=geojson,
                                                area_ha=area_ha,
                                                app=app,
                                                lang=lang,
                                                template=template)
        logging.info(f'[Geodescriber ROUTER]: result {gd_result}')
        return serialize_geodescriber(analysis=gd_result,
                                      type='geodescriber'), 200
    except GeodescriberError as e:
        logging.error(f'[Geodescriber ROUTER]: {e.message}')
        return error(status=500, detail=e.message)
    except Exception as e:
        logging.error(f'[Geodescriber ROUTER]: {e}')
        return error(status=500, detail='Generic Error')
Beispiel #4
0
def internal_server_error(e):
    return error(status=500, detail='Internal Server Error')
Beispiel #5
0
def gone(e):
    return error(status=410, detail='Gone')
Beispiel #6
0
def method_not_allowed(e):
    return error(status=405, detail='Method Not Allowed')
Beispiel #7
0
def page_not_found(e):
    return error(status=404, detail='Not Found')
Beispiel #8
0
def forbidden(e):
    return error(status=403, detail='Forbidden')
Beispiel #9
0
 def wrapper(*args, **kwargs):
     if request.method == 'GET':
         geostore = request.args.get('geostore')
         if not geostore:
             return error(status=400, detail='Geostore is required')
     return func(*args, **kwargs)