足迹的纬度/经度的 Python 排序字典
我正在计算椭圆体表面上的卫星覆盖足迹,我的函数返回如下所示的纬度/经度列表。它是一个Python 字典列表。现在,如果我在 Matlab 或 Matplotlib 中散点图,我会得到一个由断开点组成的漂亮 3D 足迹。但是,我希望能够使用绘图(而不是散点)命令创建一个平滑的 3D 圆来表示足迹。为了做到这一点,我需要以某种方式对它们进行排序。我尝试过半正弦(最大圆距离)来找到每个点的最近邻居,但是当我有更大的值集(GEO sats)时,这仍然偶尔会出现断开的线。当足迹跨越赤道时,我还尝试将这些值拆分为 N 纬度和 S 纬度,然后按经度排序。我可能错过了一些东西 - 有没有人有更好/更快的想法来对这样的列表进行排序,以便如果我连接列表中的所有连续点,我会得到一个完整的、有序的圆圈?
latLons = [{'lat': -33.783781327, 'lon': 137.47747747700001}, {'lat': -33.783781326899998, 'lon': 139.63963964000001}, {'lat': -33.603601166200001, 'lon': 136.03603603600001}, {'lat': -33.423421005500003, 'lon': 134.59459459499999}, {'lat': -32.882880523399997, 'lon': 132.43243243200001}, {'lat': -32.522520202199999, 'lon': 131.71171171200001}, {'lat': -32.342340041600004, 'lon': 145.40540540500001}, {'lat': -31.261259078399998, 'lon': 147.56756756799999}, {'lat': -31.081078917799999, 'lon': 128.828828829}, {'lat': -29.459457473099999, 'lon': 126.666666667}, {'lat': -28.558556670200002, 'lon': 125.94594594599999}, {'lat': -27.657655866700001, 'lon': 125.225225225}, {'lat': -26.936935223300001, 'lon': 151.89189189199999}, {'lat': -26.7567550624, 'lon': 124.504504504}, {'lat': -25.6756740961, 'lon': 152.61261261300001}, {'lat': -25.3153137736, 'lon': 123.78378378399999}, {'lat': -23.873872481599999, 'lon': 153.33333333300001}, {'lat': -23.333331995999998, 'lon': 123.063063063}, {'lat': -19.3693684138, 'lon': 154.05405405400001}, {'lat': -15.765765115600001, 'lon': 123.063063063}, {'lat': -15.2252246167, 'lon': 153.33333333300001}, {'lat': -13.243242777300001, 'lon': 152.61261261300001}, {'lat': -12.162161767000001, 'lon': 124.504504505}, {'lat': -11.801801428999999, 'lon': 151.89189189199999}, {'lat': -10.9009005815, 'lon': 125.225225225}, {'lat': -8.1981980155999992, 'lon': 149.00900900900001}, {'lat': -6.9369368056800003, 'lon': 147.56756756799999}, {'lat': -6.5765764584799999, 'lon': 129.54954954999999}, {'lat': -6.5765764584799999, 'lon': 146.84684684699999}, {'lat': -5.6756755875199998, 'lon': 130.99099099099999}, {'lat': -4.7747747122700002, 'lon': 143.24324324299999}, {'lat': -4.23423418502, 'lon': 141.08108108100001}, {'lat': -3.8738738326600002, 'lon': 138.198198198}]
I am calculating satellite coverage footprints on the surface of an ellipsoid and my function returns a list of Lat / Lons that looks like below. It is a python list of dictionaries. Now if I scatter plot this in Matlab or Matplotlib I get a nice 3D footprint of disconnected points.. However, I want to be able to use the plot (not scatter) command to create a smooth 3D circle to represent the footprint. In order to do this I need to sort them somehow. I've tried Haversine (greatest circle distance) to find the nearest neighbor for each point but this still gives me the occasional disconnected line when I have a larger set of values (GEO sats). I've also attempted to split the values into N and S latitudes when the footprint straddles the equator, and then sort by longitude. I'm probably missing something - Does anyone have a better/faster idea to sort a list like this so that if I connect all sequential points in the list I would get a complete, ordered, circle?
latLons = [{'lat': -33.783781327, 'lon': 137.47747747700001}, {'lat': -33.783781326899998, 'lon': 139.63963964000001}, {'lat': -33.603601166200001, 'lon': 136.03603603600001}, {'lat': -33.423421005500003, 'lon': 134.59459459499999}, {'lat': -32.882880523399997, 'lon': 132.43243243200001}, {'lat': -32.522520202199999, 'lon': 131.71171171200001}, {'lat': -32.342340041600004, 'lon': 145.40540540500001}, {'lat': -31.261259078399998, 'lon': 147.56756756799999}, {'lat': -31.081078917799999, 'lon': 128.828828829}, {'lat': -29.459457473099999, 'lon': 126.666666667}, {'lat': -28.558556670200002, 'lon': 125.94594594599999}, {'lat': -27.657655866700001, 'lon': 125.225225225}, {'lat': -26.936935223300001, 'lon': 151.89189189199999}, {'lat': -26.7567550624, 'lon': 124.504504504}, {'lat': -25.6756740961, 'lon': 152.61261261300001}, {'lat': -25.3153137736, 'lon': 123.78378378399999}, {'lat': -23.873872481599999, 'lon': 153.33333333300001}, {'lat': -23.333331995999998, 'lon': 123.063063063}, {'lat': -19.3693684138, 'lon': 154.05405405400001}, {'lat': -15.765765115600001, 'lon': 123.063063063}, {'lat': -15.2252246167, 'lon': 153.33333333300001}, {'lat': -13.243242777300001, 'lon': 152.61261261300001}, {'lat': -12.162161767000001, 'lon': 124.504504505}, {'lat': -11.801801428999999, 'lon': 151.89189189199999}, {'lat': -10.9009005815, 'lon': 125.225225225}, {'lat': -8.1981980155999992, 'lon': 149.00900900900001}, {'lat': -6.9369368056800003, 'lon': 147.56756756799999}, {'lat': -6.5765764584799999, 'lon': 129.54954954999999}, {'lat': -6.5765764584799999, 'lon': 146.84684684699999}, {'lat': -5.6756755875199998, 'lon': 130.99099099099999}, {'lat': -4.7747747122700002, 'lon': 143.24324324299999}, {'lat': -4.23423418502, 'lon': 141.08108108100001}, {'lat': -3.8738738326600002, 'lon': 138.198198198}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是用相对于中心点的极坐标表示您的点,并使用角度作为排序键。
这是一个简单的实现:
One approach would be representing your points in polar coordinates with respect to the center point and using the angle as the sorting key.
Here is a simple implementation:
我认为常规排序不是您所需要的。在常规排序中,您在项目之间使用绝对顺序。这里没有绝对顺序(“第一个”坐标是什么?),只有相对顺序。
首先,我将从字典中获取数据并放入元组列表中:
然后
import scipy.spatial
并使用 距离 您选择的用于查找每个的最近邻居 观点。当然,您也可以使用欧几里德距离,而无需求助于 scipy。使用如下方法计算所有可能的距离(应为 n^2 操作):
然后从任意节点开始遍历节点列表,在每一步中查找最近的节点。
I don't think a regular sort is what you need. In a regular sort you use an absolute order between items. Here you don't have an absolute order (what's the "first" coordinate?), only a relative one.
First I'd get the data out of dictionaries and into a list of tuples:
Then
import scipy.spatial
and use a distance of your choice for finding the nearest neighbour to each point. You can also use euclidean distance without resorting to scipy, of course.Compute all possible distances (should be
n^2
ops) with something like this:Then walk the node list starting from an arbitrary node, looking for the nearest node in each step.