def get_tile_config():
    import TileStache as tilestache
    pth = os.path.join(TILE_CONFIG_DIR, 'tiles.cfg')
    try:
        cfg = tilestache.parseConfigfile(pth)
    except (IOError, ValueError):
        cfg = None
    return cfg
 def __call__(self, environ, start_response):
     """ Handle a request, using PATH_INFO and QUERY_STRING from environ.
     
         There are six required query string parameters: width, height,
         xmin, ymin, xmax and ymax. Layer name must be supplied in PATH_INFO.
     """
     if self.autoreload: # re-parse the config file on every request
         try:
             self.config = TileStache.parseConfigfile(self.config_path)
         except Exception, e:
             raise Core.KnownUnknown("Error loading Tilestache config file:\n%s" % str(e))
Exemple #3
0
 def GET(layer, zoom, x, y):
     ini = time.clock()
     path_configfile = os.path.join(request.folder, 'static/tilestache.cfg')
     config2 = ts.parseConfigfile(path_configfile)
     formato = request.extension
     token_version = "x234dffx"
     response.headers["Cache-Control"] = "public, max-age=100"
     if request.env.http_if_none_match == token_version:
         raise HTTP(304, "", **response.headers)
     else:
         try:
             layer2 = config2.layers[layer]
             coord = ts.Coordinate(int(y), int(x), int(zoom))
             mime_type, tile_content = ts.getTile(layer2, coord, formato)
         except:
             raise HTTP(404)
         response.headers["Content-Type"] = mime_type
         response.headers["Etag"] = token_version
         raise HTTP(200, tile_content, **response.headers)
     return locals()
    (options, args) = parser.parse_args()

    if options.include_paths:
        for p in options.include_paths.split(':'):
            path.insert(0, p)

    import TileStache
    
    try:
        if options.config is None:
            raise TileStache.Core.KnownUnknown('Missing required configuration (--config) parameter.')

        if options.layer is None:
            raise TileStache.Core.KnownUnknown('Missing required layer (--layer) parameter.')

        config = TileStache.parseConfigfile(options.config)

        if options.layer not in config.layers:
            raise TileStache.Core.KnownUnknown('"%s" is not a layer I know about. Here are some that I do know about: %s.' % (options.layer, ', '.join(sorted(config.layers.keys()))))

        provider = Provider(config.layers[options.layer], options.verbose, options.ignore_cached)
        
        try:
            outfile = args[0]
        except IndexError:
            raise BadComposure('Error: Missing output file.')
        
        if options.center and options.extent:
            raise BadComposure("Error: bad map coverage, center and extent can't both be set.")
        
        elif options.extent and options.dimensions and options.zoom:
    (options, args) = parser.parse_args()

    if options.include_paths:
        for p in options.include_paths.split(':'):
            path.insert(0, p)

    import TileStache
    
    try:
        if options.config is None:
            raise TileStache.Core.KnownUnknown('Missing required configuration (--config) parameter.')

        if options.layer is None:
            raise TileStache.Core.KnownUnknown('Missing required layer (--layer) parameter.')

        config = TileStache.parseConfigfile(options.config)

        if options.layer not in config.layers:
            raise TileStache.Core.KnownUnknown('"%s" is not a layer I know about. Here are some that I do know about: %s.' % (options.layer, ', '.join(sorted(config.layers.keys()))))

        provider = Provider(config.layers[options.layer], options.verbose, options.ignore_cached)
        
        try:
            outfile = args[0]
        except IndexError:
            raise BadComposure('Error: Missing output file.')
        
        if options.center and options.extent:
            raise BadComposure("Error: bad map coverage, center and extent can't both be set.")
        
        elif options.extent and options.dimensions and options.zoom:
        yvar_end = float(opts.y_variable[2])

        o_format = output[-4:]
        assert o_format in ('.png', '.jpg')
        i_format = source[-4:]
        assert i_format in ('.png', '.jpg')
        c_format = config_path[-4:]
        assert c_format in ('.cfg')

    except Exception, e:
        print >> sys.stderr, e
        print >> sys.stderr, 'Usage: python test-grid.py <output>'
        sys.exit(1)

    try:
        config = TileStache.parseConfigfile(config_path)
        default_vars = config.layers[layer].provider.defaults
    except Exception, e:
        print >> sys.stderr, e
        print >> sys.stderr, 'Error parsing config file'
        sys.exit(1)

    mask = Image.open(source)
    print "edge:", default_vars['edge_tile']
    edge_texture = Image.open(default_vars['edge_tile'])
    display_texture = Image.open(texture)

    grid = Image.new("RGB",
                     (mask.size[0] * columns + buff *
                      (columns - 1), mask.size[1] * rows + buff * (rows - 1)),
                     "#FFFFFF")
Exemple #7
0
        "-v",
        "--verbose",
        dest="verbose",
        help="Enable verbose logging. Default is false.",
        action="store_true",
        default=False,
    )

    options, args = parser.parse_args()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    # Some day, Python will have a -I flag...

    if options.include:
        for path in options.include.split(":"):
            logging.debug("include %s to Python's sys.path")
            sys.path.insert(0, path)

    logging.info("start server on %s:%s" % (options.host, options.port))

    # http://docs.python.org/library/wsgiref.html

    httpd = make_server(options.host, int(options.port), application)
    httpd.base_environ["TILESTACHE_CONFIG"] = TileStache.parseConfigfile(options.config)

    httpd.serve_forever()
Exemple #8
0
    data =  response.read()
    pfTile = vector_pb2.VectorMapTile()
    pfTile.ParseFromString(data)
    return Response(
        content_type="text/plain",
        body=pfTile.__str__()
    )

@view_config(route_name='tileFinder')
def getTile(request):
    proj = vectormap.GoogleProjection()
    latlon = map(float,request.matchdict['latlon'].split(','))
    zoom = int(request.matchdict['zoom'])
    tile = proj.fromLLtoTileId(latlon, zoom)
    return Response(
        content_type="text/plain",
        body=tile.__str__()
    )

if __name__ == '__main__':
    config_path = 'tilestache.cfg'
    tsConfig = TileStache.parseConfigfile(config_path)
    config = Configurator()
    config.add_route('ref', '/ref/{zoom}/{y}/{x}')
    config.add_route('tileFinder', '/finder/{zoom}/{latlon}')
    config.scan('server')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8088, app)
    print 'starting server...'
    server.serve_forever()