def discovery_dile_by_radius(lon,lat,radius):
    """Discovery the diles given a center point by lon/lat and a radius in km.

    :example: /discovery/dile/by/radius/-135.0/22.5/5000.0
    :param: dim -- json document
    :param: var -- single or multiple string variables' names 
    :returns: geojson -- the return a feature collection with the selected diles.
    -------------------------------------------------------------------------------------------

    """

    qbm = QueryBuilderMongo()

    d_param = request.args.get('dim')
    v_param = request.args.getlist('var')

    # creating the dimension query
    if d_param is not None:
        qbm = getDimentions(d_param, qbm)

    # creating the variables query
    if v_param:
        qbm = getVariables(v_param, qbm)

    query = qbm.queryIntersectRadius(app.config['LOCATION'], float(lon), float(lat), float(radius))

    qbm.addField(query)
    qbm.addProjection({"_id": 0, "uri" : 1})

    return jsonify(query_diles_db(qbm.getQuery()))
def discovery_dile_by_feature():

    """Discovery the diles given a Feature (Point or Polygon)
 
    :param: feat -- json feature
    :param: dim  -- json document
    :param: var  -- single or multiple string variables' names  
    :example: /discovery/dile/by/feature?feat={'geometry'%3A+{'type'%3A+'Point'%2C+'coordinates'%3A+[-90%2C+42.293564192170095]}%2C+'type'%3A+'Feature'%2C+'properties'%3A+{}}
    :returns: geojson -- return a feature collection with the selected diles.
    -------------------------------------------------------------------------------------------
    """

    # creating the object to build the queries
    qbm = QueryBuilderMongo()

    # request the arguments of the url query
    f_param = request.args.get('feat')    
    d_param = request.args.get('dim')
    v_param = request.args.getlist('var')


    # creating the feature query
    if f_param is not None:
        qbm = getFeature(f_param, qbm)
    else:
        return "ERROR: -feat- not found"


    # creating the dimension query
    if d_param is not None:
        qbm = getDimentions(d_param, qbm)

    # creating the variables query
    if v_param:
        qbm = getVariables(v_param, qbm)


    # adding the projection
    qbm.addProjection({"_id": 0, "uri" : 1})

    return jsonify(query_diles_db(qbm.getQuery()))
def discovery_dile_by_bbox(minLon,minLat,maxLon,maxLat):
    """Discovery the diles given a bounding box.

    :example: /discovery/dile/by/bbox/-135.0/22.5/-45.0/67.5
    :param: dim -- json document
    :param: var -- single or multiple string variables' names 
    :returns: geojson -- the return a feature collection with the selected diles.
    -------------------------------------------------------------------------------------------

    """

    bb = {
            "lat_min": float(minLat),
            "lat_max": float(maxLat),
            "lon_min": float(minLon),
            "lon_max": float(maxLon)
    }

    qbm = QueryBuilderMongo()

    d_param = request.args.get('dim')
    v_param = request.args.getlist('var')

    # creating the dimension query
    if d_param is not None:
        qbm = getDimentions(d_param, qbm)

    # creating the variables query
    if v_param:
        qbm = getVariables(v_param, qbm)

    query = qbm.queryIntersectBbox(app.config['LOCATION'],bb)

    qbm.addField(query)
    qbm.addProjection({"_id": 0, "uri" : 1})


    return jsonify(query_diles_db(qbm.getQuery()))