示例#1
0
def get_tileservice(environ):
    global _tilecache_service

    try:
        return _tilecache_service
    except NameError:
        pass

    from medin.templates import TemplateLookup
    from cStringIO import StringIO
    from ConfigParser import ConfigParser

    # get the config information by merging the current environment
    # with the config template
    template_lookup = TemplateLookup(environ)
    lookup = template_lookup.lookup()
    mappath = os.path.join('config', 'tilecache.cfg')
    cache_dir = os.path.join(environ.root, 'tmp')
    template = lookup.get_template(mappath)
    cfg = template.render(cache_dir=cache_dir)

    # create the service from our configuration
    config = ConfigParser()
    cfg_fp = StringIO(cfg)
    config.readfp(cfg_fp)

    _tilecache_service = TileService.loadConfig(config)

    return _tilecache_service
示例#2
0
    def __call__(self, environ, start_response):
        import os.path
        import medin.spatial

        self.prepareSOAP(environ)
        parser = self.request()
        if not parser:
            raise HTTPError(
                '404 Not Found', 'The metadata record does not exist: %s' %
                environ['selector.vars']['gid'])

        # Check if the client needs a new version
        headers = []
        date = get_metadata_date(environ, parser)
        if date:
            etag = check_etag(environ, date)
            headers.extend([('Etag', etag),
                            ('Cache-Control', 'no-cache, must-revalidate')])

        bboxes = parser.bboxes()
        if not bboxes:
            raise HTTPError(
                '404 Not Found',
                'The metadata record does not have a geographic bounding box')

        # ensure the background raster datasource has been created
        template_lookup = TemplateLookup(environ)
        lookup = template_lookup.lookup()
        rasterpath = background_raster(lookup, environ)

        # create the mapfile from its template
        mappath = os.path.join('config', 'metadata-extent.xml')
        template = lookup.get_template(mappath)
        mapfile = template.render(root_dir=environ.root)

        # create the image
        image = medin.spatial.metadata_image(bboxes, mapfile)

        # serialise the image
        bytes = image.tostring('png')

        headers.append(('Content-Type', 'image/png'))

        start_response('200 OK', headers)
        return [bytes]
示例#3
0
    def __call__(self, environ, start_response):
        import os.path
        import medin.spatial

        self.prepareSOAP(environ)
        parser = self.request()
        if not parser:
            raise HTTPError('404 Not Found', 'The metadata record does not exist: %s' % environ['selector.vars']['gid'])

        # Check if the client needs a new version
        headers = []
        date = get_metadata_date(environ, parser)
        if date:
            etag = check_etag(environ, date)
            headers.extend([('Etag', etag),
                            ('Cache-Control', 'no-cache, must-revalidate')])

        bboxes = parser.bboxes()
        if not bboxes:
            raise HTTPError('404 Not Found', 'The metadata record does not have a geographic bounding box')

        # ensure the background raster datasource has been created
        template_lookup = TemplateLookup(environ)
        lookup = template_lookup.lookup()
        rasterpath = background_raster(lookup, environ)

        # create the mapfile from its template
        mappath = os.path.join('config', 'metadata-extent.xml')
        template = lookup.get_template(mappath)
        mapfile = template.render(root_dir=environ.root)

        # create the image
        image = medin.spatial.metadata_image(bboxes, mapfile)

        # serialise the image
        bytes = image.tostring('png')

        headers.append(('Content-Type', 'image/png'))

        start_response('200 OK', headers)
        return [bytes]