python - 如何将光栅窗口导出到没有地理引用信息的图像?

标签 python image-processing gis raster rasterio

我想将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: Dataset has no geotransform set. The identity matrix may be returned.

有没有办法从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',
        'transform': rasterio.Affine(1, 0, 0, 0, 1, 0),
    }
    with rasterio.open(path, 'w', **profile) as dst:
        dst.write(w)

关于python - 如何将光栅窗口导出到没有地理引用信息的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58393244/

相关文章:

python - Pandas 映射 groupby 在同一数据框中具有多个列

python - 将 PythonMagick Image 对象转换为 numpy 数组(用于 OpenCV),然后转换为 PIL 图像对象

r - 将多边形列表组合成单个对象

python - "Rank"DataFrame 每行列数

python - Python中浅拷贝而不是新对象

c - C中的.bmp处理

sqlite - 纬度查询-精度

python - 确定 NxN 数组的行和列中的最低值

python - 如何使用带有 Tensorflow 的 Docker 在 Mac 终端上运行 Python 脚本?

opencv - 使用 OpenCV 从边缘图像中去除长水平/垂直线