将x,y转换为纬度和经度 [英] Convert x,y to latitiude and longitude
问题描述
如果我的地图图片在以下位置:
If I have a map image where:
- 已知左上角(x = 0,y = 0)的纬度和经度
- 图像的宽度和高度是已知的
- 缩放(z轴)是已知的.
我们可以计算图像中其他坐标的纬度和经度吗? 例如,在下面的图像中,如果我想计算白色方晶(已知坐标(x,y)的位置)的纬度/经度值
Can we compute the latitude and longitude for other coordinates in the image? For example, in the following image if I want to compute the lat/lon values for the white ploygon (where the coordinates (x,y) are known)
推荐答案
So given the information and the shape of the image, (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)或(经度,纬度).
Gives the (x, y) or (longtiude, latitude) of your given point.
可以使用numpy给定点集来推广这种方法:
This approach can be generalised given a set of points using numpy as:
coords * pixel_sizes + top_left # coords is (N, 2) array
如果coords
是数组的元组,则可以使用np.column_stack
将其转换为(N,2)
数组.
If coords
is a tuple of arrays it can be converted to an (N,2)
array using np.column_stack
.
这篇关于将x,y转换为纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!