Exemple #1
0
def request(config_content, layer_name, format, row, column, zoom):
    '''
    Helper method to write config_file to disk and do
    request
    '''
    if sys.version_info.major == 2:
        is_string = isinstance(config_content, basestring)
    else:
        is_string = isinstance(config_content, (str, bytes))

    if is_string:
        absolute_file_name = create_temp_file(config_content)
        config = parseConfig(absolute_file_name)

    else:
        config = parseConfig(config_content)

    layer = config.layers[layer_name]
    coord = Coordinate(int(row), int(column), int(zoom))
    mime_type, tile_content = getTile(layer, coord, format)

    if is_string:
        os.remove(absolute_file_name)

    return mime_type, tile_content
Exemple #2
0
def request(config_content, layer_name, format, row, column, zoom):
    '''
    Helper method to write config_file to disk and do
    request
    '''
    if sys.version_info.major == 2:
        is_string = isinstance(config_content, str)
    else:
        is_string = isinstance(config_content, (str, bytes))

    if is_string:
        absolute_file_name = create_temp_file(config_content)
        config = parseConfig(absolute_file_name)

    else:
        config = parseConfig(config_content)

    layer = config.layers[layer_name]
    coord = Coordinate(int(row), int(column), int(zoom))
    mime_type, tile_content = getTile(layer, coord, format)

    if is_string:
        os.remove(absolute_file_name)

    return mime_type, tile_content
Exemple #3
0
    def __init__(self, tilestache_cfg=None, **kwargs):
        if not tilestache_cfg:
            raise ValueError('tilestache_cfg is a required parameter')

        self.raw_config = tilestache_cfg
        # TODO: refatoar isto, pois pode ser um objeto também
        if isinstance(tilestache_cfg, six.string_types) or isinstance(tilestache_cfg, dict):
            self.config = parseConfig(tilestache_cfg)
        else:
            self.config = tilestache_cfg
Exemple #4
0
def get_tilestache_config():
    """
    Gets the config for tilestache.
    this returns an object that can be used by
    tilestache and serve tiles.

    There is two methods, and while the method get_Config
    only gets a JSON representation, this one uses the former
    to construct a full TileStache object
    """
    return parseConfig(get_config())
Exemple #5
0
    def __init__(self, config_dict=None):

        if config_dict:
            self.config_dict = config_dict
            self.init_cache()
        else:
            self.init_cache()
            self.config_dict.update({'cache': self.cache.cache_dict})
        self.config = parseConfig(self.config_dict)
        try:
            self.init_layers()
        except:
            pass
    def test_config(self):
        '''Read configuration and verify successful read'''

        config_content = {
           "layers":{
              "memcache_osm":{
                 "provider":{
                    "name":"proxy",
                    "url": "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png"
                 }
              }
            },
            "cache": {
                "name": "Memcache",
                "servers": ["127.0.0.1:11211"],
                "revision": 4
            }
        }

        config = parseConfig(config_content)
        self.assertEqual(config.cache.servers, ["127.0.0.1:11211"])
        self.assertEqual(config.cache.revision, 4)
        self.assertTrue(config.layers['memcache_osm'])
        self.assertTrue(isinstance(config.layers['memcache_osm'], Core.Layer))
Exemple #7
0
    def test_config(self):
        '''Read configuration and verify successful read'''

        config_content = {
            "layers": {
                "memcache_osm": {
                    "provider": {
                        "name": "proxy",
                        "url": "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png"
                    }
                }
            },
            "cache": {
                "name": "Memcache",
                "servers": ["127.0.0.1:11211"],
                "revision": 4
            }
        }

        config = parseConfig(config_content)
        self.assertEqual(config.cache.servers, ["127.0.0.1:11211"])
        self.assertEqual(config.cache.revision, 4)
        self.assertTrue(config.layers['memcache_osm'])
        self.assertTrue(isinstance(config.layers['memcache_osm'], Core.Layer))
Exemple #8
0
                  help='Layer name from configuration.')

pathinfo_pat = re.compile(r'^(?P<z>\d+)/(?P<x>\d+)/(?P<y>\d+)\.(?P<e>\w+)$')

if __name__ == '__main__':
    options, paths = parser.parse_args()

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

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

        config = parseConfig(options.config)

        if options.layer not in config.layers:
            raise 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()))))

        layer = config.layers[options.layer]

        coords = []

        for path in paths:
            path_ = pathinfo_pat.match(path)

            if path_ is None:
                raise KnownUnknown(
Exemple #9
0
 def _load_remote_config(self, response):
     data = response.json()
     return parseConfig(data)
    from TileStache import parseConfig, getTile
    from TileStache.Core import KnownUnknown
    from TileStache.Caches import Disk, Multi

    from ModestMaps.Core import Coordinate
    from ModestMaps.Geo import Location

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

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

        config = parseConfig(options.config)

        if options.layer in ('ALL', 'ALL LAYERS') and options.layer not in config.layers:
            # clean every layer in the config
            layers = config.layers.values()

        elif options.layer not in config.layers:
            raise 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()))))

        else:
            # clean just one layer in the config
            layers = [config.layers[options.layer]]

        verbose = options.verbose
        extension = options.extension
        progressfile = options.progressfile
Exemple #11
0
def clean_resource_cache(tile):
    if not settings.CACHE_RESOURCE_TILES:
        return

    # get the tile model's bounds
    bounds = None
    nodegroup = models.NodeGroup.objects.get(pk=tile.nodegroup_id)
    for node in nodegroup.node_set.all():
        if node.datatype == 'geojson-feature-collection':
            node_data = tile.data[str(node.pk)]
            for feature in node_data['features']:
                shape = asShape(feature['geometry'])
                if bounds is None:
                    bounds = shape.bounds
                else:
                    minx, miny, maxx, maxy = bounds
                    if shape.bounds[0] < minx:
                        minx = shape.bounds[0]
                    if shape.bounds[1] < miny:
                        miny = shape.bounds[1]
                    if shape.bounds[2] > maxx:
                        maxx = shape.bounds[2]
                    if shape.bounds[3] > maxy:
                        maxy = shape.bounds[3]
                    bounds = (minx, miny, maxx, maxy)
    if bounds is None:
        return

    zooms = range(20)
    config = parseConfig(get_tileserver_config())
    layer = config.layers['resources']
    mimetype, format = layer.getTypeByExtension('pbf')

    lon1, lat1, lon2, lat2 = bounds
    south, west = min(lat1, lat2), min(lon1, lon2)
    north, east = max(lat1, lat2), max(lon1, lon2)

    northwest = Location(north, west)
    southeast = Location(south, east)

    ul = layer.projection.locationCoordinate(northwest)
    lr = layer.projection.locationCoordinate(southeast)

    # start with a simple total of all the coordinates we will need.
    for zoom in zooms:
        ul_ = ul.zoomTo(zoom).container()
        lr_ = lr.zoomTo(zoom).container()

        rows = lr_.row + 1 - ul_.row
        cols = lr_.column + 1 - ul_.column

    # now generate the actual coordinates.
    coordinates = []
    for zoom in zooms:
        ul_ = ul.zoomTo(zoom).container()
        lr_ = lr.zoomTo(zoom).container()

        for row in range(int(ul_.row), int(lr_.row + 1)):
            for column in range(int(ul_.column), int(lr_.column + 1)):
                coord = Coordinate(row, column, zoom)
                coordinates.append(coord)

    for coord in coordinates:
        config.cache.remove(layer, coord, format)