Beispiel #1
0
def rawChipByLocation_query():
    """
    Get chips images by parcel location.
    Generates a series of extracted Sentinel-2 LEVEL2A segments of 128x128 (10m
    resolution bands) or 64x64 (20 m) pixels as list of full resolution GeoTIFFs
    _
    tags:
      - rawChipByLocation
    responses:
      200:
        description: A JSON dictionary with date labels and
        relative URLs to cached GeoTIFFs.
    """
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    # Start by getting the request IP address
    if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
        rip = request.environ['REMOTE_ADDR']
    else:
        rip = request.environ['HTTP_X_FORWARDED_FOR']

    lon = request.args.get('lon')
    lat = request.args.get('lat')

    start_date = request.args.get('start_date')
    end_date = request.args.get('end_date')

    band = request.args.get('band')

    if 'plevel' in request.args.keys():
        plevel = request.args.get('plevel')
    else:
        plevel = 'LEVEL2A'

    if 'chipsize' in request.args.keys():
        chipsize = request.args.get('chipsize')
    else:
        chipsize = '1280'

    unique_id = f"dump/{rip}E{lon}N{lat}_{plevel}_{chipsize}_{band}".replace(
        '.', '_')

    data = image_requests.getRawChipByLocation(lon, lat, start_date, end_date,
                                               unique_id, band, chipsize,
                                               plevel)

    if data:
        return send_from_directory(f"chip_extract/{unique_id}", 'dump.json')
    else:
        return json.dumps({})
Beispiel #2
0
def rawChipByParcelID_query():
    """
    Get chips images by parcel ID.
    Generates a series of extracted Sentinel-2 LEVEL2A segments of 128x128 (10m
    resolution bands) or 64x64 (20 m) pixels as list of full resolution GeoTIFFs
    _
    tags:
      - rawChipByLocation
    responses:
      200:
        description: A JSON dictionary with date labels and
        relative URLs to cached GeoTIFFs.
    """
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    # Start by getting the request IP address
    if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
        rip = request.environ['REMOTE_ADDR']
    else:
        rip = request.environ['HTTP_X_FORWARDED_FOR']

    aoi = DEFAULT_AOI
    ptype = ''
    withGeometry = False
    wgs84 = False
    year = request.args.get('year')
    pid = request.args.get('pid')

    if 'ptype' in request.args.keys():
        ptype = f"_{request.args.get('ptype')}"

    if 'aoi' in request.args.keys():
        aoi = request.args.get('aoi')

    dataset = datasets[f'{aoi}_{year}']
    pdata = db_queries.getParcelById(dataset, pid, ptype, withGeometry, wgs84)
    if not pdata:
        parcel = json.dumps({})
    elif len(pdata) == 1:
        parcel = json.dumps(
            dict(zip(list(pdata[0]), [[] for i in range(len(pdata[0]))])))
    else:
        parcel = json.dumps(
            dict(zip(list(pdata[0]), [list(i) for i in zip(*pdata[1:])])))

    lon = str(json.loads(parcel)['clon'][0])
    lat = str(json.loads(parcel)['clat'][0])

    start_date = request.args.get('start_date')
    end_date = request.args.get('end_date')

    band = request.args.get('band')

    if 'plevel' in request.args.keys():
        plevel = request.args.get('plevel')
    else:
        plevel = 'LEVEL2A'

    if 'chipsize' in request.args.keys():
        chipsize = request.args.get('chipsize')
    else:
        chipsize = '1280'

    unique_id = f"dump/{rip}E{lon}N{lat}_{plevel}_{chipsize}_{band}".replace(
        '.', '_')

    data = image_requests.getRawChipByLocation(lon, lat, start_date, end_date,
                                               unique_id, band, chipsize,
                                               plevel)

    if data:
        return send_from_directory(f"chip_extract/{unique_id}", 'dump.json')
    else:
        return json.dumps({})