[英]Rotate long/lat coordinates based on True North
I have a file with latitude and longitude coordinates called coordinates.txt
我有一个名为
coordinates.txt
.txt 的经纬度坐标文件
29.66150677 -98.39336541
29.66150677 -98.39337576
29.66150651 -98.39336541
29.66150328 -98.39337576
29.66150677 -98.39336475
29.66150677 -98.39338611
29.66150393 -98.39338611
29.66150677 -98.39339646
29.66150659 -98.39339646
29.66150677 -98.39339693
29.66151576 -98.39334472
29.66151576 -98.39335506
29.66151511 -98.39334472
29.66151058 -98.39335506
29.66151576 -98.39334322
29.66151576 -98.39336541
29.66151576 -98.39337576
29.66151576 -98.39338611
29.66151576 -98.39339646
29.66151576 -98.39340681
29.66151067 -98.39340681
29.66151576 -98.39341515
29.66152475 -98.39332402
29.66152475 -98.39333437
29.66152443 -98.39332402
29.66151973 -98.39333437
29.66152475 -98.39332332
29.66152475 -98.39334472
29.66152475 -98.39335506
29.66152475 -98.39336541
29.66152475 -98.39337576
29.66152475 -98.39338611
29.66152475 -98.39339646
29.66152475 -98.39340681
29.66152475 -98.39341716
29.66151699 -98.39341716
29.66152475 -98.39342722
29.66153375 -98.39331367
29.66153375 -98.39332402
29.6615302 -98.39331367
29.66153375 -98.3933086
29.66153375 -98.39333437
29.66153375 -98.39334472
29.66153375 -98.39335506
29.66153375 -98.39336541
29.66153375 -98.39337576
29.66153375 -98.39338611
29.66153375 -98.39339646
29.66153375 -98.39340681
29.66153375 -98.39341716
29.66153375 -98.39342751
29.66152507 -98.39342751
29.66153375 -98.39343443
29.66154274 -98.39330332
29.66154274 -98.39331367
29.66153745 -98.39330332
29.66154274 -98.39329625
29.66154274 -98.39332402
29.66154274 -98.39333437
29.66154274 -98.39334472
29.66154274 -98.39335506
29.66154274 -98.39336541
29.66154274 -98.39337576
29.66154274 -98.39338611
29.66154274 -98.39339646
29.66154274 -98.39340681
29.66154274 -98.39341716
29.66154274 -98.39342751
29.66154274 -98.39343786
29.66153992 -98.39343786
29.66154274 -98.3934387
29.66155173 -98.39329297
29.66155173 -98.39330332
29.6615457 -98.39329297
29.66155173 -98.39328644
29.66155173 -98.39331367
29.66155173 -98.39332402
29.66155173 -98.39333437
29.66155173 -98.39334472
29.66155173 -98.39335506
29.66155173 -98.39336541
29.66155173 -98.39337576
29.66155173 -98.39338611
29.66155173 -98.39339646
29.66155173 -98.39340681
29.66155173 -98.39341716
29.66155173 -98.39342751
29.66155173 -98.39343786
29.66155173 -98.39344106
29.66156073 -98.39328262
29.66156073 -98.39329297
29.66155555 -98.39328262
29.66156073 -98.39327744
29.66156073 -98.39330332
29.66156073 -98.39331367
29.66156073 -98.39332402
29.66156073 -98.39333437
29.66156073 -98.39334472
29.66156073 -98.39335506
29.66156073 -98.39336541
29.66156073 -98.39337576
29.66156073 -98.39338611
29.66156073 -98.39339646
29.66156073 -98.39340681
29.66156073 -98.39341716
29.66156073 -98.39342751
29.66156073 -98.39343786
29.66156073 -98.39344196
29.66156972 -98.39327227
29.66156972 -98.39328262
29.66156651 -98.39327227
29.66156972 -98.39326964
29.66156972 -98.39329297
29.66156972 -98.39330332
29.66156972 -98.39331367
29.66156972 -98.39332402
29.66156972 -98.39333437
29.66156972 -98.39334472
29.66156972 -98.39335506
29.66156972 -98.39336541
29.66156972 -98.39337576
29.66156972 -98.39338611
29.66156972 -98.39339646
29.66156972 -98.39340681
29.66156972 -98.39341716
29.66156972 -98.39342751
29.66156972 -98.39343786
29.66156972 -98.393442
29.66157871 -98.39327227
29.66157871 -98.39328262
29.66157871 -98.39326327
29.66157871 -98.39329297
29.66157871 -98.39330332
29.66157871 -98.39331367
29.66157871 -98.39332402
29.66157871 -98.39333437
29.66157871 -98.39334472
29.66157871 -98.39335506
29.66157871 -98.39336541
29.66157871 -98.39337576
29.66157871 -98.39338611
29.66157871 -98.39339646
29.66157871 -98.39340681
29.66157871 -98.39341716
29.66157871 -98.39342751
29.66157871 -98.39343786
29.66157871 -98.39344084
29.66158771 -98.39326192
29.66158771 -98.39327227
29.66158097 -98.39326192
29.66158771 -98.39325788
29.66158771 -98.39328262
29.66158771 -98.39329297
29.66158771 -98.39330332
29.66158771 -98.39331367
29.66158771 -98.39332402
29.66158771 -98.39333437
29.66158771 -98.39334472
29.66158771 -98.39335506
29.66158771 -98.39336541
29.66158771 -98.39337576
29.66158771 -98.39338611
29.66158771 -98.39339646
29.66158771 -98.39340681
29.66158771 -98.39341716
29.66158771 -98.39342751
29.66158771 -98.39343786
29.66158771 -98.39343926
29.66159226 -98.39343786
29.6615967 -98.39326192
29.6615967 -98.39327227
29.6615967 -98.39325426
29.6615967 -98.39328262
29.6615967 -98.39329297
29.6615967 -98.39330332
29.6615967 -98.39331367
29.6615967 -98.39332402
29.6615967 -98.39333437
29.6615967 -98.39334472
29.6615967 -98.39335506
29.6615967 -98.39336541
29.6615967 -98.39337576
29.6615967 -98.39338611
29.6615967 -98.39339646
29.6615967 -98.39340681
29.6615967 -98.39341716
29.6615967 -98.39342751
29.6615967 -98.39343623
29.66160569 -98.39325157
29.66160569 -98.39326192
29.66160564 -98.39325157
29.66160569 -98.39325156
29.66160569 -98.39327227
29.66160569 -98.39328262
29.66160569 -98.39329297
29.66160569 -98.39330332
29.66160569 -98.39331367
29.66160569 -98.39332402
29.66160569 -98.39333437
29.66160569 -98.39334472
29.66160569 -98.39335506
29.66160569 -98.39336541
29.66160569 -98.39337576
29.66160569 -98.39338611
29.66160569 -98.39339646
29.66160569 -98.39340681
29.66160569 -98.39341716
29.66160569 -98.39342751
29.66160569 -98.39343291
29.66161468 -98.39325157
29.66161468 -98.39326192
29.66161468 -98.39324921
29.66161468 -98.39327227
29.66161468 -98.39328262
29.66161468 -98.39329297
29.66161468 -98.39330332
29.66161468 -98.39331367
29.66161468 -98.39332402
29.66161468 -98.39333437
29.66161468 -98.39334472
29.66161468 -98.39335506
29.66161468 -98.39336541
29.66161468 -98.39337576
29.66161468 -98.39338611
29.66161468 -98.39339646
29.66161468 -98.39340681
29.66161468 -98.39341716
29.66161468 -98.39342751
29.66161468 -98.39342823
29.66161592 -98.39342751
29.66162368 -98.39325157
29.66162368 -98.39326192
29.66162368 -98.39324697
29.66162368 -98.39327227
29.66162368 -98.39328262
29.66162368 -98.39329297
29.66162368 -98.39330332
29.66162368 -98.39331367
29.66162368 -98.39332402
29.66162368 -98.39333437
29.66162368 -98.39334472
29.66162368 -98.39335506
29.66162368 -98.39336541
29.66162368 -98.39337576
29.66162368 -98.39338611
29.66162368 -98.39339646
29.66162368 -98.39340681
29.66162368 -98.39341716
29.66162368 -98.39342302
29.66163267 -98.39325157
29.66163267 -98.39326192
29.66163267 -98.39324642
29.66163267 -98.39327227
29.66163267 -98.39328262
29.66163267 -98.39329297
29.66163267 -98.39330332
29.66163267 -98.39331367
29.66163267 -98.39332402
29.66163267 -98.39333437
29.66163267 -98.39334472
29.66163267 -98.39335506
29.66163267 -98.39336541
29.66163267 -98.39337576
29.66163267 -98.39338611
29.66163267 -98.39339646
29.66163267 -98.39340681
29.66163267 -98.39341716
29.66163267 -98.39341722
29.66163275 -98.39341716
29.66164166 -98.39325157
29.66164166 -98.39326192
29.66164166 -98.39324588
29.66164166 -98.39327227
29.66164166 -98.39328262
29.66164166 -98.39329297
29.66164166 -98.39330332
29.66164166 -98.39331367
29.66164166 -98.39332402
29.66164166 -98.39333437
29.66164166 -98.39334472
29.66164166 -98.39335506
29.66164166 -98.39336541
29.66164166 -98.39337576
29.66164166 -98.39338611
29.66164166 -98.39339646
29.66164166 -98.39340681
29.66164166 -98.39341103
29.66164749 -98.39340681
29.66165066 -98.39325157
29.66165066 -98.39326192
29.66165066 -98.39324533
29.66165066 -98.39327227
29.66165066 -98.39328262
29.66165066 -98.39329297
29.66165066 -98.39330332
29.66165066 -98.39331367
29.66165066 -98.39332402
29.66165066 -98.39333437
29.66165066 -98.39334472
29.66165066 -98.39335506
29.66165066 -98.39336541
29.66165066 -98.39337576
29.66165066 -98.39338611
29.66165066 -98.39339646
29.66165066 -98.39340447
29.66165965 -98.39325157
29.66165965 -98.39326192
29.66165965 -98.39324479
29.66165965 -98.39327227
29.66165965 -98.39328262
29.66165965 -98.39329297
29.66165965 -98.39330332
29.66165965 -98.39331367
29.66165965 -98.39332402
29.66165965 -98.39333437
29.66165965 -98.39334472
29.66165965 -98.39335506
29.66165965 -98.39336541
29.66165965 -98.39337576
29.66165965 -98.39338611
29.66165965 -98.39339646
29.66165965 -98.39339783
29.6616615 -98.39339646
29.66166864 -98.39325157
29.66166864 -98.39326192
29.66166864 -98.39324424
29.66166864 -98.39327227
29.66166864 -98.39328262
29.66166864 -98.39329297
29.66166864 -98.39330332
29.66166864 -98.39331367
29.66166864 -98.39332402
29.66166864 -98.39333437
29.66166864 -98.39334472
29.66166864 -98.39335506
29.66166864 -98.39336541
29.66166864 -98.39337576
29.66166864 -98.39338611
29.66166864 -98.39339119
29.66167552 -98.39338611
29.66167764 -98.39325157
29.66167764 -98.39326192
29.66167764 -98.3932437
29.66167764 -98.39327227
29.66167764 -98.39328262
29.66167764 -98.39329297
29.66167764 -98.39330332
29.66167764 -98.39331367
29.66167764 -98.39332402
29.66167764 -98.39333437
29.66167764 -98.39334472
29.66167764 -98.39335506
29.66167764 -98.39336541
29.66167764 -98.39337576
29.66167764 -98.39338455
29.66168663 -98.39325157
29.66168663 -98.39326192
29.66168663 -98.39324315
29.66168663 -98.39327227
29.66168663 -98.39328262
29.66168663 -98.39329297
29.66168663 -98.39330332
29.66168663 -98.39331367
29.66168663 -98.39332402
29.66168663 -98.39333437
29.66168663 -98.39334472
29.66168663 -98.39335506
29.66168663 -98.39336541
29.66168663 -98.39337576
29.66168663 -98.39337791
29.66168954 -98.39337576
29.66169562 -98.39325157
29.66169562 -98.39326192
29.66169562 -98.39324277
29.66169562 -98.39327227
29.66169562 -98.39328262
29.66169562 -98.39329297
29.66169562 -98.39330332
29.66169562 -98.39331367
29.66169562 -98.39332402
29.66169562 -98.39333437
29.66169562 -98.39334472
29.66169562 -98.39335506
29.66169562 -98.39336541
29.66169562 -98.39337127
29.66170356 -98.39336541
29.66170462 -98.39325157
29.66170462 -98.39326192
29.66170462 -98.39324245
29.66170462 -98.39327227
29.66170462 -98.39328262
29.66170462 -98.39329297
29.66170462 -98.39330332
29.66170462 -98.39331367
29.66170462 -98.39332402
29.66170462 -98.39333437
29.66170462 -98.39334472
29.66170462 -98.39335506
29.66170462 -98.39336463
29.66171361 -98.39325157
29.66171361 -98.39326192
29.66171361 -98.39324213
29.66171361 -98.39327227
29.66171361 -98.39328262
29.66171361 -98.39329297
29.66171361 -98.39330332
29.66171361 -98.39331367
29.66171361 -98.39332402
29.66171361 -98.39333437
29.66171361 -98.39334472
29.66171361 -98.39335506
29.66171361 -98.39335799
29.66171758 -98.39335506
29.6617226 -98.39325157
29.6617226 -98.39326192
29.6617226 -98.393242
29.6617226 -98.39327227
29.6617226 -98.39328262
29.6617226 -98.39329297
29.6617226 -98.39330332
29.6617226 -98.39331367
29.6617226 -98.39332402
29.6617226 -98.39333437
29.6617226 -98.39334472
29.6617226 -98.39335135
29.66173159 -98.39334472
29.6617316 -98.39325157
29.6617316 -98.39326192
29.6617316 -98.393242
29.6617316 -98.39327227
29.6617316 -98.39328262
29.6617316 -98.39329297
29.6617316 -98.39330332
29.6617316 -98.39331367
29.6617316 -98.39332402
29.6617316 -98.39333437
29.6617316 -98.39334471
29.66174059 -98.39325157
29.66174059 -98.39326192
29.66174059 -98.393242
29.66174059 -98.39327227
29.66174059 -98.39328262
29.66174059 -98.39329297
29.66174059 -98.39330332
29.66174059 -98.39331367
29.66174059 -98.39332402
29.66174059 -98.39333437
29.66174059 -98.39333807
29.66174561 -98.39333437
29.66174958 -98.39325157
29.66174958 -98.39326192
29.66174958 -98.39324293
29.66174958 -98.39327227
29.66174958 -98.39328262
29.66174958 -98.39329297
29.66174958 -98.39330332
29.66174958 -98.39331367
29.66174958 -98.39332402
29.66174958 -98.39333143
29.66175858 -98.39325157
29.66175858 -98.39326192
29.66176663 -98.39325157
29.66176757 -98.39326192
29.66175858 -98.39324585
29.66175858 -98.39327227
29.66175858 -98.39328262
29.66175858 -98.39329297
29.66175858 -98.39330332
29.66175858 -98.39331367
29.66175858 -98.39332402
29.66175858 -98.39332427
29.6617589 -98.39332402
29.66176757 -98.39327227
29.66177412 -98.39326192
29.66177656 -98.39327227
29.66176757 -98.3932525
29.66176757 -98.39328262
29.66176757 -98.39329297
29.66176757 -98.39330332
29.66176757 -98.39331367
29.66177543 -98.39330332
29.66176974 -98.39331367
29.66176757 -98.3933162
29.66177656 -98.39328262
29.66177775 -98.39327227
29.66177872 -98.39328262
29.66177656 -98.39326599
29.66177656 -98.39329297
29.66177855 -98.39329297
29.66177656 -98.39330028
In addition, I have a reference point, anchor
另外,我有一个参考点,
anchor
anchor = [29.66165674, -98.39334562]
I want to rescale the latitude and longitude coordinates to a cartesian plane where anchor
is the origin / (0,0)我想将纬度和经度坐标重新缩放到笛卡尔平面,其中
anchor
是原点 / (0,0)
import numpy as np
import utm
latlongs = np.loadtxt('coordinates.txt')
center = utm.from_latlon(center[0], center[1])
latlongs = utm.from_latlon(latlongs[:, 0], latlongs[:, 1])
center_x, center_y = center[0], center[1]
x, y = latlongs[0], latlongs[1]
x -= center_x
y -= center_y
plt.axis('equal')
plt.scatter(x, y, marker='o', color='black')
plt.show()
The output looks as follows:输出如下所示:
Now, I want to rotate the contour.现在,我想旋转轮廓。 I am not sure how this is done.
我不确定这是如何完成的。 But I have two data sources.
但我有两个数据源。 I know that
我知道
trueNorth = 166 # I don't know the definition, only the value
and a compass:和指南针:
How do I calculate the rotation angle or how do I update the long-, latitudes coordinates?如何计算旋转角度或如何更新经纬度坐标?
trueNorth
appears to be the angle of rotation of north with respect to the ascending vertical in the trigonometric direction. trueNorth
似乎是北方相对于三角方向上升垂直的旋转角度。 To apply the rotation you can use a Rotation matrix .要应用旋转,您可以使用Rotation matrix 。 Be careful to convert degrees in radians.
小心以弧度转换度数。
Here is the complete code to do this:这是执行此操作的完整代码:
import matplotlib.pyplot as plt
import numpy as np
import utm
latlongs = np.loadtxt("coordinates.txt")
anchor = [29.66165674, -98.39334562]
center = utm.from_latlon(anchor[0], anchor[1])
latlongs = utm.from_latlon(latlongs[:, 0], latlongs[:, 1])
center_x, center_y = center[0], center[1]
x, y = latlongs[0], latlongs[1]
x -= center_x
y -= center_y
# Rotation
# ========
trueNorth = 166 * np.pi / 180
rot_x = x * np.cos(trueNorth) - y * np.sin(trueNorth)
rot_y = x * np.sin(trueNorth) + y * np.cos(trueNorth)
plt.axis('equal')
plt.scatter(rot_x, rot_y, marker='o', color='black')
plt.show()
The output looks as follows:输出如下所示:
trueNorth = 166 # I don't know the definition, only the value
Judging from that and your compass image you are required to rotate 166 degrees counter-clockwise from normal position.从那和您的指南针图像来看,您需要从正常位置逆时针旋转 166 度。 Rotation matrix provides way to rotate point (x,y) around original point (double zero) counter-clockwise from which following observation could be derived
旋转矩阵提供了围绕原始点(双零)逆时针旋转点(x,y)的方法,从中可以得出以下观察结果
After rotating counter-clockwise point (x,y) by angle a it becomes point with cordinates x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)
将点 (x,y) 逆时针旋转角度 a 后,它变为坐标为 x * cos(a) - y * sin(a), x * sin(a) + y * cos(a) 的点
you should be able to implement above using sin
and cos
functions, either from math
(built-in module) or numpy
, but be watchful to not mistake x and y, especially if you use numpy
convention (y,x) and that mentioned function accept values in radians, not degrees (see radians
function for possible means of conversion).您应该能够使用来自
math
(内置模块)或numpy
的sin
和cos
函数来实现上述功能,但请注意不要弄错 x 和 y,特别是如果您使用numpy
约定 (y,x) 和提到的函数接受弧度值,而不是度数(请参阅radians
函数了解可能的转换方式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.