コード例 #1
0
ファイル: geodata.py プロジェクト: cjh1/geoweb
def run(method='read', expr=None, vars=None, time=None, fields=None, limit=1000, sort=None, fill=None):
    # Create an empty response object.
    response = geoweb.empty_response();

    # Check the requested method.
    if method not in ['find', 'read']:
        response['error'] = "Unsupported data operation '%s'" % (method)
        return bson.json_util.dumps(response)

    # Decode the strings into Python objects.
    try:
        if expr is not None: expr = decode(expr, 'expr', response)
        if vars is not None: vars = decode(vars, 'vars', response)
        if time is not None: time = decode(time, 'time', response)
        if fields is not None: fields = decode(fields, 'f', response)
        if sort is not None: sort = decode(sort, 'sort', response)
        if fill is not None:
            fill = decode(fill, 'fill', response)
        else:
            fill = True
    except ValueError:
        return bson.json_util.dumps(response)

    # Cast the limit value to an int
    try:
        limit = int(limit)
    except ValueError:
        response['error'] = "Argument 'limit' ('%s') could not be converted to int." % (limit)
        return bson.json_util.dumps(response)

    # Perform the requested action.
    if method == 'find':
        # @todo This method should find the matching data on the server
        pass
    elif method == 'read':
        # Load reader module
        import reader
        try:
            it = reader.read(expr, vars, time)

            # Create a list of the results.
            if fill:
                results = [it]
            else:
                results = []

            # Create an object to structure the results.
            retobj = {}
            retobj['count'] = 1
            retobj['data'] = results

            # Pack the results into the response object, and return it.
            response['result'] = retobj
        except IOError as io:
            response['error'] = io.message
    else:
        raise RuntimeError("illegal method '%s' in module 'mongo'")

    # Return the response object.
    return bson.json_util.dumps(response)
コード例 #2
0
ファイル: mongo.py プロジェクト: OpenGeoscience/geoweb
def run(server, db, coll, method='find', queryId=None, query=None, limit=1000, fields=None, sort=None, fill=None):
    # Create an empty response object.
    response = geoweb.empty_response()

    # Check the requested method.
    if method not in ['find', 'insert']:
        response['error'] = "Unsupported MongoDB operation '%s'" % (method)
        return bson.json_util.dumps(response)

    # Decode the query strings into Python objects.
    try:
        if query is not None: query = decode(query, 'query', response)
        if fields is not None: fields = decode(fields, 'fields', response)
        if sort is not None: sort = decode(sort, 'sort', response)
        if fill is not None:
            fill = decode(fill, 'fill', response)
        else:
            fill = True
    except ValueError:
        return bson.json_util.dumps(response)

    # Cast the limit value to an int.
    try:
        limit = int(limit)
    except ValueError:
        response['error'] = "Argument 'limit' ('%s') could not be converted to int." % (limit)
        return bson.json_util.dumps(response)

    # Create database connection.
    try:
        c = pymongo.Connection(server)[db][coll]
    except pymongo.errors.AutoReconnect:
        response['error'] = "Could not connect to MongoDB server '%s'" % (server)
        return bson.json_util.dumps(response)

    # Perform the requested action.
    if method == 'find':
        # Do a find operation with the passed arguments.
        it = c.find(spec=query, fields=fields, limit=limit, sort=sort)

        # Create a list of the results.
        if fill:
            results = [x for x in it]
        else:
            results = []

        # Create an object to structure the results.
        retobj = {}
        if queryId:
            retobj['queryId'] = int(queryId)
        retobj['count'] = it.count()
        retobj['data'] = results

        # Pack the results into the response object, and return it.
        response['result'] = retobj
    else:
        raise RuntimeError("illegal method '%s' in module 'mongo'")

    # Return the response object.
    return bson.json_util.dumps(response)
コード例 #3
0
ファイル: points.py プロジェクト: OpenGeoscience/geoweb
def count_points(bbox, res, limit=1):
    bbox = json.loads(bbox)
    res = float(res)
    response = geoweb.empty_response()

    count = find_points(bbox, None, res, limit, 0).count(True)

    response['result'] = {'count': count}

    return response
コード例 #4
0
ファイル: session.py プロジェクト: OpenGeoscience/geoweb
def run(parameter= None):
    response = geoweb.empty_response()

    method = cherrypy.request.method

    if method == 'GET':
        response['result'] = {'value': cherrypy.session[parameter] }
    elif method == 'DELETE':
        cherrypy.session.clear()

    return json.dumps(response)
コード例 #5
0
ファイル: points.py プロジェクト: OpenGeoscience/geoweb
def run(*pargs, **kwargs):

    method = cherrypy.request.method
    # GET /floodmap/<id>/points
    # {
    #  result: {id: <id>, geoJson: <points>,
    #  hasMore: <true|false> }
    # }
    if method == 'GET':
        if len(pargs) == 1 and pargs[0] == 'count':
            cherrypy.log("here")
            response = count_points(**kwargs)
        elif len(kwargs) > 1:
            response = points(**kwargs)
        else:
            response = geoweb.empty_response();
            response['error'] =  "Invalid GET request"
    else:
        response = geoweb.empty_response();
        response['error'] =  "Unsupported HTTP method"

    return json.dumps(response)
コード例 #6
0
ファイル: query.py プロジェクト: OpenGeoscience/geoweb
def run(*pargs, **kwargs):
    response = geoweb.empty_response();

    streamId = str(uuid.uuid1())
    expr = kwargs['expr']
    base_url = cherrypy.session['ESGFBaseUrl']
    streams[streamId] = query(base_url, expr)
    response['result'] = {'hasNext': True, 'streamId': streamId}

    if 'queryId' in kwargs:
        response['result']['queryId'] = int(kwargs['queryId'])

    return json.dumps(response)
コード例 #7
0
ファイル: points.py プロジェクト: OpenGeoscience/geoweb
def points(id, bbox, rise, res, thresh, cluster, batch):

    try:
        bbox = json.loads(bbox)
        rise = int(rise)
        batch = int(batch)
        res = float(res)
        thresh = float(thresh)
        cluster = float(cluster)

        if not id:
            id = uuid.uuid4()

        cherrypy.log("course points")

        points = []
        raw_points = find_points(bbox, rise, res, BATCH_SIZE, batch)

        for point in raw_points:
            elevation = point['tile']['properties']['elevation']
            coordinates = point['tile']['coordinates']
            coordinates.append(elevation)
            points.append(coordinates)

        cherrypy.log(str(thresh))
        cherrypy.log(str(cluster))

        if thresh != -1.0:
            points = remove_outliers(points, thresh, cluster)

        response = geoweb.empty_response()
        geojson = to_geojson(points)

        has_more = True

        if len(points) == 0 or len(points) < BATCH_SIZE:
            has_more = False


        response['result'] = {'id': str(id),
                              'hasMore': has_more,
                              'res': res,
                              'batch': batch + 1,
                              'geoJson': geojson}
    except:
        import traceback
        cherrypy.log(traceback.format_exc())

    return response
コード例 #8
0
ファイル: esgf.py プロジェクト: OpenGeoscience/geoweb
def run(method, **kwargs):

    response = geoweb.empty_response();
    start = None
    end = None
    bbox = None

    if method == 'query':
        streamId = str(uuid.uuid1())
        expr = kwargs['expr']

        if 'start' in kwargs:
          start = kwargs['start']

        if 'end' in kwargs:
          end = kwargs['end']

        if 'bbox' in kwargs:
          bbox = kwargs['bbox']


        base_url = cherrypy.session['ESGFBaseUrl']
        streams[streamId] = query(base_url, expr, start, end, bbox)
        response['result'] = {'hasNext': True, 'streamId': streamId}

        if 'queryId' in kwargs:
            response['result']['queryId'] = int(kwargs['queryId'])

    elif method == 'stream':
        streamId = None
        if 'streamId' in kwargs:
            streamId = kwargs['streamId']

        if 'cancel' in kwargs:
            if streamId in streams:
                del streams[streamId]
            response['result'] = {'hasNext': False}
        try:
            if streamId in streams:
                response['result'] = {'hasNext': True,
                                      'streamId': streamId,
                                      'data': [streams[streamId].next()] };
            else:
                response['result'] = {'hasNext': False}
        except StopIteration:
            response['result'] = {'hasNext': False}

        if 'queryId' in kwargs:
            response['result']['queryId'] = int(kwargs['queryId'])
    elif method == 'read':
        url = kwargs['url'].strip('"')
        read(url);
    elif method == "download":
        user_url = cherrypy.session['username']
        url = kwargs['url'].strip('"')
        size = kwargs['size']
        checksum = kwargs['checksum']
        r = pygeo.esgf.download.download.delay(url, size, checksum, user_url);
        response['result'] = {'taskId': r.task_id}
    elif method == 'download_status':
        response['result'] = pygeo.esgf.download.status(**kwargs)
    elif method == 'cancel_download':
        pygeo.esgf.download.cancel(**kwargs)
    elif method == 'filepath':
        user_url = cherrypy.session['username']
        url = kwargs['url'].strip('"')
        response['result'] = {'filepath': url_to_download_filepath(user_url, url)}
    elif method == 'registerGroups':
        response['result'] = {'groups': pygeo.esgf.registration.register_groups(**kwargs)}
    elif method == 'register':
        response['result'] = {'success': pygeo.esgf.registration.register_with_group(**kwargs)}
    else:
        raise RuntimeError("illegal method '%s' in module 'esgf'" % (method))

    return json.dumps(response)