예제 #1
0
def test_windows_intersect():
    assert windows.intersect(((0, 6), (3, 6)), ((2, 4), (1, 5))) is True

    assert windows.intersect(((0, 6), (3, 6)), ((2, 4), (1, 5)),
                             ((3, 6), (0, 6))) is True

    assert windows.intersect(((0, 2), (0, 2)), ((1, 4), (1, 4))) is True
예제 #2
0
def test_iter_args_winfuncs():
    wins = [
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5))]

    assert windows.intersect(*wins) == windows.intersect(wins)
    assert windows.intersection(*wins) == windows.intersection(wins)
    assert windows.union(*wins) == windows.union(wins)
예제 #3
0
def test_iter_args_winfuncs():
    wins = [
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5))]

    assert windows.intersect(*wins) == windows.intersect(wins)
    assert windows.intersection(*wins) == windows.intersection(wins)
    assert windows.union(*wins) == windows.union(wins)
예제 #4
0
def test_windows_intersect():
    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices((2, 4), (1, 5))) is True

    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices(
            (2, 4), (1, 5)), windows.Window.from_slices((3, 6),
                                                        (0, 6))) is True

    assert windows.intersect(windows.Window.from_slices(
        (0, 2), (0, 2)), windows.Window.from_slices((1, 4), (1, 4))) is True
예제 #5
0
def test_windows_intersect():
    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5))) is True

    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5)),
        ((3, 6), (0, 6))) is True

    assert windows.intersect(
        ((0, 2), (0, 2)),
        ((1, 4), (1, 4))) is True
예제 #6
0
def test_windows_intersect_disjunct(recwarn):
    data = [((0, 6), (3, 6)), ((2, 4), (1, 5))]
    warnings.simplefilter('always')
    old = windows_intersect(data)
    assert len(recwarn) == 1
    assert recwarn.pop(DeprecationWarning)
    new = windows.intersect(data)
    assert len(recwarn) == 0
    assert old == new
예제 #7
0
def test_windows_intersect_disjunct(recwarn):
    data = [
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5))]
    warnings.simplefilter('always')
    old = windows_intersect(data)
    assert len(recwarn) == 1
    assert recwarn.pop(DeprecationWarning)
    new = windows.intersect(data)
    assert len(recwarn) == 0
    assert old == new
예제 #8
0
def test_windows_intersect_disjunct():
    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices((10, 20), (0, 6))) is False

    # polygons touch at point
    assert windows.intersect(windows.Window.from_slices(
        (0, 2), (1, 3)), windows.Window.from_slices((2, 4), (3, 5))) is False

    # polygons touch at point, rev order
    assert windows.intersect(windows.Window.from_slices(
        (2, 4), (3, 5)), windows.Window.from_slices((0, 2), (1, 3))) is False

    # polygons touch at line
    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices((6, 10), (1, 5))) is False

    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices(
            (2, 4), (1, 5)), windows.Window.from_slices((5, 6),
                                                        (0, 6))) is False

    assert windows.intersect(windows.Window.from_slices(
        (0, 6), (3, 6)), windows.Window.from_slices(
            (2, 4), (1, 3)), windows.Window.from_slices((3, 6),
                                                        (4, 6))) is False
예제 #9
0
def test_windows_intersect_disjunct():
    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((10, 20), (0, 6))) is False

    # polygons touch at point
    assert windows.intersect(
        ((0, 2), (1, 3)),
        ((2, 4), (3, 5))) is False

    # polygons touch at point, rev order
    assert windows.intersect(
        ((2, 4), (3, 5)),
        ((0, 2), (1, 3))) is False

    # polygons touch at line
    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((6, 10), (1, 5))) is False

    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((2, 4), (1, 5)),
        ((5, 6), (0, 6))) is False

    assert windows.intersect(
        ((0, 6), (3, 6)),
        ((2, 4), (1, 3)),
        ((3, 6), (4, 6))) is False
예제 #10
0
def fetch_raster_window(
    asset_entry: Optional[Tuple[Reader, windows.Window]],
    slices: Tuple[slice, ...],
) -> np.ndarray:
    current_window = windows.Window.from_slices(*slices)
    if asset_entry is not None:
        reader, asset_window = asset_entry

        # check that the window we're fetching overlaps with the asset
        if windows.intersect(current_window, asset_window):
            # backend: Backend = manager.acquire(needs_lock=False)
            data = reader.read(current_window)

            return data[None, None]

    # no dataset, or we didn't overlap it: return empty data.
    # use the broadcast trick for even fewer memz
    return np.broadcast_to(np.nan, (1, 1) + windows.shape(current_window))
예제 #11
0
def test_3x3matrix():
    """For a 3x3 arrangement of 2x2 windows
      a | b | c
      ---------
      d | e | f
      ---------
      g | h | i

      i.e. window e is ((2, 4), (2, 4))

      None of them should intersect or have an intersection
    """
    from itertools import product, combinations

    pairs = ((0, 2), (2, 4), (4, 6))
    arrangement = product(pairs, pairs)
    for wins in combinations(arrangement, 2):
        assert not windows.intersect(*wins)
        with pytest.raises(WindowError):
            windows.intersection(*wins)
예제 #12
0
def test_3x3matrix():
    """For a 3x3 arrangement of 2x2 windows
      a | b | c
      ---------
      d | e | f
      ---------
      g | h | i

      i.e. window e is ((2, 4), (2, 4))

      None of them should intersect or have an intersection
    """
    from itertools import product, combinations

    pairs = ((0, 2), (2, 4), (4, 6))
    arrangement = product(pairs, pairs)
    for wins in combinations(arrangement, 2):
        assert not windows.intersect(*wins)
        with pytest.raises(WindowError):
            windows.intersection(*wins)
예제 #13
0
def test_window_class_intersects():
    """Windows intersect"""
    assert intersect(Window(0, 0, 10, 10), Window(8, 8, 10, 10))
예제 #14
0
def windows_intersect(data):
    warnings.warn("Deprecated; Use rasterio.windows instead", DeprecationWarning)
    return windows.intersect(data)
예제 #15
0
def test_window_class_intersects():
    """Windows intersect"""
    assert intersect(Window(0, 0, 10, 10), Window(8, 8, 10, 10))
예제 #16
0
def test_window_class_intersects_list():
    """A list of Windows intersect"""
    assert intersect([Window(0, 0, 10, 10), Window(8, 8, 10, 10)])
예제 #17
0
def test_window_class_nonintersects():
    """Windows do not intersect"""
    assert not intersect(Window(0, 0, 10, 10), Window(10, 10, 10, 10))
예제 #18
0
def windows_intersect(data):
    warnings.warn("Deprecated; Use rasterio.windows instead",
                  DeprecationWarning)
    return windows.intersect(data)
예제 #19
0
def test_window_class_intersects_list():
    """A list of Windows intersect"""
    assert intersect([Window(0, 0, 10, 10), Window(8, 8, 10, 10)])
예제 #20
0
def test_window_class_nonintersects():
    """Windows do not intersect"""
    assert not intersect(Window(0, 0, 10, 10), Window(10, 10, 10, 10))
예제 #21
0
def getIntersection(tif_window, mask_window, mask_name, mask_size):
    if windows.intersect(mask_window, tif_window):
        return (mask_name, mask_window, mask_size,
                mask_window.intersection(tif_window))
    return None