示例#1
0
文件: views.py 项目: squeakus/matahn
def submitnewtask():
    left  = request.args.get('left', type=float)
    bottom  = request.args.get('bottom', type=float)
    right  = request.args.get('right', type=float)
    top  = request.args.get('top', type=float)
    email = request.args.get('email', type=str)
    classification = request.args.get('classification', type=str)

    # email validation
    if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
        return jsonify(wronginput = "Invalid email address")
    # classification validation
    if not re.match(r"^(?=\w{1,2}$)([ug]).*", classification):
        return jsonify(wronginput = "Wrong AHN2 classification")
    # selection bounds validation
    ewkt = get_ewkt_from_bounds(left, bottom, right, top)
    if 0 == db_session.query(Tile).filter( Tile.geom.intersects( ewkt ) ).count():
        return jsonify(wronginput = "Selection is empty")
    if not request.remote_addr in app.config['TRUSTED_IP_ADDRESSES'] and get_point_count_estimate_from_ewkt(ewkt) > app.config['MAX_POINT_QUERY_SIZE']:
        return jsonify(wronginput = "At this time we don't accept requests larger than {} points. Draw a smaller selection to continue.".format(format_big_number(app.config['MAX_POINT_QUERY_SIZE'])))

    # new celery task
    result = new_task.apply_async((left, bottom, right, top, classification))
    # store task parameters in db
    task = Task(id=result.id, ahn2_class=classification, emailto=email, geom=get_ewkt_from_bounds(left, bottom, right, top),\
            time_stamp=datetime.datetime.now(), ip_address=request.remote_addr )
    db_session.add(task)
    db_session.commit()

    taskurl = url_for('tasks_page', task_id=result.id)
    return jsonify(result = taskurl)
示例#2
0
def get_tile_from_file(path, bounds=None):

    lasinfo_file = path[:-3] + 'txt'
    if os.path.isfile(lasinfo_file):
        info_txt = lasinfo_file
    else:
        info_txt = lasinfotxt(path)

    info_dict = read_lasinfotxt(info_txt)

    filename = os.path.basename(path)
    name = filename.split('.')[0]

    if bounds is None:
        x_max, y_max, z_max = info_dict['max_xyz']
        x_min, y_min, z_min = info_dict['min_xyz']
        ewkt = get_ewkt_from_bounds(x_min, y_min, x_max, y_max)
    else:
        try:
            ewkt = get_ewkt_from_pointlist(bounds[name])
        except:
            x_max, y_max, z_max = info_dict['max_xyz']
            x_min, y_min, z_min = info_dict['min_xyz']
            ewkt = get_ewkt_from_bounds(x_min, y_min, x_max, y_max)

    tile = Tile(path=path,
                active=True,
                pointcount=info_dict['pointcount'],
                name=name,
                geom=ewkt)

    return tile
示例#3
0
文件: tasks.py 项目: squeakus/matahn
def new_task(left, bottom, right, top, ahn2_class):
    if ahn2_class == 'ug': ahn2_class = 'u|g'
    ewkt = get_ewkt_from_bounds(left, bottom, right, top)
    # geojson = get_geojson_from_bounds(left, bottom, right, top)
    filenames = db_session.query(Tile.path).filter(Tile.ahn2_class.match(ahn2_class)).filter(Tile.geom.intersects(ewkt)).all()
    filenames = [f[0] for f in filenames]
    
    output_laz = app.config['RESULTS_FOLDER'] + str(new_task.request.id)+'.laz'
    # this will cause an exception if something goes wrong while calling lasmerge executable
    t0 = time.time()
    lastools.lasmerge(filenames, left, bottom, right, top, output_laz)
    t1 = time.time()

    t = db_session.query(Task).filter(Task.id==str(new_task.request.id)).one()
    try:
        t.send_email()
    except:
        pass

    infotxt = lastools.lasinfotxt(output_laz)
    info = tile_io.read_lasinfotxt(infotxt)

    t.log_execution_time = t1-t0
    t.log_actual_point_count = info['pointcount']
    db_session.commit()
示例#4
0
文件: views.py 项目: squeakus/matahn
def getPointCountEstimate():
    """Gives an estimate of the number of points in the query rectangle"""
    left = request.args.get('left', type=float)
    bottom = request.args.get('bottom', type=float)
    right = request.args.get('right', type=float)
    top = request.args.get('top', type=float)

    ewkt = get_ewkt_from_bounds(left, bottom, right, top)
    
    total_estimate = get_point_count_estimate_from_ewkt(ewkt)

    return jsonify(result="You selected about {} points!".format(format_big_number(total_estimate)))
示例#5
0
def getPointCountEstimate():
    """Gives an estimate of the number of points in the query rectangle"""
    left = request.args.get('left', type=float)
    bottom = request.args.get('bottom', type=float)
    right = request.args.get('right', type=float)
    top = request.args.get('top', type=float)
    dataset_id = request.args.get('dataset_id', type=int)

    dataset = Dataset.query.get(dataset_id)
    ewkt = get_ewkt_from_bounds(left, bottom, right, top)

    total_estimate = get_point_count_estimate_from_ewkt(dataset, ewkt)

    return jsonify(result="You selected about {} points!".format(
        format_big_number(total_estimate)))
示例#6
0
def merge_tiles_from_taskfile(taskfile):
    with open(taskfile) as f:
        left = float(f.readline().split(':')[-1])
        bottom = float(f.readline().split(':')[-1])
        right = float(f.readline().split(':')[-1])
        top = float(f.readline().split(':')[-1])
        ahn2_class = f.readline().split(':')[-1].strip()

    if ahn2_class == 'ug': ahn2_class = 'u|g'
    ewkt = get_ewkt_from_bounds(left, bottom, right, top)
    filenames = db_session.query(Tile.path).filter(
        Tile.ahn2_class.match(ahn2_class)).filter(
            Tile.geom.intersects(ewkt)).all()
    filenames = [f[0] for f in filenames]

    lasmerge(filenames, left, bottom, right, top, taskfile[:-3] + 'laz')
示例#7
0
def submitnewtask():
    left = request.args.get('left', type=float)
    bottom = request.args.get('bottom', type=float)
    right = request.args.get('right', type=float)
    top = request.args.get('top', type=float)
    email = request.args.get('email', type=str)
    classification = request.args.get('classification', type=str)
    dataset_id = request.args.get('dataset_id', type=int)

    # email validation
    if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
        return jsonify(wronginput="Invalid email address")
    # classification validation
    if not re.match(r"^([1-9][0-9]?)(,[1-9][0-9]?)*$", classification):
        return jsonify(wronginput="Invalid classification string")
    classification = classification.split(',')
    # dataset validation
    dataset = Dataset.query.get(dataset_id)
    if dataset is None:
        return jsonify(wronginput="Invalid dataset name")
    # selection bounds validation
    ewkt = get_ewkt_from_bounds(left, bottom, right, top)
    if 0 == db_session.query(Tile).filter(Tile.geom.intersects(ewkt)).count():
        return jsonify(wronginput="Selection is empty")
    if not request.remote_addr in app.config[
            'TRUSTED_IP_ADDRESSES'] and get_point_count_estimate_from_ewkt(
                dataset, ewkt) > app.config['MAX_POINT_QUERY_SIZE']:
        return jsonify(
            wronginput=
            "At this time we don't accept requests larger than {} points. Draw a smaller selection to continue."
            .format(format_big_number(app.config['MAX_POINT_QUERY_SIZE'])))

    # new celery task
    result = new_task.apply_async(
        (left, bottom, right, top, dataset_id, classification))
    # store task parameters in db
    task = Task(id=result.id, dataset=dataset, classes=classification, emailto=email, geom=get_ewkt_from_bounds(left, bottom, right, top),\
            time_stamp=datetime.datetime.now(), ip_address=request.remote_addr )
    db_session.add(task)
    db_session.commit()

    taskurl = url_for('tasks_page', task_id=result.id)
    return jsonify(result=taskurl)