Exemplo n.º 1
0
def user(username):

    tuser = current_user
    trips = db.session.query(Tracks).join(Trips).join(User).filter(
        User.id == current_user.get_id()).with_entities(
            Trips.id, Trips.time, Tracks.objtype, Tracks.rutenavn,
            func.ST_AsGeoJSON(Tracks.geog)).all()
    return render_template('user.html', user=tuser, trips=trips)
Exemplo n.º 2
0
    def list_tiles_cube(cls, cube_id: int, only_ids=False):
        """Retrieve all tiles (as GeoJSON) that belongs to a data cube."""
        features = db.session.query(
            Item.tile_id,
            Tile,
            func.ST_AsGeoJSON(Item.geom, 6, 3).cast(sqlalchemy.JSON).label('geom')
        ).distinct(Item.tile_id).filter(Item.collection_id == cube_id, Item.tile_id == Tile.id).all()

        return [feature.Tile.name if only_ids else feature.geom for feature in features], 200
Exemplo n.º 3
0
def winter():
    query = db.session.query(Tracks.lokalid, Tracks.rutenavn, Tracks.objtype,
                             func.ST_AsGeoJSON(Tracks.geog)).filter(
                                 Tracks.objtype != 'Fotrute').all()
    res = FeatureCollection([])
    for i, q in enumerate(query):
        new = Feature(properties={
            "LOKALID": q[0],
            "RUTENAVN": q[1],
            "OBJTYPE": q[2]
        },
                      geometry=loads(q[3]))
        res['features'].append(new)
    return jsonify(res)
Exemplo n.º 4
0
def get_user_trips():
    query = db.session.query(Tracks).join(Trips).join(User).filter(
        User.id == current_user.get_id()).with_entities(
            Tracks.lokalid, Tracks.rutenavn, Tracks.objtype,
            func.ST_AsGeoJSON(Tracks.geog)).all()

    res = FeatureCollection([])
    for i, q in enumerate(query):
        new = Feature(properties={
            "LOKALID": q[0],
            "RUTENAVN": q[1],
            "OBJTYPE": q[2]
        },
                      geometry=loads(q[3]))
        res['features'].append(new)

    return jsonify(res)
Exemplo n.º 5
0
    def get_grs_schema(self, grs_id):
        """Retrieve a Grid Schema definition with tiles associated."""
        schema = GridRefSys.query().filter(GridRefSys.id == grs_id).first()

        if schema is None:
            return 'GRS {} not found.'.format(grs_id), 404

        geom_table = schema.geom_table
        tiles = db.session.query(
            geom_table.c.tile,
            func.ST_AsGeoJSON(func.ST_Transform(geom_table.c.geom, 4326), 6, 3).cast(sqlalchemy.JSON).label('geom_wgs84')
        ).all()

        dump_grs = Serializer.serialize(schema)
        dump_grs['tiles'] = [dict(id=t.tile, geom_wgs84=t.geom_wgs84) for t in tiles]

        return dump_grs, 200
Exemplo n.º 6
0
    def get_grs_schema(cls,
                       grs_id,
                       bbox: Tuple[float, float, float, float] = None,
                       tiles=None):
        """Retrieve a Grid Schema definition with tiles associated."""
        schema: GridRefSys = GridRefSys.query().filter(
            GridRefSys.id == grs_id).first()

        if schema is None:
            return 'GRS {} not found.'.format(grs_id), 404

        geom_table = schema.geom_table
        srid_column = get_srid_column(geom_table.c, default_srid=4326)
        where = []
        if bbox is not None:
            x_min, y_min, x_max, y_max = bbox
            where.append(
                func.ST_Intersects(
                    func.ST_MakeEnvelope(x_min, y_min, x_max, y_max, 4326),
                    func.ST_Transform(
                        func.ST_SetSRID(geom_table.c.geom, srid_column),
                        4326)))

        if tiles:
            where.append(geom_table.c.tile.in_(tiles))

        tiles = db.session.query(
            geom_table.c.tile,
            func.ST_AsGeoJSON(
                func.ST_Transform(
                    func.ST_SetSRID(geom_table.c.geom, srid_column), 4326), 6,
                3).cast(
                    sqlalchemy.JSON).label('geom_wgs84')).filter(*where).all()

        dump_grs = Serializer.serialize(schema)
        dump_grs['tiles'] = [
            dict(id=t.tile, geom_wgs84=t.geom_wgs84) for t in tiles
        ]

        return dump_grs, 200