[Tilecache] PILcopy layer

Richard Duivenvoorde rdmailings at duif.net
Thu Jul 14 17:35:43 EDT 2011


Hi all,

I have this almost complete tilecache of my country in 14 zoomlevels.

Now somebody wanted to have this cache (sometimes) in black and white.

Thinking about PIL and ImageMagick, I managed to hack a (what I call)
'PILcopy'-Layer together, which generates black and white tiles on the
fly/demand based on an (almost full) excisting disk cache.

It has a 'parent'-layer parameter (the layer that it is supposed to use
the tiles from).
Upon a request, it just finds out the path/key, and reads the tile of
the parent from disk, convert it to b&w ( img.convert("L") ) and saves
it in a second cache and returns the b&w tile to client.

It's that simple.

Anybody interested in such functionality? Or maybe this is not the
preferred way? Or maybe it's already there :-)
PIL can also do other tricks probably (I'm hoping it can do the same as
ImageMagick, then you can also spit out dithered maps. sepia maps etc etc).

Only question I have:
- it would be nice to make this work on layers which are not fully
seeded too. So upon a negative test if the 'parent'-layer-tile is
available, the Layer should 'switch back' as parent-layer first,
generate the parent tiles. and then 'switch forward' to the copy-layer
again to do the b&w trick. In this way we can generate two 'dependent'
caches in one go.
I did not manage to do that in a Layer-impl: the MetaLayer constructor
is constructed with **kwargs, and I do not no how to store those for use
in 'renderTile'.

Somebody an idea for that?

Regards,

Richard Duivenvoorde



More information about the Tilecache mailing list