Ejemplo n.º 1
0
def test_read_unscale():
    """Should or Shouldn't apply scale and offset to a data."""
    with rasterio.open(COG_SCALE) as src_dst:
        arr, mask = reader.tile(src_dst, 218, 99, 8, tilesize=128)
        arrS, maskS = reader.tile(src_dst,
                                  218,
                                  99,
                                  8,
                                  tilesize=128,
                                  unscale=True)

        assert arr.dtype == "int16"
        assert arrS.dtype == "float32"
        assert not numpy.array_equal(arr, arrS)
        numpy.testing.assert_array_equal(mask, maskS)

        meta = reader.metadata(src_dst)
        assert isinstance(meta["statistics"][1]["min"], int)

        meta = reader.metadata(src_dst, unscale=True)
        assert isinstance(meta["statistics"][1]["min"], float)

        p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs)
        assert p == [8917]

        p = reader.point(src_dst, [310000, 4100000],
                         coord_crs=src_dst.crs,
                         unscale=True)
        assert round(p[0], 3) == 1000.892
Ejemplo n.º 2
0
def test_point():
    """Read point values"""
    with rasterio.open(COG_SCALE) as src_dst:
        p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs, indexes=1)
        assert p == [8917]

        p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs)
        assert p == [8917]

        with pytest.raises(Exception):
            reader.point(src_dst, [810000, 4100000], coord_crs=src_dst.crs)
Ejemplo n.º 3
0
def test_point():
    """Read point values"""
    with rasterio.open(COG_SCALE) as src_dst:
        p = reader.point(src_dst, [310000, 4100000],
                         coord_crs=src_dst.crs,
                         indexes=1)
        assert p == [8917]

        p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs)
        assert p == [8917]

        with pytest.raises(PointOutsideBounds):
            reader.point(src_dst, [810000, 4100000], coord_crs=src_dst.crs)

    with rasterio.open(S3_MASK_PATH) as src_dst:
        # Test with COG + internal mask
        assert not reader.point(src_dst, [-104.7753105, 38.953548])[0]
        assert reader.point(src_dst, [-104.7753105415, 38.953548],
                            masked=False)[0] == 0

    with rasterio.open(S3_ALPHA_PATH) as src_dst:
        # Test with COG + Alpha Band
        assert not reader.point(src_dst, [-104.77519499, 38.95367054])[0]
        assert reader.point(src_dst, [-104.77519499, 38.95367054],
                            masked=False)[0] == 0
Ejemplo n.º 4
0
def point(address: str, lon: float, lat: float, **kwargs: Any) -> List:
    """
    Read point value from a file.

    Attributes
    ----------
    address: str
        file url.
    lon: float
        Longitude
    lat: float
        Latittude.
    kwargs: dict, optional
        These will be passed to the 'rio_tiler.reader.point' function.

    Returns
    -------
    point: list
        List of pixel values per bands indexes.

    """
    with rasterio.open(address) as src_dst:
        return reader.point(src_dst, (lon, lat), **kwargs)
Ejemplo n.º 5
0
def test_point():
    """Read point values"""
    with rasterio.open(COG_SCALE) as src_dst:
        p = reader.point(src_dst, [310000, 4100000],
                         coord_crs=src_dst.crs,
                         indexes=1)
        assert p == [8917]

        p = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs)
        assert p == [8917]

        with pytest.raises(PointOutsideBounds):
            reader.point(src_dst, [810000, 4100000], coord_crs=src_dst.crs)

    with rasterio.open(COG_CMAP) as src_dst:
        # Should return None when reading masked pixel
        assert not reader.point(src_dst, [-95.530, 19.8882])[0]

        # Should return value when not using Masked
        assert reader.point(src_dst, [-95.530, 19.8882], masked=False)[0] == 0

        # Checking nodata overwrite
        assert (reader.point(src_dst, [-95.530, 19.8882],
                             masked=True,
                             nodata=100)[0] == 0)

    with rasterio.open(S3_MASK_PATH) as src_dst:
        # Test with COG + internal mask
        assert not reader.point(src_dst, [-104.7753105, 38.953548])[0]
        assert reader.point(src_dst, [-104.7753105415, 38.953548],
                            masked=False)[0] == 0

    with rasterio.open(S3_ALPHA_PATH) as src_dst:
        # Test with COG + Alpha Band
        assert not reader.point(src_dst, [-104.77519499, 38.95367054])[0]
        assert reader.point(src_dst, [-104.77519499, 38.95367054],
                            masked=False)[0] == 0