예제 #1
0
def test_terrain(png_fname, encoding):
    """Test output from decode_ele against JS output
    """
    # Generate terrain output in Python
    path = this_dir() / f'data/{png_fname}.png'
    png = imread(path)
    terrain = decode_ele(png, encoding=encoding).flatten('C')

    # Load JS terrain output
    path = this_dir() / f'data/{png_fname}_terrain'
    with open(path, 'rb') as f:
        exp_terrain = np.frombuffer(f.read(), dtype=np.float32)

    assert np.array_equal(terrain,
                          exp_terrain), 'terrain not matching expected'
예제 #2
0
def test_errors(png_fname, encoding):
    """Test errors output from martini.create_tile(terrain)
    """
    # Generate errors output in Python
    path = this_dir() / f'data/{png_fname}.png'
    png = imread(path)
    terrain = decode_ele(png, encoding=encoding)
    martini = Martini(png.shape[0] + 1)
    tile = martini.create_tile(terrain)
    errors = np.asarray(tile.errors_view, dtype=np.float32)

    # Load JS errors output
    path = this_dir() / f'data/{png_fname}_errors'
    with open(path, 'rb') as f:
        exp_errors = np.frombuffer(f.read(), dtype=np.float32)

    assert np.array_equal(errors, exp_errors), 'errors not matching expected'
예제 #3
0
def load_assets(x,
                y,
                z,
                assets,
                tile_size,
                input_format: str = None,
                output_format: str = None,
                backfill: bool = False,
                pixel_selection: str = 'first',
                resampling_method: str = "nearest"):

    if input_format == 'terrarium':
        arrays = [rasterio.open(asset).read() for asset in assets]
        backfilled = backfill_arrays(*arrays)

        if output_format == 'terrarium':
            return backfilled

        data = decode_ele(backfilled, 'terrarium', backfill=backfill)

    elif input_format == 'geotiff':
        arrays = [rasterio.open(asset).read() for asset in assets]
        data = backfill_arrays(*arrays)

    else:
        with rasterio.Env(aws_session):
            pixsel_method = PIXSEL_METHODS[pixel_selection]
            data, _ = mosaic_tiler(
                assets,
                x,
                y,
                z,
                cogeoTiler,
                tilesize=tile_size,
                pixel_selection=pixsel_method(),
                resampling_method=resampling_method,
            )

    if output_format == 'terrarium':
        return mapzen_elevation_rgb(data)

    return data
예제 #4
0
def test_mesh(png_fname, max_error, encoding):
    # Generate mesh output in Python
    path = this_dir() / f'data/{png_fname}.png'
    png = imread(path)
    terrain = decode_ele(png, encoding=encoding)
    martini = Martini(png.shape[0] + 1)
    tile = martini.create_tile(terrain)
    vertices, triangles = tile.get_mesh(max_error)

    # Load JS mesh output
    path = this_dir() / f'data/{png_fname}_vertices_{max_error}'
    with open(path, 'rb') as f:
        exp_vertices = np.frombuffer(f.read(), dtype=np.uint16)

    path = this_dir() / f'data/{png_fname}_triangles_{max_error}'
    with open(path, 'rb') as f:
        exp_triangles = np.frombuffer(f.read(), dtype=np.uint32)

    assert np.array_equal(vertices,
                          exp_vertices), 'vertices not matching expected'
    assert np.array_equal(triangles,
                          exp_triangles), 'triangles not matching expected'
예제 #5
0
from time import time

from imageio import imread

from pymartini import Martini, decode_ele

path = './test/data/fuji.png'
fuji = imread(path)
terrain = decode_ele(fuji, 'mapbox')

start = time()
martini = Martini(fuji.shape[0] + 1)
end = time()
print(f'init tileset: {(end - start) * 1000:.3f}ms')

start = time()
tile = martini.create_tile(terrain)
end = time()
print(f'create tile: {(end - start) * 1000:.3f}ms')

start = time()
vertices, triangles = tile.get_mesh(30)
end = time()
print(f'mesh (max_error=30): {(end - start) * 1000:.3f}ms')
print(f'vertices: {len(vertices) / 2}, triangles: {len(triangles) / 3}')

all_meshes_start = time()
for i in range(21):
    start = time()
    tile.get_mesh(i)
    end = time()