2016-08-17 73 views
2

我試圖做一些基本的圖像過濾。我從rasterio食譜中包含一段逐字記錄(我從中值過濾器輸出中刪除了.astype())。問題是,我的輸入和輸出柵格應該有相同的程度,但沒有。輸入和輸出的變換和仿射是不同的。這是預期的行爲?我是否需要對仿射進行操作並進行變換以使輸出與輸入相同?rasterio變換和仿射

Python 2.7.11 | Anaconda 4.0.0(64-bit)| (默認情況下,2016年2月16日,9點58分36秒)[MSC v.1500 64位(AMD64)]在Win32

rasterio == 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} 

回答

0

的rasterio文檔包括history affine/transform usage那你可能會覺得有用。我曾經有一條如下幾條線來處理這個問題:

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) 

我認爲這是必要的。