예제 #1
0
def load_coverage(conf):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get('ogr_where', None)
        geom = load_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons']))
        bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        srs = conf['bbox_srs']
        bbox = conf['bbox']
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(','))
        geom = None

    return coverage(geom or bbox, SRS(srs))
예제 #2
0
파일: coverage.py 프로젝트: gijs/mapproxy
def load_coverage(conf):
    if "ogr_datasource" in conf:
        require_geom_support()
        srs = conf["ogr_srs"]
        datasource = conf["ogr_datasource"]
        if not re.match(r"^\w{2,}:", datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get("ogr_where", None)
        geom = load_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif "polygons" in conf:
        require_geom_support()
        srs = conf["polygons_srs"]
        geom = load_polygons(abspath(conf["polygons"]))
        bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        srs = conf["bbox_srs"]
        bbox = conf["bbox"]
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(","))
        geom = None

    return coverage(geom or bbox, SRS(srs))
예제 #3
0
def font_file(font_name):
    font_dir = base_config().image.font_dir
    font_name = font_name.replace(' ', '')
    if font_dir:
        abspath(font_dir)
        path = os.path.join(font_dir, font_name + '.ttf')
    else:
        path = pkg_resources.resource_filename(__name__, 'fonts/' + font_name + '.ttf')
    return path
예제 #4
0
파일: message.py 프로젝트: atrawog/mapproxy
def font_file(font_name):
    font_dir = base_config().image.font_dir
    if font_dir:
        abspath(font_dir)
    else:
        font_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fonts')
    font_name = font_name.replace(' ', '')
    path = os.path.join(font_dir, font_name + '.ttf')
    return path
예제 #5
0
def font_file(font_name):
    font_dir = base_config().image.font_dir
    font_name = font_name.replace(' ', '')
    if font_dir:
        abspath(font_dir)
        path = os.path.join(font_dir, font_name + '.ttf')
    else:
        path = pkg_resources.resource_filename(__name__, 'fonts/' + font_name + '.ttf')
    return path
예제 #6
0
파일: config.py 프로젝트: vartagg/mapproxy
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" %
                (conf["time"], ))
    if 'mtime' in conf:
        datasource = abspath(conf['mtime'])
        try:
            return os.path.getmtime(datasource)
        except OSError as ex:
            raise SeedConfigurationError(
                "can't parse last modified time from file '%s'." %
                (datasource, ), ex)
    deltas = {}
    for delta_type in ('weeks', 'days', 'hours', 'minutes', 'seconds'):
        deltas[delta_type] = conf.get(delta_type, 0)
    return timestamp_before(**deltas)
예제 #7
0
파일: coverage.py 프로젝트: wkke/mapproxy
def load_coverage(conf, base_path=None):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    else:
        return None
    return coverage(geom or bbox, SRS(srs))
예제 #8
0
def load_coverage(conf):
    if 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource)
        where = conf.get('ogr_where', None)
        bbox, geom = load_datasource(datasource, where)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        bbox, geom = load_polygons(abspath(conf['polygons']))
    else:
        srs = conf['bbox_srs']
        bbox = conf['bbox']
        if isinstance(bbox, basestring):
            bbox = map(float, bbox.split(','))
        geom = None

    return coverage(geom or bbox, SRS(srs))
        
예제 #9
0
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" % (conf["time"], ))
    if 'mtime' in conf:
        datasource = abspath(conf['mtime'])
        try:
            return os.path.getmtime(datasource)
        except OSError, ex:
            raise SeedConfigurationError(
                "can't parse last modified time from file '%s'." % (datasource, ), ex)
예제 #10
0
파일: config.py 프로젝트: imclab/mapproxy
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" %
                (conf["time"], ))
    if 'mtime' in conf:
        datasource = abspath(conf['mtime'])
        try:
            return os.path.getmtime(datasource)
        except OSError, ex:
            raise SeedConfigurationError(
                "can't parse last modified time from file '%s'." %
                (datasource, ), ex)
예제 #11
0
파일: config.py 프로젝트: Geodan/mapproxy
def before_timestamp_from_options(conf):
    """
    >>> import time
    >>> t = before_timestamp_from_options({'hours': 4})
    >>> time.time() - t - 4 * 60 * 60 < 1
    True
    """
    if 'time' in conf:
        try:
            return timestamp_from_isodate(conf['time'])
        except ValueError:
            raise SeedConfigurationError(
                "can't parse time '%s'. should be ISO time string" % (conf["time"], ))
    if 'mtime' in conf:
        datasource = abspath(conf['mtime'])
        try:
            return os.path.getmtime(datasource)
        except OSError as ex:
            raise SeedConfigurationError(
                "can't parse last modified time from file '%s'." % (datasource, ), ex)
    deltas = {}
    for delta_type in ('weeks', 'days', 'hours', 'minutes', 'seconds'):
        deltas[delta_type] = conf.get(delta_type, 0)
    return timestamp_before(**deltas)
예제 #12
0
파일: coverage.py 프로젝트: LKajan/mapproxy
def load_coverage(conf, base_path=None):
    clip = False
    if 'clip' in conf:
        clip = conf['clip']

    if 'union' in conf:
        parts = []
        for cov in conf['union']:
            parts.append(load_coverage(cov))
        return union_coverage(parts, clip=clip)
    elif 'intersection' in conf:
        parts = []
        for cov in conf['intersection']:
            parts.append(load_coverage(cov))
        return intersection_coverage(parts, clip=clip)
    elif 'difference' in conf:
        parts = []
        for cov in conf['difference']:
            parts.append(load_coverage(cov))
        return diff_coverage(parts, clip=clip)
    elif 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'expire_tiles' in conf:
        require_geom_support()
        filename = abspath(conf['expire_tiles'])
        geom = load_expire_tiles(filename)
        _, geom = build_multipolygon(geom, simplify=False)
        return coverage(geom, SRS(3857))
    else:
        return None

    return coverage(geom or bbox, SRS(srs), clip=clip)
예제 #13
0
def load_coverage(conf, base_path=None):
    clip = False
    if 'clip' in conf:
        clip = conf['clip']

    if 'union' in conf:
        parts = []
        for cov in conf['union']:
            parts.append(load_coverage(cov))
        return union_coverage(parts, clip=clip)
    elif 'intersection' in conf:
        parts = []
        for cov in conf['intersection']:
            parts.append(load_coverage(cov))
        return intersection_coverage(parts, clip=clip)
    elif 'difference' in conf:
        parts = []
        for cov in conf['difference']:
            parts.append(load_coverage(cov))
        return diff_coverage(parts, clip=clip)
    elif 'ogr_datasource' in conf:
        require_geom_support()
        srs = conf['ogr_srs']
        datasource = conf['ogr_datasource']
        if not re.match(r'^\w{2,}:', datasource):
            # looks like a file and not PG:, MYSQL:, etc
            # make absolute path
            datasource = abspath(datasource, base_path=base_path)
        where = conf.get('ogr_where', None)
        geom = load_ogr_datasource(datasource, where)
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'polygons' in conf:
        require_geom_support()
        srs = conf['polygons_srs']
        geom = load_polygons(abspath(conf['polygons'], base_path=base_path))
        bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'bbox' in conf:
        srs = conf.get('bbox_srs') or conf['srs']
        bbox = conf['bbox']
        if isinstance(bbox, string_type):
            bbox = [float(x) for x in bbox.split(',')]
        geom = None
    elif 'datasource' in conf:
        require_geom_support()
        datasource = conf['datasource']
        srs = conf['srs']
        if isinstance(datasource, (list, tuple)):
            bbox = datasource
            geom = None
        elif bbox_string_re.match(datasource):
            bbox = [float(x) for x in datasource.split(',')]
            geom = None
        else:
            if not re.match(r'^\w{2,}:', datasource):
                # looks like a file and not PG:, MYSQL:, etc
                # make absolute path
                datasource = abspath(datasource, base_path=base_path)
            where = conf.get('where', None)
            geom = load_datasource(datasource, where)
            bbox, geom = build_multipolygon(geom, simplify=True)
    elif 'expire_tiles' in conf:
        require_geom_support()
        filename = abspath(conf['expire_tiles'])
        geom = load_expire_tiles(filename)
        _, geom = build_multipolygon(geom, simplify=False)
        return coverage(geom, SRS(3857))
    else:
        return None

    return coverage(geom or bbox, SRS(srs), clip=clip)