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
Beispiel #2
0
def setup_site(confname, script_name='', debug=False):
    globalconf = {}
    for var in dir(sys.modules['config.defaults']):
        if var.isupper():
            globalconf[var] = getattr(sys.modules['config.defaults'], var)

    site_cfg = {}
    try:
        __import__('config.sites.' + confname)
        site_cfg = getattr(sys.modules['config.sites.' + confname], 'SITE', {})
    except ImportError:
        print("Missing config for site '%s'. Skipping." % site)
        raise

    os_environ['ROUTEMAPDB_CONF_MODULE'] = 'maps.%s' % confname
    from db import conf as db_config
    mapdb_pkg = 'db.%s' % db_config.get('MAPTYPE')
    mapdb_class = __import__(mapdb_pkg, globals(), locals(), ['DB'], 0).DB

    mapdb = mapdb_class(_MapDBOption())

    app = cherrypy.tree.mount(
        Trails(mapdb,
               db_config.get('MAPTYPE'),
               globalconf['LANGUAGES'],
               debug=debug), script_name + '/',
        {
            '/favicon.ico': {
                'tools.staticfile.on':
                True,
                'tools.staticfile.filename':
                '%s/img/map/map_%s.ico' % (globalconf['MEDIA_ROOT'], confname)
            }
        })

    app.config['DB'] = {'map': mapdb}
    app.config['Global'] = globalconf
    app.config['Global']['BASENAME'] = confname
    app.config['Global']['MAPTYPE'] = db_config.get('MAPTYPE')
    app.config['Site'] = site_cfg

    # now disable trailing slash
    cherrypy.config.update({'tools.trailing_slash.on': False})
def setup_site(confname, script_name='', debug=False):
    globalconf = {}
    for var in dir(sys.modules['config.defaults']):
        if var.isupper():
            globalconf[var] = getattr(sys.modules['config.defaults'], var)

    site_cfg = {}
    try:
        __import__('config.sites.' + confname)
        site_cfg = getattr(sys.modules['config.sites.' + confname], 'SITE', {})
    except ImportError:
        print("Missing config for site '%s'. Skipping." % site)
        raise

    os_environ['ROUTEMAPDB_CONF_MODULE'] = 'maps.%s' % confname
    from db import conf as db_config
    mapdb_pkg = 'db.%s' % db_config.get('MAPTYPE')
    mapdb_class = __import__(mapdb_pkg, globals(), locals(), ['DB'], 0).DB

    mapdb = mapdb_class(_MapDBOption())

    app = cherrypy.tree.mount(Trails(mapdb, db_config.get('MAPTYPE'),
                                     globalconf['LANGUAGES'], debug=debug),
                              script_name + '/',
                              {
                                  '/favicon.ico':
                                  {
                                      'tools.staticfile.on': True,
                                      'tools.staticfile.filename':
                                        '%s/img/map/map_%s.ico' %
                                        (globalconf['MEDIA_ROOT'], confname)
                                  }
                              })

    app.config['DB'] = { 'map' : mapdb }
    app.config['Global'] = globalconf
    app.config['Global']['BASENAME'] = confname
    app.config['Global']['MAPTYPE'] = db_config.get('MAPTYPE')
    app.config['Site'] = site_cfg

    # now disable trailing slash
    cherrypy.config.update({'tools.trailing_slash.on': False })
Beispiel #4
0
import os
import cairo
from math import pi
from xml.dom.minidom import parse
from xml.parsers.expat import ExpatError

import gi
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
gi.require_version('Rsvg', '2.0')
from gi.repository import Pango, PangoCairo, Rsvg

from db.configs import ShieldConfiguration
from db import conf

CONFIG = conf.get('SYMBOLS', ShieldConfiguration)


def _parse_color(color):
    if color in CONFIG.color_names:
        return color, CONFIG.color_names[color]

    m = re.match('#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$', color)
    if m:
        return color[1:], ((1.0 + int(m.group(1), 16)) / 256.0,
                           (1.0 + int(m.group(2), 16)) / 256.0,
                           (1.0 + int(m.group(3), 16)) / 256.0)

    return None

from collections import namedtuple, OrderedDict

import osgende
from osgende.update import UpdatedGeometriesTable
from osgende.relations import RouteSegments, RelationHierarchy
from osgende.tags import TagStore

from sqlalchemy import MetaData, select, text

from db.tables.countries import CountryGrid
from db.tables.routes import RouteInfo, RouteSegmentStyle
from db.tables.route_nodes import GuidePosts, NetworkNodes
from db.configs import RouteDBConfig
from db import conf

CONFIG = conf.get('ROUTEDB', RouteDBConfig)


class DB(osgende.MapDB):
    routeinfo_class = RouteInfo
    segmentstyle_class = RouteSegmentStyle

    def __init__(self, options):
        setattr(options, 'schema', CONFIG.schema)
        osgende.MapDB.__init__(self, options)

        country = CountryGrid(MetaData(), CONFIG.country_table)
        if not self.get_option('no_engine') and not country.data.exists(
                self.engine):
            raise RuntimeError("No country table found.")
from collections import namedtuple, OrderedDict

import osgende
from osgende.generic import FilteredTable
from osgende.common.tags import TagStore
from osgende.lines import GroupedWayTable

from sqlalchemy import text, select, func, and_, column, exists, not_

from db.tables.piste import PisteRoutes, PisteWayInfo
from db.tables.piste import _basic_tag_transform as piste_tag_transform
from db.configs import SlopeDBConfig, PisteTableConfig
from db.routes_maptype import DB as RoutesDB
from db import conf

CONF = conf.get('ROUTEDB', SlopeDBConfig)
PISTE_CONF = conf.get('PISTE', PisteTableConfig)


class DB(RoutesDB):
    routeinfo_class = PisteRoutes

    def create_tables(self):
        # all the route stuff we take from the RoutesDB implmentation
        tables = self.create_table_dict()

        # now create the additional joined ways
        subset = and_(text(CONF.way_subset),
                      column('id').notin_(select([tables['relway'].c.id])))
        filt = FilteredTable(self.metadata,
                             PISTE_CONF.way_table_name + '_view',
Beispiel #7
0
from shapely.ops import linemerge

from db.common.symbols import ShieldFactory
from db.common.route_types import Network
from db.configs import RouteTableConfig
from db import conf

import sqlalchemy as sa
from sqlalchemy.sql import functions as saf
from sqlalchemy.dialects.postgresql import JSONB
from geoalchemy2 import Geometry
from geoalchemy2.shape import from_shape

log = logging.getLogger(__name__)

ROUTE_CONF = conf.get('ROUTES', RouteTableConfig)

class RouteRow(dict):
    fields = set(('id', 'intnames', 'name', 'level', 'ref', 'itinary', 'network', 'top', 'geom', 'symbol', 'country'))

    def __init__(self, id_):
        for attr in self.fields:
            self[attr] = None

        self['id'] = id_
        self['intnames'] = {}
        self['level'] = Network.LOC()

    def __getattr__(self, name):
        return self[name]
                       select, func, Index, text, BigInteger
from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, array
from geoalchemy2 import Geometry
from geoalchemy2.shape import to_shape, from_shape

from shapely.ops import linemerge

from osgende.relations import Routes
from osgende.tags import TagStore

from db.configs import RouteTableConfig, RouteStyleTableConfig
from db import conf
from db.common.symbols import ShieldFactory
from db.tables.styles import SegmentStyle

ROUTE_CONF = conf.get('ROUTES', RouteTableConfig)

class RouteInfo(Routes):

    def __init__(self, segments, hierarchy, countries):
        super().__init__(ROUTE_CONF.table_name, segments, hiertable=hierarchy)
        self.country_table = countries
        self.symbols = ShieldFactory(*ROUTE_CONF.symbols)

    def columns(self):
        return (Column('name', String),
                Column('intnames', HSTORE),
                Column('symbol', String),
                Column('country', String(length=3)),
                Column('network', String(length=2)),
                Column('level', SmallInteger),
Beispiel #9
0
    # setup logging
    logging.basicConfig(format='%(asctime)s %(message)s',
                        level=options.loglevel,
                        datefmt='%y-%m-%d %H:%M:%S')

    mapname = 'hiking' if options.routemap == 'db' else options.routemap
    os.environ['ROUTEMAPDB_CONF_MODULE'] = 'maps.%s' % mapname

    try:
        from db import conf
    except ImportError:
        print("Cannot find route map named '%s'." % options.routemap)
        raise

    try:
        mapdb_pkg = 'db.%s' % conf.get('MAPTYPE')
        __import__(mapdb_pkg)
        mapdb_class = getattr(sys.modules[mapdb_pkg], 'DB')
    except ImportError:
        print("Unknown map type '%s'." % conf.get('MAPTYPE'))
        raise

    if options.routemap != 'db' or options.action == 'update':
        mapdb = mapdb_class(options)

        status = mapdb.osmdata.status
        with mapdb.engine.begin() as conn:
            basemap_date = conn.execute(
                status.select().where(status.c.part == 'base')).fetchone()
            if options.routemap == 'db':
                map_date = conn.scalar(select([sql_min(status.c.sequence)]))
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
""" Various tables for nodes in a route network.
"""

from re import compile as re_compile

from sqlalchemy import Column, String, text
from osgende.nodes import NodeSubTable
from db.configs import GuidePostConfig, NetworkNodeConfig
from db import conf


GUIDEPOST_CONF = conf.get('GUIDEPOSTS', GuidePostConfig)

class GuidePosts(NodeSubTable):
    """ Information about guide posts. """
    elepattern = re_compile('[\\d.]+')

    def __init__(self, meta, osmdata, geom_change=None):
        super().__init__(meta, GUIDEPOST_CONF.table_name, osmdata,
                         subset=text(GUIDEPOST_CONF.node_subset),
                         geom_change=geom_change)

    def columns(self):
        return (Column('name', String),
                Column('ele', String)
               )
Beispiel #11
0
"""

from sqlalchemy import Column, String, SmallInteger, Integer, Boolean, \
                       ForeignKey, select, func, Index, text, BigInteger
from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, array
from geoalchemy2 import Geometry

from osgende.relations import Routes
from osgende.ways import Ways

from db import conf
from db.common.symbols import ShieldFactory
from db.tables.styles import SegmentStyle
from db.configs import PisteTableConfig

CONF = conf.get('PISTE', PisteTableConfig)

def _create_piste_columns(name):
    return [Column('name', String),
            Column('intnames', HSTORE),
            Column('symbol', String),
            Column('difficulty', SmallInteger),
            Column('piste', SmallInteger),
            Index('idx_%s_iname' % name, text('upper(name)'))
           ]

def _basic_tag_transform(osmid, tags):
    outtags = { 'intnames' : {} }

    # determine name
    if 'piste:name' in tags:
Beispiel #12
0
                       select, func, Index, text, BigInteger
from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, array
from geoalchemy2 import Geometry
from geoalchemy2.shape import to_shape, from_shape

from shapely.ops import linemerge

from osgende.relations import Routes
from osgende.tags import TagStore

from db.configs import RouteTableConfig, RouteStyleTableConfig
from db import conf
from db.common.symbols import ShieldFactory
from db.tables.styles import SegmentStyle

ROUTE_CONF = conf.get('ROUTES', RouteTableConfig)


class RouteInfo(Routes):
    def __init__(self, segments, hierarchy, countries):
        super().__init__(ROUTE_CONF.table_name, segments, hiertable=hierarchy)
        self.country_table = countries
        self.symbols = ShieldFactory(*ROUTE_CONF.symbols)

    def columns(self):
        return (Column('name', String), Column('intnames', HSTORE),
                Column('symbol', String), Column('country', String(length=3)),
                Column('network', String(length=2)),
                Column('level', SmallInteger), Column('top', Boolean),
                Column(
                    'geom',
Beispiel #13
0
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
""" Various tables for nodes in a route network.
"""

from re import compile as re_compile

import sqlalchemy as sa
from geoalchemy2 import Geometry

from osgende.generic import TransformedTable
from osgende.common.tags import TagStore
from db.configs import GuidePostConfig, NetworkNodeConfig
from db import conf

GUIDEPOST_CONF = conf.get('GUIDEPOSTS', GuidePostConfig)


class GuidePosts(TransformedTable):
    """ Information about guide posts. """
    elepattern = re_compile('[\\d.]+')

    def __init__(self, meta, source, updates):
        self.srid = meta.info.get('srid', source.c.geom.type.srid)
        super().__init__(meta, GUIDEPOST_CONF.table_name, source)
        self.updates = updates

    def add_columns(self, table, src):
        table.append_column(sa.Column('name', sa.String))
        table.append_column(sa.Column('ele', sa.String))
        table.append_column(
Beispiel #14
0
from collections import namedtuple, OrderedDict

import osgende
from osgende.update import UpdatedGeometriesTable
from osgende.relations import RouteSegments, RelationHierarchy
from osgende.tags import TagStore

from sqlalchemy import MetaData, select, text

from db.tables.countries import CountryGrid
from db.tables.routes import RouteInfo, RouteSegmentStyle
from db.tables.route_nodes import GuidePosts, NetworkNodes
from db.configs import RouteDBConfig
from db import conf

CONFIG = conf.get('ROUTEDB', RouteDBConfig)


class DB(osgende.MapDB):
    routeinfo_class = RouteInfo
    segmentstyle_class = RouteSegmentStyle

    def __init__(self, options):
        setattr(options, 'schema', CONFIG.schema)
        osgende.MapDB.__init__(self, options)

        country = CountryGrid(MetaData(), CONFIG.country_table)
        if not self.get_option('no_engine') and not country.data.exists(self.engine):
            raise RuntimeError("No country table found.")

    def create_tables(self):
import os
import cairo
from math import pi
from xml.dom.minidom import parse
from xml.parsers.expat import ExpatError

import gi
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
gi.require_version('Rsvg', '2.0')
from gi.repository import Pango, PangoCairo, Rsvg

from db.configs import ShieldConfiguration
from db import conf

CONFIG = conf.get('SYMBOLS', ShieldConfiguration)

def _parse_color(color):
    if color in CONFIG.color_names:
        return color, CONFIG.color_names[color]

    m = re.match('#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$', color)
    if m:
        return color[1:], ((1.0+int(m.group(1),16))/256.0,
                           (1.0+int(m.group(2),16))/256.0,
                           (1.0+int(m.group(3),16))/256.0)

    return None

def _parse_ref(tags):
    if 'ref' in tags:
Beispiel #16
0
from collections import namedtuple, OrderedDict

import osgende
from osgende.relations import RouteSegments
from osgende.ways import JoinedWays
from osgende.tags import TagStore

from sqlalchemy import text, select, func, and_, column, exists, not_

from db.tables.piste import PisteRouteInfo, PisteWayInfo, PisteSegmentStyle
from db.tables.piste import _basic_tag_transform as piste_tag_transform
from db.configs import SlopeDBConfig, PisteTableConfig
from db.routes import DB as RoutesDB
from db import conf

CONF = conf.get('ROUTEDB', SlopeDBConfig)
PISTE_CONF = conf.get('PISTE', PisteTableConfig)

class DB(RoutesDB):
    routeinfo_class = PisteRouteInfo
    segmentstyle_class = PisteSegmentStyle

    def create_tables(self):
        # all the route stuff we take from the RoutesDB implmentation
        tables = vars(super().create_tables())

        # now create the additional joined ways
        subset = and_(text(CONF.way_subset),
                      not_(exists().where(column('id') == func.any(tables['segments'].data.c.ways))))
        ways = PisteWayInfo(self.metadata, self.osmdata,
                            subset=subset, geom_change=tables['updates'])
    # setup logging
    logging.basicConfig(format='%(asctime)s %(message)s', level=options.loglevel,
                        datefmt='%y-%m-%d %H:%M:%S')

    mapname = 'hiking' if options.routemap == 'db' else options.routemap
    os.environ['ROUTEMAPDB_CONF_MODULE'] = 'maps.%s' % mapname

    try:
        from db import conf
    except ImportError:
        print("Cannot find route map named '%s'." % options.routemap)
        raise

    try:
        mapdb_pkg = 'db.%s' % conf.get('MAPTYPE')
        __import__(mapdb_pkg)
        mapdb_class = getattr(sys.modules[mapdb_pkg], 'DB')
    except ImportError:
        print("Unknown map type '%s'." % conf.get('MAPTYPE'))
        raise

    if options.routemap != 'db' or options.action == 'update':
        mapdb = mapdb_class(options)

        status = mapdb.osmdata.status
        with mapdb.engine.begin() as conn:
            basemap_date = conn.execute(status.select().where(status.c.part == 'base')).fetchone()
            if options.routemap == 'db':
                map_date = conn.scalar(select([sql_min(status.c.sequence)]))
            else: