當前位置: 首頁>>代碼示例>>Python>>正文


Python mercantile.children方法代碼示例

本文整理匯總了Python中mercantile.children方法的典型用法代碼示例。如果您正苦於以下問題:Python mercantile.children方法的具體用法?Python mercantile.children怎麽用?Python mercantile.children使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mercantile的用法示例。


在下文中一共展示了mercantile.children方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: children

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import children [as 別名]
def children(ctx, input, depth):
    """Takes a [x, y, z] tile as input and writes its children to stdout
    in the same form.

    $ echo "[486, 332, 10]" | mercantile parent

    Output:

    [243, 166, 9]
    """
    src = normalize_input(input)
    for line in iter_lines(src):
        line = line.strip()
        tiles = [json.loads(line)[:3]]
        for i in range(depth):
            tiles = sum([mercantile.children(t) for t in tiles], [])
        for t in tiles:
            output = json.dumps(t)
            click.echo(output)


# The parent command. 
開發者ID:enricofer,項目名稱:go2mapillary,代碼行數:24,代碼來源:__init__.py

示例2: add_tiles

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import children [as 別名]
def add_tiles(self, zMin, zMax):
        zooms = np.arange(zMax - zMin + 2) + zMin - 1

        obj = {
            zMin - 1: [mercantile.tile(-122.4, 37.5, zMin - 1)]
        }

        basepath = '%s/jpg' % (self.path)
        if not os.path.isdir(basepath):
            os.mkdir(basepath)

        for i in range(1, len(zooms)):
            tiles = []
            os.mkdir("%s/%s" % (basepath, zooms[i]))
            for t in obj[zooms[i - 1]]:
                for tt in mercantile.children(t):
                    tiles.append(tt)
                    if os.path.isdir("%s/%s/%s" % (basepath, zooms[i], tt.x)):
                        shutil.copy(self.imgs[int(np.random.rand() + 0.1)],
                                    "%s/%s/%s/%s.jpg" % (basepath, zooms[i], tt.x, tt.y))
                    else:
                        os.mkdir("%s/%s/%s" % (basepath, zooms[i], tt.x))
                        shutil.copy(self.imgs[int(np.random.rand() + 0.1)],
                                    "%s/%s/%s/%s.jpg" % (basepath, zooms[i], tt.x, tt.y))
            obj[zooms[i]] = tiles 
開發者ID:mapbox,項目名稱:untiler,代碼行數:27,代碼來源:test_cli.py

示例3: find_quadkeys

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import children [as 別名]
def find_quadkeys(mercator_tile: mercantile.Tile, quadkey_zoom: int) -> List[str]:
    """
    Find quadkeys at desired zoom for tile

    Attributes
    ----------
    mercator_tile: mercantile.Tile
        Input tile to use when searching for quadkeys
    quadkey_zoom: int
        Zoom level

    Returns
    -------
    list
        List[str] of quadkeys

    """
    # get parent
    if mercator_tile.z > quadkey_zoom:
        depth = mercator_tile.z - quadkey_zoom
        for i in range(depth):
            mercator_tile = mercantile.parent(mercator_tile)
        return [mercantile.quadkey(*mercator_tile)]

    # get child
    elif mercator_tile.z < quadkey_zoom:
        depth = quadkey_zoom - mercator_tile.z
        mercator_tiles = [mercator_tile]
        for i in range(depth):
            mercator_tiles = sum([mercantile.children(t) for t in mercator_tiles], [])

        mercator_tiles = list(filter(lambda t: t.z == quadkey_zoom, mercator_tiles))
        return [mercantile.quadkey(*tile) for tile in mercator_tiles]
    else:
        return [mercantile.quadkey(*mercator_tile)] 
開發者ID:developmentseed,項目名稱:cogeo-mosaic,代碼行數:37,代碼來源:utils.py

示例4: all_descendant_tiles

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import children [as 別名]
def all_descendant_tiles(x, y, zoom, max_zoom):
    """
    Return all child tiles contained within a tile defined by x, y, zoom
    down to the max_zom level.
    """
    if zoom < max_zoom:
        for child_tile in mercantile.children(x, y, zoom):
            yield child_tile
            yield from all_descendant_tiles(child_tile.x, child_tile.y,
                                            child_tile.z, max_zoom) 
開發者ID:osm2vectortiles,項目名稱:osm2vectortiles,代碼行數:12,代碼來源:generate_jobs.py

示例5: download_tile_tms

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import children [as 別名]
def download_tile_tms(tile, imagery, folder, kwargs):
    """Download a satellite image tile from a tms endpoint"""

    image_format = get_image_format(imagery, kwargs)

    if os.environ.get('ACCESS_TOKEN'):
        token = os.environ.get('ACCESS_TOKEN')
        imagery = imagery.format_map(SafeDict(ACCESS_TOKEN=token))

    r = requests.get(url(tile.split('-'), imagery),
                     auth=kwargs.get('http_auth'))
    tile_img = op.join(folder, '{}{}'.format(tile, image_format))
    tile = tile.split('-')

    over_zoom = kwargs.get('over_zoom')
    if over_zoom:
        new_zoom = over_zoom + kwargs.get('zoom')
        # get children
        child_tiles = children(int(tile[0]), int(tile[1]), int(tile[2]), zoom=new_zoom)
        child_tiles.sort()

        new_dim = 256 * (2 * over_zoom)

        w_lst = []
        for i in range (2 * over_zoom):
            for j in range(2 * over_zoom):
                window = Window(i * 256, j * 256, 256, 256)
                w_lst.append(window)

        # request children
        with rasterio.open(tile_img, 'w', driver='jpeg', height=new_dim,
                        width=new_dim, count=3, dtype=rasterio.uint8) as w:
                for num, t in enumerate(child_tiles):
                    t = [str(t[0]), str(t[1]), str(t[2])]
                    r = requests.get(url(t, imagery),
                                    auth=kwargs.get('http_auth'))
                    img = np.array(Image.open(io.BytesIO(r.content)), dtype=np.uint8)
                    try:
                        img = img.reshape((256, 256, 3)) # 4 channels returned from some endpoints, but not all
                    except ValueError:
                        img = img.reshape((256, 256, 4))
                    img = img[:, :, :3]
                    img = np.rollaxis(img, 2, 0)
                    w.write(img, window=w_lst[num])
    else:
        r = requests.get(url(tile, imagery),
                         auth=kwargs.get('http_auth'))
        with open(tile_img, 'wb')as w:
            w.write(r.content)
    return tile_img 
開發者ID:developmentseed,項目名稱:label-maker,代碼行數:52,代碼來源:utils.py


注:本文中的mercantile.children方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。