How to use the mercantile.quadkey_to_tile 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_empty_quadkey_to_tile():
    qk = ""
    expected = mercantile.Tile(0, 0, 0)
    assert mercantile.quadkey_to_tile(qk) == expected
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_quadkey_failure(recwarn):
    """expect a deprecation warning"""
    warnings.simplefilter("always")
    with pytest.raises(mercantile.QuadKeyError):
        mercantile.quadkey_to_tile("lolwut")
    assert len(recwarn) == 1
    assert recwarn.pop(DeprecationWarning)
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_quadkey_to_tile():
    qk = "0313102310"
    expected = mercantile.Tile(486, 332, 10)
    assert mercantile.quadkey_to_tile(qk) == expected
github hotosm / tasking-manager / server / services / ml_enabler_service.py View on Github external
model_id = get_model_id(api_url, model_name)
        url = f'{api_url}/model/{model_id}/tiles'
        params = dict(bbox=bbox, zoom=zoom)
        response = requests.get(url, params=params)
        data = response.json()
        if not data.get('error'):
            main_response = {'status': 'ok', 'prediction_ids': [], 
                             'error': '', 'diff_total': 0}
            osm_total = 0
            pred_total = 0

            for k in data.keys():
                main_response['prediction_ids'].append(k)
                new_list = []
                for pred in data[k]:
                    tile = mercantile.quadkey_to_tile(pred['quadkey'])
                    bbox = mercantile.xy_bounds(tile)
                    pred['bbox'] = (bbox.left, bbox.bottom, bbox.right, bbox.top)
                    pred['zoom'] = tile.z
                    
                    #we ignore negativae values 
                    if pred['ml_prediction'] > pred['osm_building_area']:
                        pred_total += pred['ml_prediction']
                        osm_total += pred['osm_building_area']
                        
                    new_list.append(pred)
                data[k] = new_list

            main_response['predictions'] = data
            main_response['diff_total'] = pred_total - osm_total
        else:
            main_response = {'status': 'error', 'error': data.get('error')}
github mapbox / mercantile / mercantile / scripts / __init__.py View on Github external
0313102310

    $ echo "0313102310" | mercantile quadkey

    Output:

    [486, 332, 10]
    """
    src = normalize_input(input)
    try:
        for line in iter_lines(src):
            if line[0] == "[":
                tile = json.loads(line)[:3]
                output = mercantile.quadkey(tile)
            else:
                tile = mercantile.quadkey_to_tile(line)
                output = json.dumps(tile)
            click.echo(output)
    except mercantile.QuadKeyError:
        raise click.BadParameter("{0}".format(input), param=input, param_hint="input")