Exemple #1
0
 def load_mml(self, m):
     import cascadenik
     if hasattr(cascadenik, 'VERSION'):
         major = int(cascadenik.VERSION.split('.')[0])
         if major < 1:
             from cascadenik import compile as _compile
             compiled = '%s_compiled.xml' % os.path.splitext(
                 self.mapfile)[0]
             open(compiled, 'w').write(_compile(self.mapfile))
             mapnik.load_map(m, compiled, True)
         elif major == 1:
             cascadenik.load_map(m,
                                 self.mapfile,
                                 self.output_dir,
                                 verbose=self.verbose)
         elif major > 1:
             raise NotImplementedError(
                 'This nik2img version does not yet support Cascadenik > 1.x, please upgrade nik2img to the latest release'
             )
     else:
         from cascadenik import compile as _compile
         compiled = os.path.join(
             self.output_dir, '%s_compiled.xml' %
             os.path.splitext(os.path.basename(self.mapfile))[0])
         output = _compile(self.mapfile)
         open(compiled, 'w').write(output)
         mapnik.load_map(m, compiled, True)
Exemple #2
0
 def load_mml(self,m):
     import cascadenik
     if hasattr(cascadenik,'VERSION'):
         major = int(cascadenik.VERSION.split('.')[0])
         if major < 1:
             from cascadenik import compile as _compile
             compiled = '%s_compiled.xml' % os.path.splitext(self.mapfile)[0]
             open(compiled, 'w').write(_compile(self.mapfile))
             mapnik.load_map(m, compiled,True)
         elif major == 1:
             cascadenik.load_map(m,self.mapfile,self.output_dir,verbose=self.verbose)
         elif major > 1:
             raise NotImplementedError('This nik2img version does not yet support Cascadenik > 1.x, please upgrade nik2img to the latest release')
     else:
         from cascadenik import compile as _compile
         compiled = os.path.join(self.output_dir,'%s_compiled.xml' % os.path.splitext(os.path.basename(self.mapfile))[0])
         output = _compile(self.mapfile)
         open(compiled, 'w').write(output)
         mapnik.load_map(m, compiled,True)
Exemple #3
0
    def __init__(self, mapfile, config=None):
        # private
        self._changed = []
        self._config = config
        self._locked = False

        self._log = logging.getLogger('tilelite')
        
        # mutable
        self.size = 256
        self.buffer_size = 128
        self.format = 'png'
        self.paletted = False
        self.max_zoom = 22
        self.debug = True
        self.watch_mapfile = False
        self.watch_interval = 2
        self.max_failures = 6

        self.caching = False
        self.cache_force = False
        self.cache_path = '/tmp' #tempfile.gettempdir()
        self.metatile = 0

        self._mapnik_map = mapnik.Map(self.size,self.size)

        if self._config:
            self.absorb_options(parse_config(self._config))

        self._mapfile = mapfile
        if mapfile.endswith('.xml'):
            mapnik.load_map(self._mapnik_map, self._mapfile)
        elif mapfile.endswith('.mml'):
            import cascadenik
            if hasattr(cascadenik,'VERSION'):
                major = int(cascadenik.VERSION.split('.')[0])
                if major < 1:
                    from cascadenik import compile as _compile
                    compiled = '%s_compiled.xml' % os.path.splitext(str(mapfile))[0]
                    open(compiled, 'w').write(_compile(self._mapfile))
                    mapnik.load_map(self._mapnik_map, compiled)
                elif major == 1:
                    if str(mapfile).startswith('http'):
                        output_dir = os.getcwd() #os.path.expanduser('~/.cascadenik')
                    else:
                        output_dir = os.path.dirname(str(mapfile))
                    cascadenik.load_map(self._mapnik_map,mapfile,output_dir,verbose=self.debug)
                elif major > 1:
                    raise NotImplementedError('This TileLite version does not yet support Cascadenik > 1.x, please upgrade to the latest release')
            else:
                from cascadenik import compile as _compile
                compiled = '%s_compiled.xml' % os.path.splitext(str(mapfile))[0]
                open(compiled, 'w').write(_compile(self._mapfile))
                mapnik.load_map(self._mapnik_map, compiled)

        self.post_init_setup()
        
        if self.watch_mapfile:
            self.modified = os.path.getmtime(self._mapfile)
            import thread
            thread.start_new_thread(self.watcher, ())
        self._mapnik_map.zoom_all()
        self.envelope = self._mapnik_map.envelope()

        self.empty_tile = mapnik.Image(self.size, self.size)
        if self._mapnik_map.background:
            self.empty_tile.background = self._mapnik_map.background