utils.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:GeoInfoMiner 作者: jingge326 项目源码 文件源码
def read_image(imagery_path):
    # Read image
    dataset = gdal.Open(imagery_path)
    dsmatrix = dataset.ReadAsArray(xoff=0, yoff=0, xsize=dataset.RasterXSize, ysize=dataset.RasterYSize)

    # Get Geographic meta data
    geo_trans_list = dataset.GetGeoTransform()
    proj_str = dataset.GetProjection()
    num_bands = dataset.RasterCount

    # Adapt to one bands or multi-bands
    if num_bands > 1:
        # Unfold array into pandas DataFrame
        rows = dsmatrix.shape[1]
        cols = dsmatrix.shape[2]
        data_array = dsmatrix[:,0,:]
        for irow in range(1,rows):
            tempmatirx = dsmatrix[:,irow,:]
            data_array = np.hstack((data_array,tempmatirx))
    else:
        # Unfold array into pandas DataFrame
        rows = dsmatrix.shape[0]
        cols = dsmatrix.shape[1]
        data_array = dsmatrix[0,:]
        for irow in range(1,rows):
            tempmatirx = dsmatrix[irow,:]
            data_array = np.hstack((data_array,tempmatirx))

    data_frame = pd.DataFrame(data_array.T)

    return data_frame, rows, cols, geo_trans_list, proj_str, num_bands
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号