2016-10-08 18 views
0

ジオテフファイルがありますが、座標はわずかです。私は、画像を幾何学的に変換(シフト)するために、rasterioのAPI(またはpygdalのような他のpython geo API)を使用したいと思います。たとえば、画像の座標を「北」のピクセル幅で移動するにはどうすればよいですか?Rasterio Geotiff座標変換

qgisのようなツールで表示すると、画像はまったく同じになりますが、数ピクセル上に移動します。

答えて

1

ジオリファレンスのジオリファレンスを変更することは、本当に簡単な作業です。私はgdal pythonモジュールを使ってそれを行う方法を示します。まず、「アファインジオトランスフォーム」を中心にGDAL data modelを見てください。

私はあなたのgeotransformこのgeotransformで

gt = (X_topleft, X_resolution, 0, Y_topleft, 0, Y_resolution) 

のようなものが見えるように、ラスタは(0,0)座標、ラスタが偏ったり回転させないことを前提としていますが(X_topleft, Y_topleft)の左上隅を持っています。

ラスタ位置をシフトするには、X_topleftY_topleftを変更する必要があります。

import gdal 

# open dataset with update permission 
ds = gdal.Open('myraster.tif', gdal.GA_Update) 
# get the geotransform as a tuple of 6 
gt = ds.GetGeoTransform() 
# unpack geotransform into variables 
x_tl, x_res, dx_dy, y_tl, dy_dx, y_res = gt 

# compute shift of 1 pixel RIGHT in X direction 
shift_x = 1 * x_res 
# compute shift of 2 pixels UP in Y direction 
# y_res likely negative, because Y decreases with increasing Y index 
shift_y = -2 * y_res 

# make new geotransform 
gt_update = (x_tl + shift_x, x_res, dx_dy, y_tl + shift_y, dy_dx, y_res) 
# assign new geotransform to raster 
ds.SetGeoTransform(gt_update) 
# ensure changes are committed 
ds.FlushCache() 
ds = None 
+0

ありがとうございます! gdalライブラリは美しく動作しました。私はrasterioというライブラリを使ってAffineを修正しようとしましたが、バウンディングボックスが変更されなかった問題が発生しました。基本的に画像の中央部分は正しく移動しますが、一方の端が黒くなり、他方の端が消えてしまいます。代わりにこの方法を使用するように切り替えます。 –

関連する問題