2016-08-17 10 views
2

基本的な画像フィルタリングをやろうとしています。 Iveはrasterio cookbookから抜粋したスニペットを含んでいます(中央値フィルタ出力から.astype()を削除しました)。問題は、入力と出力のラスタが同じ程度でなければならないということです。変換とアファインは入力と出力で異なります。これは期待される行動ですか?私は、アフィンに何かをして、出力を入力と同じにするために変換する必要がありますか?rasterio transformとaffine

Python 2.7.11 | Anaconda 4.0.0(64-bit)| (デフォルトでは、2016年2月16日、9時58分36秒)MSC v.1500 64ビット(AMD64)]

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

をWin32で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) 

私はこれが必要なのです。