[Tilecache] Building a Custom Service

Christopher Schmidt crschmidt at metacarta.com
Fri Feb 27 09:27:34 EST 2009


On Fri, Feb 27, 2009 at 08:13:14AM -0600, Brian Walawender wrote:
> I've been playing around with building a custom service (in lieu of reading
> tilecache.cfg because of the large number of layers we are reading) but
> can't exactly figure out how Service.py gets the layer name from the client.
> I'm currently parsing req.unparsed_uri but I feel I am making some dangerous
> assumptions.

Currently, inside of the Services subclasses, there is some URL-format
based parsing. This happens in the 'parse' method, called in
dispatchRequest. I see that this will be a problem for you, because
these classes call self.getLayer() internally, which just does:
        try:
           return self.service.layers[layername]
        except:
            raise Exception()

I would recommmend that what this means is that we should change some
aspect of this behavior, but I'm not sure which part. Possibilities:

 * Split the layer-name-fetching out as a seperate method of the Service
   classes (Request Subclasses), which can be called with the same data
   as parse(), but just returns the layername. Then, in your service
   subclass, call getLayerName first, load the layer, *then* call
   parse().

 * Modify Request to call service.loadLayer(layername) before throwing
   the exception, if iti's not already loaded. In the base service
   class, this would just do nothing, but in your subclass, it could
   load from the database.

The latter feels reasonably clean, and has the benefit of needing to
change only one section of code. I'd suggest that's probably the better
option.

Best Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Tilecache mailing list