How to use the mercantile.parent function in mercantile

To help you get started, we’ve selected a few mercantile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent():
    parent = mercantile.parent(486, 332, 10)
    assert parent == (243, 166, 9)
    assert parent.z == 9
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent_fractional_tile():
    with pytest.raises(mercantile.ParentTileError) as e:
        mercantile.parent((243.3, 166.2, 9), zoom=1)
    assert "the parent of a non-integer tile is undefined" in str(e.value)
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent_invalid_args(args):
    """tile arg must have length 1 or 3"""
    with pytest.raises(mercantile.TileArgParsingError):
        mercantile.parent(*args)
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent_fractional_zoom():
    with pytest.raises(mercantile.InvalidZoomError) as e:
        mercantile.parent((243, 166, 9), zoom=1.2)
    assert "zoom must be an integer and less than" in str(e.value)
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent_multi():
    parent = mercantile.parent(486, 332, 10, zoom=8)
    assert parent == (121, 83, 8)
    assert parent.z == 8
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_parent_bad_tile_zoom():
    with pytest.raises(mercantile.InvalidZoomError) as e:
        mercantile.parent((243.3, 166.2, 9), zoom=10)
    assert "zoom must be an integer and less than" in str(e.value)
github mapbox / mercantile / mercantile / scripts / __init__.py View on Github external
https://tools.ietf.org/html/rfc8142 and
    https://tools.ietf.org/html/rfc7159).

    $ echo "[486, 332, 10]" | mercantile parent

    Output:

    [243, 166, 9]
    """
    src = normalize_input(input)
    for line in iter_lines(src):
        tile = json.loads(line)[:3]
        if tile[2] - depth < 0:
            raise click.UsageError("Invalid parent level: {0}".format(tile[2] - depth))
        for i in range(depth):
            tile = mercantile.parent(tile)
        output = json.dumps(tile)
        click.echo(output)