版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/humanity11/article/details/72911351
GDAL處理地理圖像座標計算
本文講解如何使用GDAL處理地理圖像時,通過使用行列號計算和轉換成tiff圖像的地理座標:
tif中座標計算的方法如下,其中Col表示該座標點處圖像的列號,ROW表示該座標點處圖像的行號,比如圖像左上角Col爲0,ROW爲0,圖像右下角Col爲圖像寬度,ROW爲圖像高度。
Xgeo = GT(0) + Col*GT(1) + Row*GT(2)
Ygeo = GT(3) + Col*GT(4) + Row*GT(5)
一、文中用到的係數說明:
Col表示該座標點處圖像的列號ROW表示該座標點處圖像的行號
x:該點X座標
y:該點Y座標
upleft:圖像左上角座標
upright:圖像右上角座標
downleft:圖像左下角座標
downright:圖像右下角座標
二、公式推導
則根據計算公式:GT(0)=左上點的Xgeo=upleft(x)
GT(3)=坐上點的Ygeo=upleft(y)
upRighg(x)=GT(0)+srcWidth*GT(1)+0*GT(2)
=>GT(1)=(upRight(x)-GT(0))/srcWidth;
downLeft(x)=GT(0)+0*GT(1)+srcHeight*GT(2)
=>GT(2)=(downLeft(x)-GT(0))/srcHeight
upRight(y)=GT(3)+srcWidth*GT(4)+0*GT(5)
=>GT(4)=(upRight(y)-GT(3))/srcWidth;
downLeft(y)=GT(3)+0*GT(4)+srcHeight*GT(5)
=>GT(5)=(downLeft(y)-GT(3))/srcHeight;
(三)係數驗證
驗證:右下角(假設圖像爲平行四邊形)downright=[downleft(x)+(upright(x)-upleft(x)),
upright(y)-(upleft(y)-downleft(y))]
(1)證明右下角X方向座標成立:downright(x)=downleft(x)+(upright(x)-upleft(x)
downright(x)=GT(0) + Col*GT(1) + Row*GT(2)=upleft(x)+srcWidth*(upRight(x)-GT(0))/srcWidth+srcHeight*(downLeft(x)-GT(0))/srcHeight
=upleft(x)+upRight(x)-GT(0)+downLeft(x)-GT(0)
=upleft(x)+upRight(x)-upleft(x)+downLeft(x)-upleft(x)
=upRight(x)+downLeft(x)-upLeft(x)
證明成立(係數GT(0),GT(1),GT(2)正確)
(2)證明右下角Y方向座標成立:
downright(y)=upright(y)-upleft(y)+downLeft(y)downright(y)=GT(3) + Col*GT(4) + Row*GT(5)
=upleft(y)+srcWidth*GT(4)+srcHeight*GT(5)
=upleft(y)+srcWidht*(upRight(y)-GT(3))/srcWidth+srcHeight*(downLeft(y)-GT(3))/srcHeight
=upleft(y)+upRight(y)-GT(3)+downLeft(y)-GT(3)
=upleft(y)+upRight(y)-upleft(y)+downLeft(y)-upleft(y)
=upRight(y)+downLeft(y)-upleft(y)
證明成立(係數GT(3),GT(4),GT(5)正確)