Ejemplo n.º 1
0
def test_datasets_handler(testdb, use_testdb):
    import terracotta
    from terracotta.handlers import datasets
    driver = terracotta.get_driver(str(testdb))
    keys = driver.key_names
    assert datasets.datasets()
    assert datasets.datasets() == [
        dict(zip(keys, pair)) for pair in driver.get_datasets().keys()
    ]

    # check key order
    assert all(tuple(ds.keys()) == keys for ds in datasets.datasets())
Ejemplo n.º 2
0
def test_singleband_out_of_bounds(use_testdb):
    import terracotta
    from terracotta.handlers import datasets, singleband
    ds = datasets.datasets()

    for keys in ds:
        with pytest.raises(terracotta.exceptions.TileOutOfBoundsError):
            singleband.singleband(keys, (10, 0, 0))
Ejemplo n.º 3
0
def test_singleband_handler(use_testdb, raster_file_xyz, upsampling_method):
    import terracotta
    terracotta.update_settings(UPSAMPLING_METHOD=upsampling_method)

    from terracotta.handlers import datasets, singleband
    settings = terracotta.get_settings()
    ds = datasets.datasets()

    for keys in ds:
        raw_img = singleband.singleband(keys, raster_file_xyz)
        img_data = np.asarray(Image.open(raw_img))
        assert img_data.shape == settings.DEFAULT_TILE_SIZE
Ejemplo n.º 4
0
def test_singleband_tile_size(use_testdb, raster_file_xyz):
    from terracotta.handlers import datasets, singleband
    ds = datasets.datasets()

    test_tile_size = (16, 32)

    for keys in ds:
        raw_img = singleband.singleband(keys,
                                        raster_file_xyz,
                                        tile_size=test_tile_size)
        img_data = np.asarray(Image.open(raw_img))
        assert img_data.shape == test_tile_size
Ejemplo n.º 5
0
def get_datasets() -> str:
    """Get all available key combinations
    ---
    get:
        summary: /datasets
        description:
            Get keys of all available datasets that match given key constraint.
            Constraints may be combined freely. Returns all known datasets if no query parameters
            are given.
        parameters:
          - in: query
            schema: DatasetOptionSchema
        responses:
            200:
                description: All available key combinations
                schema:
                    type: array
                    items: DatasetSchema
            400:
                description: Query parameters contain unrecognized keys
    """
    from terracotta.handlers.datasets import datasets
    option_schema = DatasetOptionSchema()
    options = option_schema.load(request.args)

    limit = options.pop('limit')
    page = options.pop('page')
    keys = options or None

    payload = {
        'limit': limit,
        'page': page,
        'datasets': datasets(keys, page=page, limit=limit)
    }

    schema = DatasetSchema()
    return jsonify(schema.load(payload))
Ejemplo n.º 6
0
def test_metadata_handler(use_testdb):
    from terracotta.handlers import metadata, datasets
    ds = datasets.datasets()[0]
    md = metadata.metadata(ds)
    assert md
    assert md['metadata'] == ['extra_data']