Beispiel #1
0
def test_conversions(area_box, geo_tiff: GeoTiff):
    int_box = geo_tiff.get_int_box(area_box)
    i = int_box[0][0] + 5
    j = int_box[0][1] + 6
    geo_tiff.get_wgs_84_coords(i, j)

    # * note: these tests will fail when the tiff is skewed
    # bounding_box = geo_tiff.get_bBox_wgs_84(area_box)
    # assert area_box[0][0] <= bounding_box[0][0]
    # assert area_box[0][1] >= bounding_box[0][1]
    # assert area_box[1][0] >= bounding_box[1][0]
    # assert area_box[1][1] <= bounding_box[1][1]

    bounding_box_outer = geo_tiff.get_bBox_wgs_84(area_box, outer_points=True)

    print(area_box)

    assert area_box[0][0] >= bounding_box_outer[0][0]
    assert area_box[0][1] <= bounding_box_outer[0][1]
    assert area_box[1][0] <= bounding_box_outer[1][0]
    assert area_box[1][1] >= bounding_box_outer[1][1]

    bounding_box_outer2 = geo_tiff.get_bBox_wgs_84(area_box, outer_points=2)

    assert bounding_box_outer[0][0] >= bounding_box_outer2[0][0]
    assert bounding_box_outer[0][1] <= bounding_box_outer2[0][1]
    assert bounding_box_outer[1][0] <= bounding_box_outer2[1][0]
    assert bounding_box_outer[1][1] >= bounding_box_outer2[1][1]
Beispiel #2
0
def test_int_box(area_box, geo_tiff: GeoTiff):
    intBox = geo_tiff.get_int_box(area_box)
    assert isinstance(intBox, tuple)
    assert len(intBox) == 2
    assert isinstance(intBox[0], tuple)
    assert isinstance(intBox[1], tuple)
    intBox_outer = geo_tiff.get_int_box(area_box, outer_points=True)
    assert intBox[0][0] == intBox_outer[0][0] + 1
    assert intBox[0][1] == intBox_outer[0][1] + 1
    assert intBox[1][0] == intBox_outer[1][0] - 1
    assert intBox[1][1] == intBox_outer[1][1] - 1
Beispiel #3
0
def test_read_box(area_box, geo_tiff: GeoTiff):
    print("testing read tiff")
    print(f"reading: {geo_tiff}")
    print(f"Using bBox: {area_box}")
    print(f"crs_code: {geo_tiff.crs_code}")
    print(f"as_crs: {geo_tiff.as_crs}")
    array = geo_tiff.read_box(area_box)
    assert isinstance(array, np.ndarray)
    print("Sample array:")
    print(array)
    print(array.shape)
    assert isinstance(array, np.ndarray)
    zarr_array = geo_tiff.read_box(area_box, aszarr=True)
    print(type(zarr_array))
    assert isinstance(zarr_array, zarr.Array)
Beispiel #4
0
def create_new_pipeline():
    global hypercube, num_layers, current_layer, paint_flag, diag_flags, compare_points
    paint_flag = False
    fn = easygui.fileopenbox(msg='Открыть гиперкуб numpy',
                             filetypes=[['.npy', 'Numpy Hypercube'],
                                        ['.tiff', 'GeoTIFF'], images_ext_list],
                             default='*.npy')
    if fn:
        _, ext_ = os.path.splitext(fn)
        if (ext_ == '.npy'):
            hypercube = numpy.load(fn)
        elif (ext_ == '.tiff'):
            # https://kipcrossing.github.io/2021-01-04-geotiff-python-package/
            from geotiff import GeoTiff
            geoTiff = GeoTiff(fn)
            hypercube = geoTiff.read()[:].transpose((2, 0, 1))
        elif (ext_ in images_ext_list):
            #hypercube = cv2.imread(fn).transpose((2, 0, 1)) #EXIF fix might be here...
            f = open(fn, "rb")
            img = cv2.imdecode(numpy.frombuffer(f.read(), dtype=numpy.uint8),
                               cv2.IMREAD_COLOR)
            hypercube = img.transpose((2, 0, 1))
        num_layers = hypercube.shape[0]
        cv2.namedWindow("Image", cv2.WINDOW_NORMAL)
        cv2.resizeWindow("Image", hypercube.shape[2], hypercube.shape[1])
        cv2.namedWindow("Settings", cv2.WINDOW_NORMAL)
        cv2.resizeWindow("Settings", 300, 100)
        cv2.setMouseCallback('Image', onmouse)
        cv2.createTrackbar('layer', 'Settings', 0, num_layers - 1,
                           OnLayerChange)
        cv2.createTrackbar('red_edge', 'Settings', num_layers // 2,
                           num_layers - 1, OnRedEdgeChange)
        cv2.setTrackbarMin('red_edge', 'Settings', 1)
        cv2.createTrackbar('num_points', 'Settings', 1, 9, OnNumPointsChange)
        cv2.setTrackbarMin('num_points', 'Settings', 1)
        current_layer = 0
        diag_flags = [True for i in range(num_layers)
                      ]  #numpy.ones((num_layers,), dtype=int)
        compare_points = []
        OnLayerChange(0)
Beispiel #5
0
import numpy as np  # type: ignore

from geotiff import GeoTiff  # type: ignore

filename = "dem.tif"
# filename = "red.tif"
dir = "./tests/inputs/"
tiff_file = os.path.join(dir, filename)
area_box = ((138.632071411, -32.447310785), (138.644218874, -32.456979174))

if __name__ == "__main__":
    print("testing read tiff")
    print(f"reading: {tiff_file}")
    print(f"Using bBox: {area_box}")
    geo_tiff: GeoTiff = GeoTiff(tiff_file, crs_code=4326, as_crs=4326, band=0)

    print()
    print(geo_tiff.crs_code)
    print(geo_tiff.as_crs)
    print(geo_tiff.tif_shape)
    print(geo_tiff.tif_bBox)
    print(geo_tiff.tif_bBox_wgs_84)
    print(geo_tiff.tif_bBox_converted)
    i = 5
    j = 6
    print(geo_tiff.get_coords(i, j))
    print(geo_tiff.get_wgs_84_coords(i, j))
    zarr_array = geo_tiff.read()
    print(zarr_array)
    print(np.array(zarr_array))
Beispiel #6
0
def test_get_coord_arrays(geo_tiff: GeoTiff, area_box):
    array = geo_tiff.read_box(area_box)
    print(geo_tiff.tif_bBox_wgs_84)
    lon_array, lat_array = geo_tiff.get_coord_arrays(bBox=area_box)
    assert array.shape == lon_array.shape
    assert array.shape == lat_array.shape
Beispiel #7
0
def test_read(geo_tiff: GeoTiff):
    zarr_array = geo_tiff.read()
    print(zarr_array.info)
    assert isinstance(zarr_array, zarr.Array)
    print(zarr_array.chunks)
Beispiel #8
0
def geo_tiff(request):
    filename = request.param
    dir = dir = "./tests/inputs/"
    # TODO: test bands, and crs params
    return GeoTiff(os.path.join(dir, filename))