在 iPhone 上使用 SQLite 数据库进行空间请求

发布于 2024-10-10 18:12:30 字数 296 浏览 6 评论 0原文

我想通过使用本地存储的空间数据来开发使用地理定位的 iPhone 应用程序。

这种应用程序的棘手部分是对“我想要我周围的 x 个最近的点”请求的响应。这是因为数据必须排序,而排序标准是球体上的距离(是的,地球不是平的^^)。所以一个有效的算法是相当复杂的。

空间数据存储在我的应用程序本地(因此使用 sqlLite),因此我无法使用 MyGis 或 PostGis 等库。在SqlLite上我看到了“SpatiaLite”,但似乎与iPhone一起使用不太方便。

有人知道可以轻松完成此任务的库吗?...或者执行此任务的便捷方法?

I want to develop an iPhone application using geolocation by using locally stored spatial data.

The tricky part of such an application is the response to the request "I want the x nearest points around me". This because the data have to be ordered, and the ordering criteria is the distance on a sphere (yes earth is not flat ^^). So an efficient algorithm is quite complex.

Spatial data are stored locally on my application (hence the use of sqlLite) so I can not use libs such as MyGis or PostGis. On SqlLite I saw "SpatiaLite" but it seems that it is not very convenient to use with iPhone.

Anyone know an library to do that easily ?... or a convenient way to perform this task ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2024-10-17 18:12:30

在 SQL 查询中,您需要计算给定点和每个存储点之间的距离,按该值对结果进行排序并返回前 x 行。

您没有说明有多少个数据点,或者它们的分散程度 - 如果这是一个大型数据集,那么这种方法将会很昂贵,您将需要在计算之前了解如何识别可能的点子集的方法所有距离和/或缓存/预计算技术,以防止您一遍又一遍地为同一位置的用户计算相同的信息。因为您实际上将在每个数据行上运行一个函数,所以不能使用索引。

关于如何计算两点之间的距离有很多很好的参考,例如:

http://www.mathopenref .com/coorddist.html

除非数据对精度特别敏感,否则地球的球形性质不会对距离产生太大影响,但如果是这样,还有其他因素(例如海拔变化)会影响距离。对实际距离也有影响。

In your SQL query, you need to calculate the distance between your given point and each stored point, order the results by that value and return the first x rows.

You don't state how many data points there are, or how dispersed they are - if this is a large data set then this approach will be expensive and you will want to look at ways of how to identify a likely subset of points before calculating all the distances, and/or a caching/pre-calculation technique to prevent you calculating the same information for a user in the same place over and over. Because you will essentially be running a function on every data row, indexes can't be used.

There are lots of good references on how to calulate the distance between two points, eg:

http://www.mathopenref.com/coorddist.html

The spherical nature of the earth won't have much impact on the distances unless the data is particularly sensitive to precision, but if it is, there are other factors such as change in altitude that will also have an effect on real distances.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文