def test_vt2geojson_line_string(): cur_dir = current_dir(__file__) data_path = os.path.join(cur_dir, f'fixtures/linestring.geojson') geojson = get_json(data_path) expected = { "type": "FeatureCollection", "features": [{ "type": "Feature", "geometry": { "type": "LineString", "coordinates": [[9.333594851195812, 47.11501442877534], [9.33286428451538, 47.11409674087989]] }, "properties": {} }] } z, x, y = 18, 137868, 92080 tile_index = geojson2vt(geojson, { 'maxZoom': z, 'indexMaxZoom': z, 'indexMaxPoints': 0 }) vt_tile = tile_index.get_tile(z, x, y) result = vt2geojson(vt_tile) assert result == expected
def test_empty_gejson(): cur_dir = current_dir(__file__) file_path = os.path.join(cur_dir, 'fixtures/empty.json') expected = get_json(file_path) result = gen_tiles(expected, {}) assert {} == result
def test_tiles(input_file, expected_file, options): cur_dir = current_dir(__file__) file_path = os.path.join(cur_dir, f'fixtures/{expected_file}') expected = get_json(file_path) file_path = os.path.join(cur_dir, f'fixtures/{input_file}') input_data = get_json(file_path) tiles = gen_tiles(input_data, options) for t, j in zip(tiles.items(), expected.items()): assert t == j
def test_small(): cur_dir = current_dir(__file__) data_path = os.path.join(cur_dir, f'fixtures/small.json') file_path = os.path.join(cur_dir, f'fixtures/small_result.json') data = get_json(data_path) expected = get_json(file_path) geojson_vt = geojson2vt(data, {}) geojson_vt.get_tile(14, 8617, 5752) geojson_vt_keys = sorted([str(k) for k in geojson_vt.tiles.keys()]) expected_keys = sorted([str(k) for k in expected.keys()]) assert geojson_vt_keys == expected_keys
def test_features(): cur_dir = current_dir(__file__) data_path = os.path.join(cur_dir, f'fixtures/us-states.json') file_path = os.path.join(cur_dir, f'fixtures/feature_result.json') data = get_json(data_path) expected = get_json(file_path) geojson_vt = geojson2vt(data, {}) features = geojson_vt.get_tile(7, 37, 48).get('features') feature_ids = [f.get('id') for f in features] expected_feature_ids = [f.get('id') for f in expected] assert feature_ids == expected_feature_ids assert features == expected
def test_get_tile(): cur_dir = current_dir(__file__) data_path = os.path.join(cur_dir, f'fixtures/us-states.json') expected_path = os.path.join(cur_dir, f'fixtures/us-states-z7-37-48.json') data = get_json(data_path) geojson_vt = geojson2vt(data, {}) features = geojson_vt.get_tile('7', '37', '48').get('features') expected = get_json(expected_path) assert features == expected assert geojson_vt.get_tile(9, 148, 192).get('features') == square assert geojson_vt.get_tile(11, 800, 400) == None assert geojson_vt.get_tile(-5, 123.25, 400.25) == None assert geojson_vt.get_tile(25, 200, 200) == None assert geojson_vt.total == 37
def test_vt2geojson_multi(): cur_dir = current_dir(__file__) data_path = os.path.join(cur_dir, f'fixtures/multi.geojson') geojson = get_json(data_path) x, y, z = 2153, 1438, 12 expected = { 'type': 'FeatureCollection', 'features': [{ 'type': 'Feature', 'geometry': { 'type': 'Polygon', 'coordinates': [[[9.31065559387207, 47.12633021376186], [9.303703308105469, 47.12142456895782], [9.317779541015625, 47.11764282567128], [9.317779541015625, 47.12698718541262], [9.31065559387207, 47.12633021376186]]] }, 'properties': {} }, { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [9.303016662597656, 47.12673899707599] }, 'properties': {} }] } tile_index = geojson2vt(geojson, { 'maxZoom': z, 'indexMaxZoom': z, 'indexMaxPoints': 0 }) vt_tile = tile_index.get_tile(z, x, y) result = vt2geojson(vt_tile) assert result == expected
def test_none_geometry(): cur_dir = current_dir(__file__) file_path = os.path.join(cur_dir, 'fixtures/feature-null-geometry.json') expected = get_json(file_path) assert {} == gen_tiles(expected, {})