Python 光栅变换与仿射

Python 光栅变换与仿射,python,rasterio,Python,Rasterio,我正在尝试做一些基本的图像过滤。我包含了rasterio食谱中的一个片段(我从中值滤波器输出中删除了.astype())。问题是我的输入和输出光栅应该具有相同的范围,但没有。对于输入和输出,变换和仿射是不同的。这是预期的行为吗?我需要对仿射和变换做些什么才能使输出与输入相同吗 win32上的Python 2.7.11 | Anaconda 4.0.0(64位)|(默认值,2016年2月16日,09:58:36)[MSC v.1500 64位(AMD64)] 光栅==0.36.0 import r

我正在尝试做一些基本的图像过滤。我包含了rasterio食谱中的一个片段(我从中值滤波器输出中删除了.astype())。问题是我的输入和输出光栅应该具有相同的范围,但没有。对于输入和输出,变换和仿射是不同的。这是预期的行为吗?我需要对仿射和变换做些什么才能使输出与输入相同吗

win32上的Python 2.7.11 | Anaconda 4.0.0(64位)|(默认值,2016年2月16日,09:58:36)[MSC v.1500 64位(AMD64)]

光栅==0.36.0

import rasterio
from scipy.signal import medfilt

path = "map.tif"
output = "map2.tif"

with rasterio.open(path) as src:
    array = src.read()
    profile = src.profile

# apply a 5x5 median filter to each band
filtered = medfilt(array, (1, 5, 5))

# Write to tif, using the same profile as the source
with rasterio.open(output, 'w', **profile) as dst:
    dst.write(filtered)

    print profile
    print dst.profile

>>> {'count': 1, 'crs': CRS({'init': u'epsg:3857'}), 'interleave': 'band', 'dtype': 'float64', 'affine': Affine(100.0, 0.0, -13250000.0, 0.0, 100.0, 3980000.0), 'driver': u'GTiff', 'transform': (-13250000.0, 100.0, 0.0, 3980000.0, 0.0, 100.0), 'height': 1700, 'width': 1700, 'tiled': False, 'nodata': None}
>>> {'count': 1, 'crs': CRS({'init': u'epsg:3857'}), u'interleave': 'band', 'dtype': 'float64', 'affine': Affine(-13250000.0, 100.0, 0.0, 3980000.0, 0.0, 100.0), 'driver': u'GTiff', 'transform': (0.0, -13250000.0, 100.0, 100.0, 3980000.0, 0.0), 'height': 1700, 'width': 1700, u'tiled': False, 'nodata': None}

rasterio文档包括一个您可能会发现有用的文档。我曾经有两行代码来处理这个问题,如下所示:

out_profile = src.profile.copy()
out_affine = out_profile.pop("affine")
out_profile["transform"] = out_affine

# then, write the output raster

with rasterio.open(output, 'w', **out_profile) as dst:
    dst.write(filtered)
我认为这是必要的