Example #1
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)
    
        points = gheat.get_cursor() 
        points = points.execute("""
    
            SELECT count(uid)
              FROM points
             WHERE lat <= ?
               AND lat >= ?
               AND lng <= ?
               AND lng >= ?
    
             AND modtime > ?
    
            """, self.llbound + (modtime,))
    
        numpoints = points.fetchone()[0] # this is guaranteed to exist, right?
        return numpoints > 0
Example #2
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.

        db = gheat.get_cursor()
        query = {"mapname":self.mapname,
                           "lat":{"$lte":self.llbound[0],"$gte":self.llbound[1]},
                           "lng":{"$lte":self.llbound[2],"$gte":self.llbound[3]}}
        _points = db.find(query)
        def points():
            """Yield x,y pixel coords within this tile, top-left of dot.
            """
            for point in _points:
                x, y = gmerc.ll2px(point['lat'], point['lng'], 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


        # 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)
Example #3
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

        """
        db = gheat.get_cursor()
        query = {"mapname":self.mapname,
                           "lat":{"$lte":self.llbound[0],"$gte":self.llbound[1]},
                           "lng":{"$lte":self.llbound[2],"$gte":self.llbound[3]}}
        numpoints = db.find(query).count()
        return numpoints == 0
Example #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.

        db = gheat.get_cursor()
        query = {
                    "loc" : {
                        "$within" : {"$box": [
                            [ self.llbound[3], self.llbound[1] ],
                            [ self.llbound[2], self.llbound[0] ]
                        ]}
                    }
                }
        _points = db.find(query, {"meta" : 0})
        def points():
            """Yield x,y pixel coords within this tile, top-left of dot.
            """
            for point in _points:
                x, y = gmerc.ll2px(point['loc'][1], point['loc'][0], self.zoom)
                x = x - self.x1 # account for tile offset relative to 
                y = y - self.y1 #  overall map
                if point["type"] in self.pad:
                    yield { 
                        "loc" : [x-self.pad[point["type"]], y-self.pad[point["type"]]],
                        "category" : point["type"]
                    }


        # 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)
Example #5
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.

        db = gheat.get_cursor()
        query = {
            "mapname": self.mapname,
            "lat": {
                "$lte": self.llbound[0],
                "$gte": self.llbound[1]
            },
            "lng": {
                "$lte": self.llbound[2],
                "$gte": self.llbound[3]
            }
        }
        _points = db.find(query)

        def points():
            """Yield x,y pixel coords within this tile, top-left of dot.
            """
            for point in _points:
                x, y = gmerc.ll2px(point['lat'], point['lng'], 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

        # 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)
Example #6
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.

        _points = gheat.get_cursor()
        _points.execute("""

            SELECT *
              FROM points
             WHERE lat <= ?
               AND lat >= ?
               AND lng <= ?
               AND lng >= ?

        """, self.llbound)
   
        def points():
            """Yield x,y pixel coords within this tile, top-left of dot.
            """
            for point in _points:
                x, y = gmerc.ll2px(point['lat'], point['lng'], 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


        # 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, DIRMODE)
Example #7
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

        """
        db = gheat.get_cursor()
        query = {
                    "loc" : {
                        "$within" : { "$box" : [
                                [ self.llbound[3], self.llbound[1] ],
                                [ self.llbound[2], self.llbound[0] ]
                            ]}
                    }
                }
        
        numpoints = db.find(query, { "meta" : 0 }).count()

        return numpoints == 0
Example #8
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

        """
        points = gheat.get_cursor() 
        points = points.execute("""
    
            SELECT count(uid)
              FROM points
             WHERE lat <= ?
               AND lat >= ?
               AND lng <= ?
               AND lng >= ?
    
            """, self.llbound)
    
        numpoints = points.fetchone()[0] # this is guaranteed to exist, right?
        return numpoints == 0
Example #9
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

        """
        db = gheat.get_cursor()
        query = {
            "mapname": self.mapname,
            "lat": {
                "$lte": self.llbound[0],
                "$gte": self.llbound[1]
            },
            "lng": {
                "$lte": self.llbound[2],
                "$gte": self.llbound[3]
            }
        }
        numpoints = db.find(query).count()
        return numpoints == 0