存储 3 个最近的坐标
我有一个 XML 文件,其中包含许多点及其经度和纬度。
目前,我的 python 代码只需循环遍历 XML 文件,找到最近的点(以英里为单位),然后将其与之前的最近点进行比较,即可获得最近的点。如果它更接近,那么我将这个新点的值分配给变量。所以这方面一切都在进行。
现在,我想做的实际上是存储最近的 2 或 3 个点。 我该怎么做呢? XML 文件不是按最接近的顺序排序的,此外,每次发出请求时,用户位置都会发生变化。我可以使用 XML 文件来执行此操作吗?还是我可能需要考虑将数据存储在 SQL Server 或 MySQL 中?
感谢您的帮助。 PS,如果有人感兴趣,可以在此处获取示例代码。这是大学项目的一部分。
I have an XML file that contains a number of points with their longitude and latitude.
My python code at the moment gets the nearest point by simply looping through the XML file, finding the nearest, in miles or whatever, then comparing it with the previous closest point. If its nearer then I assign the variable the value of this new point. So everything is working in that regard.
Now, what I want to do is actually store the closest 2 or 3 points.
How do I go about doing this? The XML file isn't ordered by closest, and besides, the users location will change each time a request is made. Can I do this with an XML file or will I perhaps have to look into storing the data is SQL Server or MySQL?
Thanks for the help.
PS, the sample code is available here if anyone is interested. This is part of a college project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在解析 xml 文件时,您应该将所有点对及其距离存储在元组列表中(例如)。
将此调整为您的代码:
You should store in a list of tuples (for example) all the point pairs and their distances as you parse de xml file.
Adapting this to your code:
这是一个适用于任意数量点的解决方案:
显然,有点伪代码。
sort()
调用可能需要一个参数,以便以有用的方式对它们进行排序,并且您可能需要一个函数来计算距离来替换distance
成员。Here's a solution that will work for any number of points:
Obviously, a bit pseudo-cody. The
sort()
calls will probably need an argument so they are sorted in a useful way, and you'll probably want a function to calculate the distance to replace thedistance
member.