コード例 #1
0
ファイル: project.py プロジェクト: gr2m/gbi-client
def create_raster_import_task(proj):
    raster_source = proj.import_raster_layers[0].source
    start_level = proj.import_raster_layers[0].start_level
    end_level = proj.import_raster_layers[0].end_level

    local_raster_source = g.db.query(model.LocalWMTSSource).filter_by(
        wmts_source=raster_source).first()

    if local_raster_source:
        local_raster_source.download_level_start = min(local_raster_source.download_level_start, start_level)
        local_raster_source.download_level_end = max(local_raster_source.download_level_end, end_level)
    else:
        local_raster_source = model.LocalWMTSSource(
            download_level_start=start_level,
            download_level_end=end_level,
            wmts_source_id=raster_source.id,
        )

    task = model.RasterImportTask(
        source=raster_source,
        zoom_level_start=start_level,
        zoom_level_end=end_level,
        layer=local_raster_source,
        coverage=prepare_task_coverage(proj.coverage),
        update_tiles=proj.update_tiles,
        project=proj
    )
    send_task_logging(current_app.config.geobox_state, task)
    g.db.add(task)
    g.db.commit()
    write_mapproxy_config(current_app.config.geobox_state)
    return True
コード例 #2
0
ファイル: project.py プロジェクト: omniscale/gbi-client
def create_raster_import_task(proj):
    raster_source = proj.import_raster_layers[0].source
    start_level = proj.import_raster_layers[0].start_level
    end_level = proj.import_raster_layers[0].end_level

    local_raster_source = g.db.query(model.LocalWMTSSource).filter_by(
        wmts_source=raster_source).first()

    if local_raster_source:
        local_raster_source.download_level_start = min(
            local_raster_source.download_level_start, start_level)
        local_raster_source.download_level_end = max(
            local_raster_source.download_level_end, end_level)
    else:
        gbi_server = raster_source.gbi_server
        if gbi_server is None:
            name = "%s_%s_%s" % (raster_source.prefix,
                                 current_app.config.geobox_state.config.get('app', 'raster_prefix'),
                                 raster_source.name)
        else:
            name = gbi_server.raster_prefix + raster_source.name
        local_raster_source = model.LocalWMTSSource(
            download_level_start=start_level,
            download_level_end=end_level,
            wmts_source_id=raster_source.id,
            name=name,
        )

    task = model.RasterImportTask(
        source=raster_source,
        zoom_level_start=start_level,
        zoom_level_end=end_level,
        layer=local_raster_source,
        coverage=prepare_task_coverage(proj.coverage),
        update_tiles=proj.update_tiles,
        project=proj
    )

    if raster_source.gbi_server is not None:
        logging_server = raster_source.gbi_server.logging_url
        user = raster_source.gbi_server.username
        send_task_logging(logging_server, user,
                          current_app.config.geobox_state,
                          task)

    g.db.add(task)
    g.db.commit()
    write_mapproxy_config(current_app.config.geobox_state)
    return True
コード例 #3
0
ファイル: project.py プロジェクト: maximebardou/gbi-client
def create_raster_import_task(proj):
    raster_source = proj.import_raster_layers[0].source
    start_level = proj.import_raster_layers[0].start_level
    end_level = proj.import_raster_layers[0].end_level

    local_raster_source = g.db.query(
        model.LocalWMTSSource).filter_by(wmts_source=raster_source).first()

    if local_raster_source:
        local_raster_source.download_level_start = min(
            local_raster_source.download_level_start, start_level)
        local_raster_source.download_level_end = max(
            local_raster_source.download_level_end, end_level)
    else:
        gbi_server = raster_source.gbi_server
        if gbi_server is None:
            name = "%s_%s_%s" % (raster_source.prefix,
                                 current_app.config.geobox_state.config.get(
                                     'app',
                                     'raster_prefix'), raster_source.name)
        else:
            name = gbi_server.raster_prefix + raster_source.name
        local_raster_source = model.LocalWMTSSource(
            download_level_start=start_level,
            download_level_end=end_level,
            wmts_source_id=raster_source.id,
            name=name,
        )

    task = model.RasterImportTask(source=raster_source,
                                  zoom_level_start=start_level,
                                  zoom_level_end=end_level,
                                  layer=local_raster_source,
                                  coverage=prepare_task_coverage(
                                      proj.coverage),
                                  update_tiles=proj.update_tiles,
                                  project=proj)

    if raster_source.gbi_server is not None:
        logging_server = raster_source.gbi_server.logging_url
        user = raster_source.gbi_server.username
        send_task_logging(logging_server, user,
                          current_app.config.geobox_state, task)

    g.db.add(task)
    g.db.commit()
    write_mapproxy_config(current_app.config.geobox_state)
    return True
コード例 #4
0
def mapproxy_thread(app_state):
    """Mapproxy background thread"""
    from mapproxy.wsgiapp import make_wsgi_app
    from geobox.lib.webserver import WebServerThread
    from geobox.utils import wait_for_http_server

    host = app_state.config.get('app', 'host')
    mapproxy_port = app_state.config.get('mapproxy', 'port')
    couch_port = app_state.config.get_int('couchdb', 'port')
    user_dir = app_state.user_data_path()

    # wait for up to ten seconds till couchdb is online
    wait_for_http_server('127.0.0.1', couch_port, max_wait=10)

    from geobox.lib.mapproxy import write_mapproxy_config
    write_mapproxy_config(app_state)

    app = make_wsgi_app(os.path.join(user_dir, 'mapproxy.yaml'), reloader=True)
    return WebServerThread(host, mapproxy_port, app, logger_name='geobox.mapproxy.server')
コード例 #5
0
ファイル: app.py プロジェクト: GeoDodo/gbi-client
def mapproxy_thread(app_state):
    """Mapproxy background thread"""
    from mapproxy.wsgiapp import make_wsgi_app
    from geobox.lib.webserver import WebServerThread
    from geobox.utils import wait_for_http_server

    host = app_state.config.get('app', 'host')
    mapproxy_port = app_state.config.get('mapproxy', 'port')
    couch_port = app_state.config.get_int('couchdb', 'port')
    user_dir = app_state.user_data_path()

    # wait for up to ten seconds till couchdb is online
    wait_for_http_server('127.0.0.1', couch_port, max_wait=10)

    from geobox.lib.mapproxy import write_mapproxy_config
    write_mapproxy_config(app_state)

    app = make_wsgi_app(os.path.join(user_dir, 'mapproxy.yaml'), reloader=True)
    return WebServerThread(host, mapproxy_port, app, logger_name='geobox.mapproxy.server')
コード例 #6
0
def remove_source(id):
    query = g.db.query(LocalWMTSSource).filter_by(id=id)
    source = query.first()

    if source:
        # delete from couch db
        couch = CouchDB(
            'http://127.0.0.1:%s' %
            (current_app.config.geobox_state.config.get('couchdb', 'port'), ),
            source.wmts_source.name)
        # if delete from couch is successfull delete from db
        if couch.delete_db():
            g.db.delete(source)
            g.db.commit()
            write_mapproxy_config(current_app.config.geobox_state)
            flash(_('delete sucessful'))
        else:
            flash(_('delete not sucessful'))

    return redirect(url_for('.admin'))
コード例 #7
0
ファイル: admin.py プロジェクト: gr2m/gbi-client
def remove_source(id):
    query = g.db.query(LocalWMTSSource).filter_by(id=id)
    source = query.first()

    if source:
        # delete from couch db
        couch = CouchDB('http://127.0.0.1:%s' %
            (current_app.config.geobox_state.config.get('couchdb', 'port'), ),
            source.wmts_source.name
        )
        # if delete from couch is successfull delete from db
        if couch.delete_db():
            g.db.delete(source)
            g.db.commit()
            write_mapproxy_config(current_app.config.geobox_state)
            flash(_('delete sucessful'))
        else:
            flash(_('delete not sucessful'))

    return redirect(url_for('.admin'))
コード例 #8
0
def import_edit(id):
    proj = g.db.query(model.ImportProject).get(id)

    sources = g.db.query(model.ExternalWMTSSource).all()
    if not proj:
        abort(404)

    coverage_form = forms.SelectCoverage()

    form = forms.ImportProjectEdit(request.form)
    form.start_level.choices = get_levels(model.ExternalWMTSSource)
    form.end_level.choices = get_levels(model.ExternalWMTSSource)
    form.update_tiles.checked = proj.update_tiles

    if form.validate_on_submit():
        redirect_url = url_for('.import_list', id=id)
        proj.title = form.data['title']
        proj.import_raster_layers = []
        if form.coverage.data != 'false':
            proj.coverage = prepare_feature_collection_coverage(
                form.coverage.data)
        else:
            proj.coverage = ''

        proj.download_size = float(form.data.get('download_size', 0.0))
        proj.update_tiles = form.data.get('update_tiles', False)

        g.db.add(
            model.ImportRasterLayer(source=form.raster_source.data,
                                    start_level=int(form.start_level.data),
                                    end_level=int(form.end_level.data),
                                    project=proj))
        g.db.commit()
        if form.start.data == 'start':
            local_raster_source = g.db.query(model.LocalWMTSSource).filter_by(
                wmts_source=form.raster_source.data).first()
            if local_raster_source:
                local_raster_source.download_level_start = min(
                    local_raster_source.download_level_start,
                    int(form.start_level.data))
                local_raster_source.download_level_end = max(
                    local_raster_source.download_level_end,
                    int(form.end_level.data))
            else:
                local_raster_source = model.LocalWMTSSource(
                    download_level_start=int(form.start_level.data),
                    download_level_end=int(form.end_level.data),
                    wmts_source_id=form.raster_source.data.id)
            g.db.add(
                model.RasterImportTask(
                    source=form.raster_source.data,
                    zoom_level_start=int(form.start_level.data),
                    zoom_level_end=int(form.end_level.data),
                    layer=local_raster_source,
                    coverage=prepare_task_coverage(form.coverage.data),
                    update_tiles=form.update_tiles.data,
                    project=proj))
            redirect_url = url_for('tasks.list')
            g.db.commit()
            write_mapproxy_config(current_app.config.geobox_state)
        return redirect(redirect_url)
    elif request.method == 'POST':
        flash(_('form error'), 'error')

    form.title.data = proj.title
    has_zoom_level = 'false'
    if proj.import_raster_layers:
        form.raster_source.data = proj.import_raster_layers[0].source
        form.start_level.data = proj.import_raster_layers[0].start_level
        form.end_level.data = proj.import_raster_layers[0].end_level
        has_zoom_level = 'true'

    coverage = proj.coverage if proj.coverage else 'null'
    base_layer = g.db.query(
        model.ExternalWMTSSource).filter_by(background_layer=True).first()
    base_layer.bbox = base_layer.bbox_from_view_coverage()

    free_disk_space = diskspace_available_in_mb(
        current_app.config.geobox_state.user_data_path())

    return render_template('projects/import_edit.html',
                           proj=proj,
                           form=form,
                           sources=sources,
                           has_zoom_level=has_zoom_level,
                           base_layer=base_layer,
                           coverage_form=coverage_form,
                           coverage=coverage,
                           free_disk_space=free_disk_space)
コード例 #9
0
ファイル: project.py プロジェクト: GeoDodo/gbi-client
def import_edit(id):
    proj = g.db.query(model.ImportProject).get(id)

    sources = g.db.query(model.ExternalWMTSSource).all()
    if not proj:
        abort(404)

    coverage_form = forms.SelectCoverage()

    form = forms.ImportProjectEdit(request.form)
    form.start_level.choices = get_levels(model.ExternalWMTSSource)
    form.end_level.choices = get_levels(model.ExternalWMTSSource)
    form.update_tiles.checked = proj.update_tiles

    if form.validate_on_submit():
        redirect_url = url_for(".import_list", id=id)
        proj.title = form.data["title"]
        proj.import_raster_layers = []
        if form.coverage.data != "false":
            proj.coverage = prepare_feature_collection_coverage(form.coverage.data)
        else:
            proj.coverage = ""

        proj.download_size = float(form.data.get("download_size", 0.0))
        proj.update_tiles = form.data.get("update_tiles", False)

        g.db.add(
            model.ImportRasterLayer(
                source=form.raster_source.data,
                start_level=int(form.start_level.data),
                end_level=int(form.end_level.data),
                project=proj,
            )
        )
        g.db.commit()
        if form.start.data == "start":
            local_raster_source = (
                g.db.query(model.LocalWMTSSource).filter_by(wmts_source=form.raster_source.data).first()
            )
            if local_raster_source:
                local_raster_source.download_level_start = min(
                    local_raster_source.download_level_start, int(form.start_level.data)
                )
                local_raster_source.download_level_end = max(
                    local_raster_source.download_level_end, int(form.end_level.data)
                )
            else:
                local_raster_source = model.LocalWMTSSource(
                    download_level_start=int(form.start_level.data),
                    download_level_end=int(form.end_level.data),
                    wmts_source_id=form.raster_source.data.id,
                )
            g.db.add(
                model.RasterImportTask(
                    source=form.raster_source.data,
                    zoom_level_start=int(form.start_level.data),
                    zoom_level_end=int(form.end_level.data),
                    layer=local_raster_source,
                    coverage=prepare_task_coverage(form.coverage.data),
                    update_tiles=form.update_tiles.data,
                    project=proj,
                )
            )
            redirect_url = url_for("tasks.list")
            g.db.commit()
            write_mapproxy_config(current_app.config.geobox_state)
        return redirect(redirect_url)
    elif request.method == "POST":
        flash(_("form error"), "error")

    form.title.data = proj.title
    has_zoom_level = "false"
    if proj.import_raster_layers:
        form.raster_source.data = proj.import_raster_layers[0].source
        form.start_level.data = proj.import_raster_layers[0].start_level
        form.end_level.data = proj.import_raster_layers[0].end_level
        has_zoom_level = "true"

    coverage = proj.coverage if proj.coverage else "null"
    base_layer = g.db.query(model.ExternalWMTSSource).filter_by(background_layer=True).first()
    base_layer.bbox = base_layer.bbox_from_view_coverage()

    free_disk_space = diskspace_available_in_mb(current_app.config.geobox_state.user_data_path())

    return render_template(
        "projects/import_edit.html",
        proj=proj,
        form=form,
        sources=sources,
        has_zoom_level=has_zoom_level,
        base_layer=base_layer,
        coverage_form=coverage_form,
        coverage=coverage,
        free_disk_space=free_disk_space,
    )
コード例 #10
0
ファイル: project.py プロジェクト: kaiCu/gbi-client
def import_edit(id=None):
    sources = g.db.query(model.ExternalWMTSSource).all()

    if id is None:
        proj = model.ImportProject()
    else:
        proj = g.db.query(model.ImportProject).get(id)

    if not proj:
        abort(404)

    coverage_form = forms.SelectCoverage()

    form = forms.ImportProjectEdit(request.form)
    form.start_level.choices = get_levels(model.ExternalWMTSSource)
    form.end_level.choices = get_levels(model.ExternalWMTSSource)
    form.update_tiles.checked = proj.update_tiles

    if form.validate_on_submit():
        redirect_url = url_for('.import_list', id=id)
        proj.title = form.data['title']
        proj.import_raster_layers = []
        if form.coverage.data != 'false':
            proj.coverage = prepare_feature_collection_coverage(form.coverage.data)
        else:
            proj.coverage = ''

        proj.download_size = float(form.data.get('download_size', 0.0))
        proj.update_tiles = form.data.get('update_tiles', False)

        g.db.add(model.ImportRasterLayer(
            source=form.raster_source.data,
            start_level=int(form.start_level.data),
            end_level=int(form.end_level.data),
            project=proj
        ))
        g.db.commit()
        if form.start.data == 'start':
            local_raster_source = g.db.query(model.LocalWMTSSource).filter_by(wmts_source=form.raster_source.data).first()
            if local_raster_source:
                local_raster_source.download_level_start = min(local_raster_source.download_level_start, int(form.start_level.data))
                local_raster_source.download_level_end = max(local_raster_source.download_level_end, int(form.end_level.data))
            else:
                local_raster_source = model.LocalWMTSSource(
                    download_level_start=int(form.start_level.data),
                    download_level_end=int(form.end_level.data),
                    wmts_source_id=form.raster_source.data.id
                )
            g.db.add(model.RasterImportTask(
                source=form.raster_source.data,
                zoom_level_start=int(form.start_level.data),
                zoom_level_end=int(form.end_level.data),
                layer=local_raster_source,
                coverage=prepare_task_coverage(form.coverage.data),
                update_tiles=form.update_tiles.data,
                project=proj
            ))
            redirect_url = url_for('tasks.list')
            g.db.commit()
            write_mapproxy_config(current_app.config.geobox_state)
        return redirect(redirect_url)
    elif request.method == 'POST':
        flash(_('form error'), 'error')

    form.title.data = proj.title
    if proj.import_raster_layers:
        form.raster_source.data = proj.import_raster_layers[0].source
        if not request.form.get('start_level'):
            form.start_level.data = proj.import_raster_layers[0].start_level
        if not request.form.get('end_level'):
            form.end_level.data = proj.import_raster_layers[0].end_level

    coverage = proj.coverage if proj.coverage else 'null'
    if form.coverage.data:
        coverage = form.coverage.data

    base_layer = g.db.query(model.ExternalWMTSSource).filter_by(background_layer=True).first()
    base_layer.bbox = base_layer.bbox_from_view_coverage()

    free_disk_space = diskspace_available_in_mb(current_app.config.geobox_state.user_data_path())

    return render_template('projects/import_edit.html',
        proj=proj, form=form, sources=sources,
        base_layer=base_layer,coverage_form=coverage_form,
        coverage=coverage, free_disk_space=free_disk_space)