Esempio n. 1
0
def test_from_wkss():
    for i in [
            "EuropeanETRS89_LAEAQuad",
            "WebMercatorQuad",
            "WorldCRS84Quad",
            "WorldMercatorWGS84Quad",
    ]:
        tp = TilePyramid.from_wkss(i)
        assert isinstance(tp, TilePyramid)
        assert isinstance(tp, TileMatrixSet)

    # now again constructing TileMatrixSet objects
    for i in [
            "EuropeanETRS89_LAEAQuad",
            "WebMercatorQuad",
            "WorldCRS84Quad",
            "WorldMercatorWGS84Quad",
    ]:
        tms = TileMatrixSet.from_wkss(i)
        assert isinstance(tms, TileMatrixSet)

    # use WKSS dictionary
    tp = TilePyramid.from_wkss(get_wkss("WorldCRS84Quad").definition)

    # rais error on invalid input
    with pytest.raises(TypeError):
        TilePyramid.from_wkss(None)
Esempio n. 2
0
def test_dump_load():
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    tp._abstract = "dummy abstract"
    tp._keywords = ["one", "two"]
    dumped = tp.to_dict()
    assert isinstance(dumped, dict)
    tp2 = TilePyramid.from_wkss(dumped)
    assert tp._identifier == tp2._identifier
    assert tp._abstract == tp2._abstract
    assert tp._keywords == tp2._keywords
Esempio n. 3
0
def test_magic_methods():
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    tile = tp.tile(5, 5, 5)
    assert str(tile)
    assert hash(tile)
    for i in tile:
        assert i == 5
Esempio n. 4
0
def test_parents_children():
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    tile = tp.tile(5, 5, 5)

    children = tile.get_children()
    assert len(children) == 4
    for child in children:
        assert child.get_parent().id == tile.id

    top_tile = tp.tile(0, 0, 0)
    assert top_tile.get_parent() is None
Esempio n. 5
0
def test_iter():
    # iterate over TilePyramid / TileMatrixSet to get TileMatrix objects
    tp = TilePyramid.from_wkss("WebMercatorQuad")

    for tile_matrix_id, tile_matrix in tp.items():
        assert isinstance(tile_matrix_id, int)
        assert isinstance(tile_matrix, TileMatrix)

    for tile_matrix_id in tp.keys():
        assert isinstance(tile_matrix_id, int)

    for tile_matrix in tp.values():
        assert isinstance(tile_matrix, TileMatrix)
Esempio n. 6
0
def test_web_mercator_tile_bounds():
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    tp_ref = tilematrix.TilePyramid("mercator")
    for zoom in range(10):
        for row, col in zip(
            list(range(tp.matrix_height(zoom))), list(range(tp.matrix_width(zoom)))
        ):
            # there is different precision between packages and to account for rounding
            # errors we have to round both bounds
            round_value = 2
            rounded_bounds = _round_tuple(tp.tile(zoom, row, col).bounds, round_value)
            rounded_ref_bounds = _round_tuple(
                tp_ref.tile(zoom, row, col).bounds(), round_value
            )
            assert rounded_bounds == rounded_ref_bounds
Esempio n. 7
0
def test_tile():
    tp = TilePyramid.from_wkss("WebMercatorQuad")

    # Tile construction
    assert isinstance(tp.tile(0, 0, 0), Tile)
    with pytest.raises(InvalidTileMatrixIndex):
        tp.tile(None, 0, 0)
    with pytest.raises(InvalidTileIndex):
        tp.tile(0, None, 0)
    with pytest.raises(InvalidTileIndex):
        tp.tile(0, 0, None)
    with pytest.raises(InvalidTileIndex):
        tp.tile(0, 1, 0)
    with pytest.raises(InvalidTileIndex):
        tp.tile(0, 0, 1)

    assert tp.matrix_width(0) == 1
    assert tp.matrix_height(0) == 1
Esempio n. 8
0
def test_crs84_tile_bounds():
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    tp_ref = tilematrix.TilePyramid("geodetic")
    for zoom in range(10):
        for row, col in zip(
            list(range(tp.matrix_height(zoom))), list(range(tp.matrix_width(zoom)))
        ):
            # leave out every second column to follow a diagonal path from corner to
            # corner of the WGS84 Tile Matrix
            col = col * 2
            # there is different precision between packages and to account for rounding
            # errors we have to round both bounds
            round_value = 8
            rounded_bounds = _round_tuple(tp.tile(zoom, row, col).bounds, round_value)
            rounded_ref_bounds = _round_tuple(
                tp_ref.tile(zoom, row, col).bounds(), round_value
            )
            assert rounded_bounds == rounded_ref_bounds
Esempio n. 9
0
def test_attributes():
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    assert tp.pixel_x_size(5) == -tp.pixel_y_size(5)
Esempio n. 10
0
def test_get():
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    for i in range(len(tp)):
        tile_matrix = tp[i]
        assert isinstance(tile_matrix, TileMatrix)
Esempio n. 11
0
def test_web_mercator_pixel_sizes(web_mercator_pixel_sizes):
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    for i in range(len(tp)):
        assert round(tp.pixel_x_size(i),
                     9) == round(web_mercator_pixel_sizes[i], 9)
Esempio n. 12
0
def test_crs84_matrix_bounds(crs84_bounds):
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    for tm in tp:
        assert tm.bounds == crs84_bounds
Esempio n. 13
0
def test_crs84_pixel_sizes(crs84_pixel_sizes):
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    for i in range(len(tp)):
        assert round(tp.pixel_x_size(i), 9) == round(crs84_pixel_sizes[i], 9)
Esempio n. 14
0
def test_web_mercator_matrix_bounds(web_mercator_bounds):
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    for tm in tp:
        assert tm.bounds == web_mercator_bounds
Esempio n. 15
0
def test_neighbors():
    tp = TilePyramid.from_wkss("WorldCRS84Quad")
    tile = tp.tile(5, 5, 5)
    # neighbors
    neighbors_control = [(5, 4, 5), (5, 6, 5), (5, 5, 4), (5, 5, 6)]
    neighbors = tile.get_neighbors(connectedness=4)
    assert len(neighbors) == 4
    for neighbor in neighbors:
        assert neighbor.id in neighbors_control

    neighbors_control.extend([(5, 4, 4), (5, 4, 6), (5, 6, 4), (5, 6, 6)])
    neighbors = tile.get_neighbors(connectedness=8)
    assert len(neighbors) == 8
    for neighbor in neighbors:
        assert neighbor.id in neighbors_control

    with pytest.raises(ValueError):
        tile.get_neighbors(connectedness="invalid")

    # over antimeridian
    tile = tp.tile(3, 1, 0)
    # 8 neighbors
    test_neighbors = {
        (3, 0, 0),
        (3, 1, 1),
        (3, 2, 0),
        (3, 1, 15),
        (3, 0, 1),
        (3, 2, 1),
        (3, 2, 15),
        (3, 0, 15),
    }
    neighbors = {t.id for t in tile.get_neighbors()}
    assert test_neighbors == neighbors
    # 4 neighbors
    test_neighbors = {(3, 0, 0), (3, 1, 1), (3, 2, 0), (3, 1, 15)}
    neighbors = {t.id for t in tile.get_neighbors(connectedness=4)}
    assert test_neighbors == neighbors

    # tile has exactly two identical neighbors
    tile = tp.tile(0, 0, 0)
    test_tile = [(0, 0, 1)]
    neighbors = [t.id for t in tile.get_neighbors(connectedness=8)]
    assert test_tile == neighbors

    # tile is alone at current zoom level
    tp = TilePyramid.from_wkss("WebMercatorQuad")
    tile = tp.tile(0, 0, 0)
    neighbors = [t.id for t in tile.get_neighbors(connectedness=8)]
    assert neighbors == []

    # don't wrap over antimeridian on non-global scale set
    tp = TilePyramid.from_wkss("EuropeanETRS89_LAEAQuad")
    tile = tp.tile(3, 1, 0)
    # 8 neighbors
    test_neighbors = {(3, 0, 0), (3, 1, 1), (3, 2, 0), (3, 0, 1), (3, 2, 1)}
    neighbors = {t.id for t in tile.get_neighbors(connectedness=8)}
    assert test_neighbors == neighbors
    # 4 neighbors
    test_neighbors = {(3, 0, 0), (3, 1, 1), (3, 2, 0)}
    neighbors = {t.id for t in tile.get_neighbors(connectedness=4)}
    assert test_neighbors == neighbors
    # other way round
    tile = tp.tile(3, 1, 7)
    test_neighbors = {(3, 0, 7), (3, 1, 6), (3, 2, 7), (3, 0, 6), (3, 2, 6)}
    neighbors = {t.id for t in tile.get_neighbors(connectedness=8)}
    assert test_neighbors == neighbors