Пример #1
0
    def search(self):

        if "q" not in self.request.params:
            return {"success": False, "msg": "Parameter 'q' is missing."}

        q = self.request.params["q"]

        if "epsg" in self.request.params:
            epsg = int(self.request.params["epsg"])
            geometry = functions.transform(Geonames.wkb_geometry, epsg)
        else:
            geometry = Geonames.wkb_geometry

        filters = [
            func.lower(Geonames.name).like(func.lower(q + "%")),
            func.lower(Geonames.asciiname).like(func.lower(q + "%")),
            func.lower(Geonames.alternatenames).like(func.lower(q + "%"))]

        rows = []

        for geojson, name, fcode, country in Session.query(
            pg_functions.geojson(geometry), Geonames.name, Geonames.fcode,
            Geonames.country).\
            filter(or_(*filters)).order_by(
                literal_column('bit_length("name")').label("word_length")).\
                all():
            rows.append({
                "name": "%s, %s, %s" % (name, fcode, country),
                "geometry": json.loads(geojson)})

        return {"success": True, "data": rows}
Пример #2
0
def wmts_edit(id=None):

    wmts = db.session.query(WMTS, pg_functions.geojson(WMTS.view_coverage.transform(3857))).filter_by(id=id).first() if id else None
    if wmts:
        wmts[0].view_coverage = wmts[1]
        wmts = wmts[0]
        form = WMTSForm(request.form, wmts)
    else:
        form = WMTSForm(request.form)

    if form.validate_on_submit():
        if not wmts:
            wmts = WMTS()
            db.session.add(wmts)
        if form.data['is_background_layer']:
            old_background_layer = WMTS.query.filter_by(is_background_layer=True).first()
            if old_background_layer:
                old_background_layer.is_background_layer = False
        wmts.url = form.data['url']
        wmts.username = form.data['username']
        wmts.password = form.data['password']
        wmts.name = form.data['name']
        wmts.title = form.data['title']
        wmts.layer = form.data['layer']
        wmts.format = form.data['format']
        wmts.srs = form.data['srs']
        wmts.matrix_set = form.data['matrix_set']
        geom = asShape(loads(form.data['view_coverage']))
        wmts.view_coverage = WKTSpatialElement(geom.wkt, srid=3857, geometry_type='POLYGON')

        wmts.view_level_start = form.data['view_level_start']
        wmts.view_level_end = form.data['view_level_end']
        wmts.is_background_layer = form.data['is_background_layer']
        wmts.is_baselayer = not form.data['is_transparent']
        wmts.is_overlay = form.data['is_transparent']
        wmts.is_transparent = form.data['is_transparent']
        wmts.is_visible = form.data['is_visible']
        wmts.is_public = form.data['is_public']
        try:
            db.session.commit()
            write_mapproxy_config(current_app)
            flash( _('Saved WMTS'), 'success')
            return redirect(url_for('admin.wmts_list'))
        except IntegrityError:
            db.session.rollback()
            flash(_('WMTS with this name already exist'), 'error')
    return render_template('admin/wmts_edit.html', form=form, id=id)
Пример #3
0
def get_context_document():
    sources = db.session.query(WMTS, pg_functions.geojson(WMTS.view_coverage.transform(3857))).order_by(desc(WMTS.is_background_layer)).all()
    response = {
        "version": "0.1",
        "wmts_sources": [],
        "couchdb_sources": [],
    }

    couchdb = CouchDBBox(current_app.config['COUCH_DB_URL'], '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id))
    user_geom = couchdb.layer_extent(current_app.config['USER_WORKON_LAYER'])
    if user_geom:
        user_geom = optimize_geometry(user_geom)
        user_geom = shapely.geometry.mapping(user_geom)

    for source in sources:
        wmts, view_coverage = source
        if wmts.is_public:
            geom = json.loads(view_coverage)
        elif user_geom:
            geom = user_geom
        else:
            continue
        response['wmts_sources'].append({
            "name": wmts.name,
            "title": wmts.title,
            "url": url_for('authproxy.tile_proxy', user_token=g.user.authproxy_token, _external=True).rstrip('/') + '/',
            "layer": wmts.layer,
            "tile_matrix": wmts.matrix_set,
            "format": wmts.format,
            "baselayer": wmts.is_baselayer,
            "overlay": wmts.is_overlay,
            "username": wmts.username,
            "password": wmts.password,
            "srs": wmts.srs,
            "view_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
                "geometry": geom
            },
            "download_restriction": {
                "zoom_level_start": wmts.view_level_start,
                "zoom_level_end": wmts.view_level_end,
                "geometry": geom
            }
        })

    response['couchdb_sources'].append({
        "name": _('area box'),
        "url": current_app.config['COUCH_DB_URL'],
        "dbname": '%s_%s' % (SystemConfig.AREA_BOX_NAME, g.user.id),
        "username": '******' % g.user.id,
        "password": g.user.authproxy_token,
        "writable": True,
        "dbname_user":  SystemConfig.AREA_BOX_NAME_LOCAL,
    })

    response['couchdb_sources'].append({
        "name": _('consultant box'),
        "url": current_app.config['COUCH_DB_URL'],
        "dbname": '%s_%s' % (SystemConfig.CONSULTANT_BOX_NAME, g.user.id),
        "username": '******' % g.user.id,
        "password": g.user.authproxy_token,
        "writable": False,
        "dbname_user":  SystemConfig.CONSULTANT_BOX_NAME_LOCAL,
    })

    response['logging'] = {
        'url': url_for('logserv.log', user_token=g.user.authproxy_token, _external=True),
    }

    return json.dumps(response)