示例#1
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
示例#2
0
    def is_empty(self):
        """With attributes set on self, return a boolean.

        Calc lat/lng bounds of this tile (include half-dot-width of padding)
        SELECT count(uid) FROM points

        """
        q = Session.query(Points)
        q = q.filter(Points.latitude <= self.llbound[0])
        q = q.filter(Points.latitude >= self.llbound[1])
        q = q.filter(Points.longitude <= self.llbound[2])
        q = q.filter(Points.longitude >= self.llbound[3])
        numpoints = q.count() # this is guaranteed to exist, right?
        return numpoints == 0
示例#3
0
    def is_stale(self):
        """With attributes set on self, return a boolean.

        Calc lat/lng bounds of this tile (include half-dot-width of padding)
        SELECT count(uid) FROM points WHERE modtime < modtime_tile

        """
        if not os.path.isfile(self.fspath):
            return True
   
        timestamp = os.stat(self.fspath)[stat.ST_MTIME]
        modtime = datetime.datetime.fromtimestamp(timestamp)
        
        q = Session.query(Points)
        q = q.filter(Points.latitude <= self.llbound[0])
        q = q.filter(Points.latitude >= self.llbound[1])
        q = q.filter(Points.longitude <= self.llbound[2])
        q = q.filter(Points.longitude >= self.llbound[3])
        q = q.filter(Points.modtime > modtime)
        numpoints = q.count() # this is guaranteed to exist, right?
        return numpoints != 0
示例#4
0
    def rebuild(self):
        """Rebuild the image at self.img. Real work delegated to subclasses.
        """

        # Calculate points.
        # =================
        # Build a closure that gives us the x,y pixel coords of the points
        # to be included on this tile, relative to the top-left of the tile.

        q = Session.query(Points)
        q = q.filter(Points.latitude <= self.llbound[0])
        q = q.filter(Points.latitude >= self.llbound[1])
        q = q.filter(Points.longitude <= self.llbound[2])
        q = q.filter(Points.longitude >= self.llbound[3])

        def points():
            """Yield x,y pixel coords within this tile, top-left of dot.
            """
            for point in q.all():
                x, y = gmerc.ll2px(point.latitude, point.longitude, self.zoom)
                x = x - self.x1 # account for tile offset relative to 
                y = y - self.y1 #  overall map
                yield x-self.pad,y-self.pad,point.magnitude


        # Main logic
        # ==========
        # Hand off to the subclass to actually build the image, then come back 
        # here to maybe create a directory before handing back to the backend
        # to actually write to disk.

        self.img = self.hook_rebuild(points())

        dirpath = os.path.dirname(self.fspath)
        if dirpath and not os.path.isdir(dirpath):
            os.makedirs(dirpath, 0755)
示例#5
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine)