def apply_valid_range(input_data_set_path: str, file_path: str) -> str:
    """Apply Valid Range -10000 -> 10000.

    Args:
        input_data_set_path (str) - Path to the input data set
        file_path (str) - Target data set filename
    Returns:
        Path to valid_range_image
    """
    src_ds = GDALOpen(input_data_set_path, GA_ReadOnly)

    if src_ds is None:
        raise ValueError(
            'Could not open data set "{}"'.format(input_data_set_path))

    driver = GetDriverByName('MEM')

    src_band = src_ds.GetRasterBand(1)
    data_set = driver.Create('', src_ds.RasterXSize, src_ds.RasterYSize, 1,
                             src_band.DataType)
    data_set.SetGeoTransform(src_ds.GetGeoTransform())
    data_set.SetProjection(src_ds.GetProjection())

    data_set_band = data_set.GetRasterBand(1)

    data_set_band.WriteArray(src_band.ReadAsArray())

    band_array = data_set_band.ReadAsArray()
    dummy = -9999
    data_set_band.SetNoDataValue(dummy)
    band_array[band_array <= -10000] = dummy
    band_array[band_array >= 10000] = dummy
    driver = GetDriverByName('GTiff')
    data_set_band.WriteArray(band_array)

    dst_ds = driver.CreateCopy(file_path, data_set, options=["COMPRESS=LZW"])

    del dst_ds
    del src_ds
    del data_set

    return file_path
Beispiel #2
0
    plt.subplot(1,2,2), plt.imshow(label_full)
    #plt.savefig('testResult.tif', dpi=300)

    # !!!! Save GEOreferenced TIFF
    pred = np.load('label_pred.npy')
    pred = (pred*255).astype('uint8')
    #pred = (pred > 0.9).astype('uint8')
    cv2.imwrite(files, pred)
    #cv2.imwrite(files, pred)
    
    dataset = Open(os.path.join(path,files))
    if dataset is None:
        print('Unable to open')
        sys.exit(1)
    
    projection   = dataset.GetProjection()
    geotransform = dataset.GetGeoTransform()
    
    if projection is None and geotransform is None:
        print('No projection or geotransform found on file')
        sys.exit(1)
        
    dataset2 = Open(files, GA_Update)
    
    if geotransform is not None and geotransform != (0,1,0,0,0,1):
        dataset2.SetGeoTransform( geotransform )
    
    if projection is not None and projection != '':
        dataset2.SetProjection( projection )
    
    gcp_count = dataset.GetGCPCount()