Example #1
0
def create_export_tasks(proj):
    for raster_layer in proj.export_raster_layers:
        raster_source = g.db.query(model.LocalWMTSSource).get(
            raster_layer.source_id)
        start_level = raster_layer.start_level
        end_level = raster_layer.end_level or raster_layer.start_level

        if not proj.coverage:
            raster_coverage = raster_source.wmts_source.download_coverage
            proj.coverage = raster_coverage
        else:
            raster_coverage = proj.coverage

        task = model.RasterExportTask(
            layer=raster_source,
            export_format=proj.export_format,
            export_srs=proj.export_srs,
            zoom_level_start=start_level,
            zoom_level_end=end_level,
            coverage=prepare_task_coverage(raster_coverage),
            project=proj)
        g.db.add(task)

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

    g.db.commit()
    return True
Example #2
0
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
Example #3
0
def create_export_tasks(proj):
    for raster_layer in proj.export_raster_layers:
        raster_source = g.db.query(model.LocalWMTSSource).get(raster_layer.source_id)
        start_level = raster_layer.start_level
        end_level = raster_layer.end_level or raster_layer.start_level

        if not proj.coverage:
            raster_coverage = raster_source.wmts_source.download_coverage
            proj.coverage = raster_coverage
        else:
            raster_coverage = proj.coverage

        task = model.RasterExportTask(
            layer=raster_source,
            export_format=proj.export_format,
            export_srs=proj.export_srs,
            zoom_level_start=start_level,
            zoom_level_end=end_level,
            coverage=prepare_task_coverage(raster_coverage),
            project=proj
        )
        g.db.add(task)

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

    g.db.commit()
    return True
Example #4
0
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
Example #5
0
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
Example #6
0
def create_export_tasks(proj):
    for raster_layer in proj.export_raster_layers:
        raster_source = g.db.query(model.LocalWMTSSource).get(raster_layer.source_id)
        start_level = raster_layer.start_level
        end_level = raster_layer.end_level or raster_layer.start_level

        if not proj.coverage:
            raster_coverage = raster_source.wmts_source.download_coverage
            proj.coverage = raster_coverage
        else:
            raster_coverage = proj.coverage

        task = model.RasterExportTask(
            layer=raster_source,
            export_format=proj.export_format,
            export_srs=proj.export_srs,
            zoom_level_start=start_level,
            zoom_level_end=end_level,
            coverage=prepare_task_coverage(raster_coverage),
            project=proj
        )
        g.db.add(task)
        send_task_logging(current_app.config.geobox_state, task)


    for vector_layers in proj.export_vector_layers:
        task = model.VectorExportTask(
            db_name=mappings[vector_layers.mapping_name].couchdb,
            mapping_name=vector_layers.mapping_name,
                project=proj,
        )
        g.db.add(task)
        send_task_logging(current_app.config.geobox_state, task)

    g.db.commit()
    return True
Example #7
0
def import_vector():
    from ...lib.vectormapping import default_mappings as mappings

    uploaded_shapes=[]
    upload_failures=[]
    not_allowed_files=[]

    for upload_file in request.files.getlist('file_upload'):
        import_dir = current_app.config.geobox_state.user_data_path('import')
        target = os.path.join(import_dir, upload_file.filename)
        if os.path.splitext(target)[1].lower() in ('.shp', '.shx', '.dbf'):
            try:
                if not os.path.isdir(import_dir):
                    os.mkdir(import_dir)

                f = open(target, 'wb')
                f.write(upload_file.stream.read())
                f.close()
            except IOError:
                upload_failures.append(upload_file.filename)

            uploaded_shapes.append(upload_file.filename)
        else:
            not_allowed_files.append(upload_file.filename)

    form = forms.ImportVectorEdit(request.form)
    shape_files, missing_files = get_shapefile_list()
    form.file_name.choices = [(name, name) for name in shape_files]
    form.mapping_name.choices = [
        (name, '%s (%s, %s)' % (mapping.name, mapping.geom_type, mapping.other_srs.srs_code))
        for name, mapping in mappings.items()
    ]

    if not len(request.files):
        if form.validate_on_submit():
            try:
                is_valid_shapefile(current_app.config.geobox_state.user_data_path('import', form.file_name.data), mappings[form.mapping_name.data])
            except ConvertError:
                flash(_('invalid mapping'), 'error')
                return render_template('vector/import.html', form=form)
            except OSError:
                flash(_('invalid shapefile'), 'error')
                return render_template('vector/import.html', form=form)
            task = VectorImportTask(
                mapping_name=form.mapping_name.data,
                db_name=mappings[form.mapping_name.data].couchdb,
                file_name=form.file_name.data
            )
            send_task_logging(current_app.config.geobox_state, task)
            g.db.add(task)
            g.db.commit()
            return redirect(url_for('tasks.list'))
        elif request.method == 'POST':
            flash(_('form error'), 'error')

    for missing_file in missing_files:
        flash(_('file %(name)s missing', name=missing_file), 'error')
    for upload_failure in upload_failures:
        flash(_('failed to upload %(name)s', name=upload_failure), 'error')
    for not_allowed_file in not_allowed_files:
        flash(_('filetype of %(name)s not allowed', name=not_allowed_file), 'error')
    for uploaded_shape in uploaded_shapes:
        flash(_('file %(name)s uploaded', name=uploaded_shape), 'info')

    file_browser = request_is_local()
    return render_template('vector/import.html', form=form, file_browser=file_browser)