我試圖將座標從經度/緯度轉換爲像素,但在此過程中我失去了點。將座標轉換爲失去點的像素
,我正在使用的代碼如下:
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
df=pd.read_csv('cords.csv')
cords=df.as_matrix(columns=['x','y'])
gt=[7.6445503225, 5.4065168747250134e-06, 0.0, 45.07436634583334, 0.0, -5.406516856707135e-06]
index=np.zeros(cords.shape)
index[:,1]=((cords[:,1] - gt[3])/gt[5]).round()
index[:,0]=((cords[:,0] - gt[0])/gt[1]).round()
index=index.astype(int)
index[:,0]=index[:,0]-min(index[:,0])+1
index[:,1]=index[:,1]-min(index[:,1])+1
row=max(index[:,1])
col=max(index[:,0])
image=np.zeros([row+1,col+1])
for i in range(0,len(index)):
image[index[i,1],index[i,0]]=255
正如你所看到的,在將緯度/經度轉換爲像素數字時有一些缺失點。黃色是255值,紫色是0值。 這怎麼解決?
在這裏,你會發現我使用cords.csv
這裏你可以找到與需要被設置到每個像素的值的座標的座標。 cords_valus.csv
什麼是'gt'在做什麼? –
它是從經緯度到軸座標的轉換向量。使用GDAL獲得。 –