tiler.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:oam-dynamic-tiler 作者: hotosm 项目源码 文件源码
def read_window(window, src_url, mask_url=None, scale=1):
    tile_size = 256 * scale

    with rasterio.Env(CPL_VSIL_CURL_ALLOWED_EXTENSIONS='.vrt,.tif,.ovr,.msk'):
        src = get_source(src_url)

        # TODO read the data and the mask in parallel
        if mask_url:
            data = src.read(out_shape=(3, tile_size, tile_size), window=window)
            mask = get_source(mask_url)
            mask_data = mask.read(out_shape=(1, tile_size, tile_size), window=window)

            return np.concatenate((data, mask_data))
        else:
            if src.count == 4:
                # alpha channel present
                return src.read(out_shape=(4, tile_size, tile_size), window=window)
            else:
                # no alpha channel, create one
                # TODO use src.bounds as an implicit mask
                data = src.read(out_shape=(3, tile_size, tile_size), window=window)
                alpha = np.full((1, tile_size, tile_size), np.iinfo(data.dtype).max, data.dtype)

                return np.concatenate((data, alpha))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号