Ejemplo n.º 1
0
    def create_table_dict(self):
        self.metadata.info['srid'] = CONFIG.srid
        self.metadata.info['num_threads'] = self.get_option('numthreads')

        tables = OrderedDict()
        # first the update table: stores all modified routes, points
        uptable = UpdatedGeometriesTable(self.metadata, CONFIG.change_table)
        tables['updates'] = uptable

        # First we filter all route relations into an extra table.
        rfilt = FilteredTable(self.metadata, CONFIG.route_filter_table,
                              self.osmdata.relation,
                              text("(%s)" % CONFIG.relation_subset))
        tables['relfilter'] = rfilt

        # Then we create the connection between ways and relations.
        # This also adds geometries.
        relway = RelationWayTable(self.metadata, CONFIG.way_relation_table,
                                  self.osmdata.way, rfilt, osmdata=self.osmdata)
        tables['relway'] = relway

        # From that create the segmented table.
        segments = SegmentsTable(self.metadata, CONFIG.segment_table, relway,
                                 (relway.c.rels,))
        tables['segments'] = segments

        # hierarchy table for super relations
        rtree = RelationHierarchy(self.metadata, CONFIG.hierarchy_table, rfilt)
        tables['hierarchy'] = rtree

        # routes table: information about each route
        routes = self.routeinfo_class(self.metadata, CONFIG.route_table,
                                      rfilt, relway, rtree,
                                      CountryGrid(MetaData(), CONFIG.country_table))
        tables['routes'] = routes

        # finally the style table for rendering
        style = StyleTable(self.metadata, routes, segments, rtree,
                           conf.get('DEFSTYLE'), uptable)
        tables['style'] = style

        # optional table for guide posts
        if conf.isdef('GUIDEPOSTS'):
            cfg = conf.get('GUIDEPOSTS')
            filt = FilteredTable(self.metadata, cfg.table_name + '_view',
                                 self.osmdata.node, text(cfg.node_subset),
                                 view_only=True)
            tables['gp_filter'] = filt
            tables['guideposts'] = GuidePosts(self.metadata, filt)
        # optional table for network nodes
        if conf.isdef('NETWORKNODES'):
            cfg = conf.get('NETWORKNODES')
            filt = FilteredTable(self.metadata, cfg.table_name + '_view',
                                 self.osmdata.node,
                                 self.osmdata.node.c.tags.has_key(cfg.node_tag),
                                 view_only=True)
            tables['nnodes_filter'] = filt
            tables['networknodes'] = NetworkNodes(self.metadata, filt)

        return tables
 def init_tables(self, mapdb, segment_table, countries, shields):
     rels = mapdb.add_table(
         'src_rels', OsmSourceTables.create_relation_table(mapdb.metadata))
     hier = mapdb.add_table(
         'hierarchy', RelationHierarchy(mapdb.metadata, 'hierarchy', rels))
     mapdb.add_table(
         'test',
         Routes(mapdb.metadata, rels, segment_table, hier, countries,
                self.Config, shields))
     mapdb.create()
Ejemplo n.º 3
0
    def create_table_dict(self):
        self.metadata.info['srid'] = CONFIG.srid

        tables = OrderedDict()
        # first the update table:
        # stores all modified routes (no changes in guideposts or
        # network nodes are tracked)
        uptable = UpdatedGeometriesTable(self.metadata, CONFIG.change_table)
        tables['updates'] = uptable

        # segment table: route segments only
        segtable = RouteSegments(self.metadata,
                                 CONFIG.segment_table,
                                 self.osmdata,
                                 subset=CONFIG.relation_subset,
                                 geom_change=uptable)
        segtable.set_num_threads(self.get_option('numthreads'))
        tables['segments'] = segtable

        # hierarchy table for super relations
        r = self.osmdata.relation.data
        hiertable = RelationHierarchy(self.metadata,
                                      CONFIG.hierarchy_table,
                                      self.osmdata,
                                      subset=select([r.c.id]).where(
                                          text(CONFIG.relation_subset)))
        tables['hierarchy'] = hiertable

        # routes table: information about each route
        routetable = self.routeinfo_class(
            segtable, hiertable, CountryGrid(MetaData(), CONFIG.country_table))
        routetable.set_num_threads(self.get_option('numthreads'))
        tables['routes'] = routetable

        # finally the style table for rendering
        tables['style'] = self.segmentstyle_class(self.metadata, self.osmdata,
                                                  routetable, segtable,
                                                  hiertable)

        # optional table for guide posts
        if conf.isdef('GUIDEPOSTS'):
            tables['guideposts'] = GuidePosts(self.metadata, self.osmdata,
                                              uptable)
        # optional table for network nodes
        if conf.isdef('NETWORKNODES'):
            tables['networknodes'] = NetworkNodes(self.metadata, self.osmdata,
                                                  uptable)

        return tables
    def init_tables(self, mapdb, route_table, segment_table):
        rels = mapdb.add_table(
            'src_rels', OsmSourceTables.create_relation_table(mapdb.metadata))
        hier = mapdb.add_table(
            'hierarchy', RelationHierarchy(mapdb.metadata, 'hierarchy', rels))
        uptable = mapdb.add_table(
            'updates', UpdatedGeometriesTable(mapdb.metadata, 'updates'))

        mapdb.add_table(
            'test',
            StyleTable(mapdb.metadata, route_table, segment_table, hier,
                       self.Config(), uptable))
        mapdb.create()

        mapdb.insert_into('routes')\
            .line(1, name='A')\
            .line(2, name='B')\
            .line(3, name='C')
Ejemplo n.º 5
0
    def create_table_dict(self, symbol_factory, route_class=Routes):
        self.metadata.info['srid'] = self.site_config.DB_SRID
        self.metadata.info['num_threads'] = self.get_option('numthreads')

        tabname = self.site_config.DB_TABLES

        tables = OrderedDict()
        # first the update table: stores all modified routes, points
        uptable = UpdatedGeometriesTable(self.metadata, tabname.change)
        tables['updates'] = uptable

        # First we filter all route relations into an extra table.
        rfilt = FilteredTable(self.metadata, tabname.route_filter,
                              self.osmdata.relation,
                              text("(%s)" % self.site_config.DB_ROUTE_SUBSET))
        tables['relfilter'] = rfilt

        # Then we create the connection between ways and relations.
        # This also adds geometries.
        relway = RelationWayTable(self.metadata,
                                  tabname.way_relation,
                                  self.osmdata.way,
                                  rfilt,
                                  osmdata=self.osmdata)
        tables['relway'] = relway

        # From that create the segmented table.
        segments = SegmentsTable(self.metadata, tabname.segment, relway,
                                 (relway.c.rels, ))
        tables['segments'] = segments

        # hierarchy table for super relations
        rtree = RelationHierarchy(self.metadata, tabname.hierarchy, rfilt)
        tables['hierarchy'] = rtree

        # routes table: information about each route
        routes = route_class(self.metadata, rfilt, relway, rtree,
                             CountryGrid(MetaData(), tabname.country),
                             self.site_config.ROUTES, symbol_factory)
        tables['routes'] = routes

        # finally the style table for rendering
        style = StyleTable(self.metadata, routes, segments, rtree,
                           self.site_config.DEFSTYLE, uptable)
        tables['style'] = style

        # optional table for guide posts
        if self.site_config.GUIDEPOSTS is not None:
            cfg = self.site_config.GUIDEPOSTS
            filt = FilteredTable(self.metadata,
                                 cfg.table_name + '_view',
                                 self.osmdata.node,
                                 text(cfg.node_subset),
                                 view_only=True)
            tables['gp_filter'] = filt
            tables['guideposts'] = GuidePosts(self.metadata, filt, cfg)

        # optional table for network nodes
        if self.site_config.NETWORKNODES is not None:
            cfg = self.site_config.NETWORKNODES
            filt = FilteredTable(self.metadata,
                                 cfg.table_name + '_view',
                                 self.osmdata.node,
                                 self.osmdata.node.c.tags.has_key(
                                     cfg.node_tag),
                                 view_only=True)
            tables['nnodes_filter'] = filt
            tables['networknodes'] = NetworkNodes(self.metadata, filt, cfg)

        return tables
def setup_tables(db, route_class=Routes):
    if not db.get_option('no_engine'):
        country = CountryGrid(MetaData(), db.site_config.DB_TABLES.country)
        if not country.data.exists(db.engine):
            raise RuntimeError("No country table found.")

    db.set_metadata('srid', db.site_config.DB_SRID)
    db.set_metadata('num_threads', db.get_option('numthreads'))

    tabname = db.site_config.DB_TABLES

    # first the update table: stores all modified routes, points
    uptable = db.add_table('updates',
                           UpdatedGeometriesTable(db.metadata, tabname.change))

    # First we filter all route relations into an extra table.
    rfilt = db.add_table(
        'relfilter',
        FilteredTable(db.metadata, tabname.route_filter, db.osmdata.relation,
                      text(f"({db.site_config.DB_ROUTE_SUBSET})")))

    # Then we create the connection between ways and relations.
    # This also adds geometries.
    relway = db.add_table(
        'relway',
        RelationWayTable(db.metadata,
                         tabname.way_relation,
                         db.osmdata.way,
                         rfilt,
                         osmdata=db.osmdata))

    # From that create the segmented table.
    segments = db.add_table(
        'segments',
        SegmentsTable(db.metadata, tabname.segment, relway, (relway.c.rels, )))

    # hierarchy table for super relations
    rtree = db.add_table(
        'hierarchy', RelationHierarchy(db.metadata, tabname.hierarchy, rfilt))

    # routes table: information about each route
    routes = db.add_table(
        'routes',
        route_class(
            db.metadata, rfilt, relway, rtree,
            CountryGrid(MetaData(), tabname.country), db.site_config.ROUTES,
            ShieldFactory(db.site_config.ROUTES.symbols,
                          db.site_config.SYMBOLS)))

    # finally the style table for rendering
    db.add_table(
        'style',
        StyleTable(db.metadata, routes, segments, rtree,
                   db.site_config.DEFSTYLE, uptable))

    # optional table for guide posts
    if db.site_config.GUIDEPOSTS is not None:
        cfg = db.site_config.GUIDEPOSTS
        filt = db.add_table(
            'gp_filter',
            FilteredTable(db.metadata,
                          cfg.table_name + '_view',
                          db.osmdata.node,
                          text(cfg.node_subset),
                          view_only=True))
        db.add_table('guideposts', GuidePosts(db.metadata, filt, cfg))\
           .set_update_table(uptable)

    # optional table for network nodes
    if db.site_config.NETWORKNODES is not None:
        cfg = db.site_config.NETWORKNODES
        filt = db.add_table(
            'nnodes_filter',
            FilteredTable(db.metadata,
                          cfg.table_name + '_view',
                          db.osmdata.node,
                          db.osmdata.node.c.tags.has_key(cfg.node_tag),
                          view_only=True))
        db.add_table('networknodes', NetworkNodes(db.metadata, filt, cfg))
Ejemplo n.º 7
0
def step_impl(context, name, subset):
    r = context.osmdata.relation.data
    context.tables[name] = RelationHierarchy(MetaData(), name, context.osmdata,
                                             subset=select([r.c.id]).where(text(subset)))
    context.tables[name].data.create(context.engine)
    context.tables[name].construct(context.engine)
Ejemplo n.º 8
0
def step_impl(context, name):
    context.tables[name] = RelationHierarchy(MetaData(), name, context.osmdata)
    context.tables[name].data.create(context.engine)
    context.tables[name].construct(context.engine)
Ejemplo n.º 9
0
 def create_tables(self, db):
     return [RelationHierarchy(db.metadata, "test", db.osmdata.relation)]