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


Python Window.from_offlen方法代碼示例

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


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

示例1: clip

# 需要導入模塊: from rasterio.windows import Window [as 別名]
# 或者: from rasterio.windows.Window import from_offlen [as 別名]
def clip(indir, chip_csv, outdir,
         image_pattern, chip_pattern, shape, driver):
    """ Output image chips listed in a CSV file

    \b
    CSV file expects the following columns:
        * idx (int): index of the chip
        * name (str): name of chip land cover
        * x (float): upper left X coordinate of chip
        * y (float): upper left Y coordinate of chip

    """
    # Handle 1 or 2 inputs
    if not len(shape):
        shape = None
    else:
        shape = (shape[0], shape[0]) if len(shape) == 1 else shape

    indir, chip_csv, outdir = Path(indir), Path(chip_csv), Path(outdir)
    outdir.mkdir(parents=True, exist_ok=True)

    # Chip info
    chips = pd.read_csv(chip_csv)

    # Input images
    images = list(indir.glob(image_pattern))

    for chip in chips.itertuples():
        _chip = dict(zip(chip._fields, chip))
        _chip['Index'] += 1  # index on 1
        for image in images:
            # Format output filename
            _chip['input'] = image.name
            out_image = outdir.joinpath(chip_pattern.format(**_chip))
            # Make sure output directory exists
            out_image.parent.mkdir(parents=True, exist_ok=True)

            with rasterio.open(str(image)) as src:
                # Formulate chip bounds
                col, row = map(int, ~src.transform * (chip.x, chip.y))
                window = Window.from_offlen(col, row, shape[0], shape[1])

                # Form output kwargs
                out_kwargs = src.meta.copy()
                out_kwargs['driver'] = driver
                out_kwargs['width'] = shape[0]
                out_kwargs['height'] = shape[1]
                out_kwargs['transform'] = src.window_transform(window)

                click.echo('Writing output for image: {}'
                           .format(out_image.name))
                with rasterio.open(str(out_image), 'w', **out_kwargs) as dst:
                    dst.write(src.read(window=window))
開發者ID:ceholden,項目名稱:misc,代碼行數:55,代碼來源:extract_chips.py

示例2: test_window_from_offlen

# 需要導入模塊: from rasterio.windows import Window [as 別名]
# 或者: from rasterio.windows.Window import from_offlen [as 別名]
def test_window_from_offlen():
    """from_offlen classmethod works."""
    with pytest.warns(RasterioDeprecationWarning):
        assert Window.from_offlen(2, 0, 1, 1) == Window.from_slices((0, 1), (2, 3))
開發者ID:RodrigoGonzalez,項目名稱:rasterio,代碼行數:6,代碼來源:test_windows.py

示例3: test_window_from_offlen

# 需要導入模塊: from rasterio.windows import Window [as 別名]
# 或者: from rasterio.windows.Window import from_offlen [as 別名]
def test_window_from_offlen():
    """from_offlen classmethod works."""
    assert Window.from_offlen(2, 0, 1, 1) == ((0, 1), (2, 3))
開發者ID:ceholden,項目名稱:rasterio,代碼行數:5,代碼來源:test_windows.py


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