【问题标题】:How to export a rasterio window to an image without geo-reference information?如何将光栅窗口导出到没有地理参考信息的图像?
【发布时间】:2019-10-15 11:07:53
【问题描述】:

我想将rasterio 窗口导出为图像。

import rasterio

def export_window(w, path):
    number_of_bands, height, width = w.shape

    profile = {
        "driver": "JPEG",
        "count": number_of_bands,
        "height": height,
        "width": width,
        'dtype': 'uint8'
    }
    with rasterio.open(path, 'w', **profile) as dst:
        dst.write(w)

不幸的是,因为我没有在上面的 profile 中指定 transform 键,所以我收到以下警告:

>>> raster = rasterio.open("/tmp/geo.tif")
>>> w = raster.read(window=rasterio.windows.Window(0, 0, 500, 500))
>>> export_window(w, "/tmp/export.jpg")

NotGeoreferencedWarning:数据集没有地理变换集。可能会返回单位矩阵。

有没有办法从rasterio 窗口导出非地理参考图像而不会收到警告?

【问题讨论】:

    标签: python image-processing gis raster rasterio


    【解决方案1】:

    您需要设置转换,如果您将其设置为标识,警告就会消失:

    import rasterio
    
    def export_window(w, path):
        number_of_bands, height, width = w.shape
    
        profile = {
            "driver": "JPEG",
            "count": number_of_bands,
            "height": height,
            "width": width,
            'dtype': 'uint8',
            'transform': rasterio.Affine(1, 0, 0, 0, 1, 0),
        }
        with rasterio.open(path, 'w', **profile) as dst:
            dst.write(w)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-13
      • 2013-08-22
      • 2015-12-24
      • 2013-08-04
      • 1970-01-01
      • 2018-04-28
      • 2012-10-08
      • 1970-01-01
      相关资源
      最近更新 更多