コード例 #1
0
def find_valid_data_region(geobox, *sources_list):
    # perform work in CRS of the output tile geobox
    unfused = [[
        dataset.extent.to_crs(geobox.crs) for dataset in tile.sources.item()
    ] for tile in sources_list]
    # fuse the dataset extents within each source tile
    tiles_extents = map(unary_union, unfused)
    # find where (within the output tile) that all prerequisite inputs available
    return unary_intersection([geobox.extent] + list(tiles_extents))
コード例 #2
0
def test_unary_intersection():
    box1 = geometry.box(10, 10, 30, 30, crs=geometry.CRS('EPSG:4326'))
    box2 = geometry.box(15, 10, 35, 30, crs=geometry.CRS('EPSG:4326'))
    box3 = geometry.box(20, 10, 40, 30, crs=geometry.CRS('EPSG:4326'))
    box4 = geometry.box(25, 10, 45, 30, crs=geometry.CRS('EPSG:4326'))
    box5 = geometry.box(30, 10, 50, 30, crs=geometry.CRS('EPSG:4326'))
    box6 = geometry.box(35, 10, 55, 30, crs=geometry.CRS('EPSG:4326'))

    inter1 = geometry.unary_intersection([box1])
    assert bool(inter1)
    assert inter1 == box1

    inter2 = geometry.unary_intersection([box1, box2])
    assert bool(inter2)
    assert inter2.area == 300.0

    inter3 = geometry.unary_intersection([box1, box2, box3])
    assert bool(inter3)
    assert inter3.area == 200.0

    inter4 = geometry.unary_intersection([box1, box2, box3, box4])
    assert bool(inter4)
    assert inter4.area == 100.0

    inter5 = geometry.unary_intersection([box1, box2, box3, box4, box5])
    assert bool(inter5)
    assert inter5.type == 'LineString'
    assert inter5.length == 20.0

    inter6 = geometry.unary_intersection([box1, box2, box3, box4, box5, box6])
    assert not bool(inter6)
    assert inter6.is_empty