Example #1
0
def data_volume():
    project_coverage = coverage_from_feature_collection(
        json.loads(request.form['coverage']))

    total_tiles = 0
    volume = 0
    max_tiles = None
    if project_coverage:
        for raster_source in json.loads(request.form['raster_data']):
            end_level = raster_source['end_level']
            if end_level:
                levels = range(raster_source['start_level'], end_level + 1)
            else:
                levels = [raster_source['start_level']]
            wmts_source = None
            if request.args.get('export', 'false').lower() == 'true':
                local_source = g.db.query(model.LocalWMTSSource).get(
                    raster_source['source_id'])
                if local_source:
                    wmts_source = local_source.wmts_source
            else:
                wmts_source = g.db.query(model.ExternalWMTSSource).get(
                    raster_source['source_id'])
                max_tiles = wmts_source.max_tiles

            source_tiles = estimate_project_tiles(project_coverage,
                                                  wmts_source, levels)
            volume += source_tiles * 15
            total_tiles += source_tiles

    return jsonify(total_tiles=total_tiles,
                   volume_mb=volume / 1024.0,
                   max_tiles=max_tiles)
Example #2
0
def data_volume():
    project_coverage = coverage_from_feature_collection(json.loads(request.form['coverage']))

    total_tiles = 0
    volume = 0
    max_tiles = None
    if project_coverage:
        for raster_source in json.loads(request.form['raster_data']):
            end_level = raster_source['end_level']
            if end_level:
                levels = range(raster_source['start_level'], end_level + 1)
            else:
                levels = [raster_source['start_level']]
            wmts_source = None
            if request.args.get('export', 'false').lower() == 'true':
                local_source = g.db.query(model.LocalWMTSSource).get(raster_source['source_id'])
                if local_source:
                    wmts_source = local_source.wmts_source
            else:
                wmts_source = g.db.query(model.ExternalWMTSSource).get(raster_source['source_id'])
                max_tiles = wmts_source.max_tiles

            source_tiles = estimate_project_tiles(project_coverage, wmts_source, levels)
            volume += source_tiles * 15
            total_tiles += source_tiles

    return jsonify(total_tiles=total_tiles, volume_mb=volume / 1024.0, max_tiles=max_tiles)
Example #3
0
def data_volume():

    project_coverage = coverage_from_feature_collection(
        json.loads(request.form['coverage']))

    total_tiles = 0
    volume = 0
    if project_coverage:
        for raster_source in json.loads(request.form['raster_data']):
            wmts_source = None
            if request.args.get('export', 'false').lower() == 'true':
                local_source = g.db.query(model.LocalWMTSSource).get(
                    raster_source['source_id'])
                if local_source:
                    wmts_source = local_source.wmts_source
            else:
                wmts_source = g.db.query(model.ExternalWMTSSource).get(
                    raster_source['source_id'])

            if wmts_source.download_coverage:
                wmts_source_coverage = coverage_from_geojson(
                    wmts_source.download_coverage)
            else:
                wmts_source_coverage = make_coverage(
                    shapely.geometry.Polygon([(-20037508.34, -20037508.34),
                                              (-20037508.34, 20037508.34),
                                              (20037508.34, 20037508.34),
                                              (20037508.34, -20037508.34)]),
                    SRS(3857))
            coverage_intersection = wmts_source_coverage.geom.intersection(
                project_coverage.geom)
            if not coverage_intersection:
                continue
            intersection = make_coverage(coverage_intersection, SRS(3857))

            levels = range(raster_source['start_level'],
                           raster_source['end_level'] + 1)
            source_tiles = estimate_tiles(tile_grid(3857), levels,
                                          intersection)
            volume += source_tiles * 15
            total_tiles += source_tiles

    return jsonify(total_tiles=total_tiles, volume_mb=volume / 1024.0)
Example #4
0
def data_volume():

    project_coverage = coverage_from_feature_collection(json.loads(request.form["coverage"]))

    total_tiles = 0
    volume = 0
    if project_coverage:
        for raster_source in json.loads(request.form["raster_data"]):
            wmts_source = None
            if request.args.get("export", "false").lower() == "true":
                local_source = g.db.query(model.LocalWMTSSource).get(raster_source["source_id"])
                if local_source:
                    wmts_source = local_source.wmts_source
            else:
                wmts_source = g.db.query(model.ExternalWMTSSource).get(raster_source["source_id"])

            if wmts_source.download_coverage:
                wmts_source_coverage = coverage_from_geojson(wmts_source.download_coverage)
            else:
                wmts_source_coverage = make_coverage(
                    shapely.geometry.Polygon(
                        [
                            (-20037508.34, -20037508.34),
                            (-20037508.34, 20037508.34),
                            (20037508.34, 20037508.34),
                            (20037508.34, -20037508.34),
                        ]
                    ),
                    SRS(3857),
                )
            coverage_intersection = wmts_source_coverage.geom.intersection(project_coverage.geom)
            if not coverage_intersection:
                continue
            intersection = make_coverage(coverage_intersection, SRS(3857))

            levels = range(raster_source["start_level"], raster_source["end_level"] + 1)
            source_tiles = estimate_tiles(tile_grid(3857), levels, intersection)
            volume += source_tiles * 15
            total_tiles += source_tiles

    return jsonify(total_tiles=total_tiles, volume_mb=volume / 1024.0)
Example #5
0
def validate_max_tiles(form):
    feature_collection = json.loads(form.coverage.data)
    if not feature_collection:
        flash(_("no coverage"))
        return False

    coverage = coverage_from_feature_collection(feature_collection)
    levels = range(int(form.start_level.data), int(form.end_level.data) + 1)
    wmts_source = form.raster_source.data
    tiles = estimate_project_tiles(coverage, wmts_source, levels)
    if not tiles:
        flash(_("no tiles"))
        return False

    max_tiles = wmts_source.max_tiles
    if not max_tiles:
        return True

    if tiles <= max_tiles:
        return True
    else:
        flash(_("to many tiles"))
        return False
Example #6
0
def validate_max_tiles(form):
    feature_collection = json.loads(form.coverage.data)
    if not feature_collection:
        flash(_("no coverage"))
        return False

    coverage = coverage_from_feature_collection(feature_collection)
    levels = range(int(form.start_level.data), int(form.end_level.data) + 1)
    wmts_source = form.raster_source.data
    tiles = estimate_project_tiles(coverage, wmts_source, levels)
    if not tiles:
        flash(_("no tiles"))
        return False

    max_tiles = wmts_source.max_tiles
    if not max_tiles:
        return True

    if tiles <= max_tiles:
        return True
    else:
        flash(_("to many tiles"))
        return False