将x,y转换为纬度和经度

时间:2020-05-16 09:51:54

标签: numpy geolocation latitude-longitude pyproj

如果我的地图图像在哪里,

  • 已知左上角(x = 0,y = 0)的纬度和经度
  • 图像的宽度和高度是已知的
  • 缩放(z轴)是已知的。

我们可以计算图像中其他坐标的纬度和经度吗? 例如,在下图中,如果我想计算白色方晶(已知坐标(x,y)的位置)的纬度/经度值

enter image description here

1 个答案:

答案 0 :(得分:0)

给定图像的信息和形状,(see previous question):

import numpy as np

top_left = np.array((32.0055597, 35.9265418))
bottom_right = np.array((33.0055597, 36.9265418))

delta = bottom_right - top_left

shape = (454, 394)[::-1] # convert from ij to xy coords

pixel_sizes = delta / shape

pixel_sizes * (80, 200) + top_left
>>> array([32.20860539, 36.36707043])

给出给定点的(x,y)或(经度,纬度)。

在使用numpy作为一组点的情况下,可以推广这种方法:

coords * pixel_sizes + top_left # coords is (N, 2) array

如果coords是数组的元组,则可以使用(N,2)将其转换为np.column_stack数组。