Exemplo n.º 1
0
    def __init__(self, lat, lon, radius):
        super(LLTileFilter, self).__init__()
        self.lat = lat
        self.lon = lon
        self.radius = radius

        # ll bounds
        self.bounds = calculateBoundingBox(lat, lon, radius)
        log_info('LLTileFilter', 'Filter Bounds: %s' % repr(self.bounds))

        # zoom bounds
        self.zoom_boundaries = {}
Exemplo n.º 2
0
    def __init__(self, lat, lon, radius):
        super(LLTileFilter, self).__init__()
        self.lat = lat
        self.lon = lon
        self.radius = radius

        # ll bounds
        self.bounds = calculateBoundingBox(lat, lon, radius)
        log_info("LLTileFilter", "Filter Bounds: %s" % repr(self.bounds))

        # zoom bounds
        self.zoom_boundaries = {}
Exemplo n.º 3
0
    def apply(self, message):
        """Filters tiles based on a central lat/lon and radius"""

        zoom = message.data.get('z', None)
        if zoom is None:
            return False

        if not zoom in self.zoom_boundaries:
            top_left_tile = deg2tile(self.bounds.top_left.lat,
                                     self.bounds.top_left.lon, zoom)
            bottom_right_tile = deg2tile(self.bounds.bottom_right.lat,
                                         self.bounds.bottom_right.lon, zoom)

            # cache zoom boundaries
            self.zoom_boundaries[zoom] = TileBounds(top_left_tile.x,
                                                    bottom_right_tile.x,
                                                    top_left_tile.y,
                                                    bottom_right_tile.y)

            log_info(
                'LLTileFilter', 'Level %s Zoom Bounds: %s' %
                (zoom, repr(self.zoom_boundaries[zoom])))

        # get tile bounds and current tile location
        tile_bounds = self.zoom_boundaries[zoom]
        xtile = message.data.get('x', None)
        ytile = message.data.get('y', None)

        # valid message
        if ytile is not None and xtile is not None:
            log_debug('LLTileFilter',
                      'Filtering Tile: %s' % repr(Tile(xtile, ytile)))
            log_debug('LLTileFilter', 'Tile Bounds: %s' % repr(tile_bounds))

            # check bounds
            if xtile >= tile_bounds.left and xtile <= tile_bounds.right \
                and ytile >= tile_bounds.top and ytile <= tile_bounds.bottom:
                return True

        # tile is either not in bounds or message is invalid
        return False
Exemplo n.º 4
0
    def apply(self, message):
        """Filters tiles based on a central lat/lon and radius"""

        zoom = message.data.get("z", None)
        if zoom is None:
            return False

        if not zoom in self.zoom_boundaries:
            top_left_tile = deg2tile(self.bounds.top_left.lat, self.bounds.top_left.lon, zoom)
            bottom_right_tile = deg2tile(self.bounds.bottom_right.lat, self.bounds.bottom_right.lon, zoom)

            # cache zoom boundaries
            self.zoom_boundaries[zoom] = TileBounds(
                top_left_tile.x, bottom_right_tile.x, top_left_tile.y, bottom_right_tile.y
            )

            log_info("LLTileFilter", "Level %s Zoom Bounds: %s" % (zoom, repr(self.zoom_boundaries[zoom])))

        # get tile bounds and current tile location
        tile_bounds = self.zoom_boundaries[zoom]
        xtile = message.data.get("x", None)
        ytile = message.data.get("y", None)

        # valid message
        if ytile is not None and xtile is not None:
            log_debug("LLTileFilter", "Filtering Tile: %s" % repr(Tile(xtile, ytile)))
            log_debug("LLTileFilter", "Tile Bounds: %s" % repr(tile_bounds))

            # check bounds
            if (
                xtile >= tile_bounds.left
                and xtile <= tile_bounds.right
                and ytile >= tile_bounds.top
                and ytile <= tile_bounds.bottom
            ):
                return True

        # tile is either not in bounds or message is invalid
        return False
Exemplo n.º 5
0
def downloadTile(root, message):
    data = message.data

    dirpath = os.path.join(root, str(data.z), str(data.x))
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)

    # filepath
    filepath = os.path.join(dirpath, '%s.png' % data.y)
    if not os.path.exists(filepath):

        with open(filepath, 'wb') as handle:
            response = requests.get(data.url, stream=True, verify=False)

            if not response.ok:
                log_error(response)
            else:
                log_info('DOWNLOADER', data.url)

                for block in response.iter_content(1024 * 16):
                    if not block:
                        break

                    handle.write(block)
Exemplo n.º 6
0
def downloadTile(root, message):
    data = message.data

    dirpath = os.path.join(root, str(data.z), str(data.x))
    if not os.path.exists(dirpath):
        os.makedirs(dirpath)

    # filepath
    filepath = os.path.join(dirpath, "%s.png" % data.y)
    if not os.path.exists(filepath):

        with open(filepath, "wb") as handle:
            response = requests.get(data.url, stream=True, verify=False)

            if not response.ok:
                log_error(response)
            else:
                log_info("DOWNLOADER", data.url)

                for block in response.iter_content(1024 * 16):
                    if not block:
                        break

                    handle.write(block)