【发布时间】:2017-12-30 11:01:08
【问题描述】:
我正在尝试将坐标从纬度/经度转换为像素,但在此过程中我丢失了分数。
我使用的代码如下:
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获得。
标签: python numpy coordinates gis coordinate-transformation