如何将光栅 window 导出到没有地理参考信息的图像?
How to export a rasterio window to an image without geo-reference information?
我想将 rasterio
window 导出到图像。
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
window 导出非地理参考图像?
您需要设置转换,如果将其设置为身份,则警告消失:
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)
我想将 rasterio
window 导出到图像。
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
window 导出非地理参考图像?
您需要设置转换,如果将其设置为身份,则警告消失:
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)