[Tilecache] Customize TileCache get image routine

Christopher Schmidt crschmidt at metacarta.com
Mon Oct 15 12:56:41 EDT 2007


On Mon, Oct 15, 2007 at 09:49:19AM -0600, Linda Rawson wrote:
> Basically I need to do the following:
> 
> 1.  Check if the image already exists in the cache.

I believe this is handled by TileCache at the 'Service' level, depending
on what you mean by 'cache'.  

> 2.  If not then check for the image with the provider by utilizing a url
> that returns a value.
> 3.  Check the value and If still no image then try another WMS service
> provider.
> 4.  If still no image then return a noimage tile.

Right. You'll need to add something like:

class MyDGLayer(Layer):
    def renderTile(self: tile):
        bbox = tile.bbox()
        u = urllib.urlopen('http://digitalglobe.com/tile?bbox=%s' % bbox)
        tile.data = u.read()
        if not tile.data:
            u = urllib.urlopen('http://wms.example.com/tile?bbox=%s' % bbox)
            tile.data = u.read()
        if not tile.data:
            tile.data = open("/my/local/no_image.png").read()
        return tile.data

> Can you direct me to the best python resource for these things?

You'll probably just want to look at basic Python documentation for
'loading data from remote servers' or 'loading data over http' or
something like that. I never looked at any resources other than Google
for learning Python, so I can't help specifically.

Sticking that at the end of the Layer.py file, and then creating a:

[digitalglobe]
type=MyDGLayer

Should get you started.  

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Tilecache mailing list