简体   繁体   English

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

[英]Spatial request using SQLite database on iPhone

I want to develop an iPhone application using geolocation by using locally stored spatial data. 我想通过使用本地存储的空间数据使用地理位置来开发iPhone应用程序。

The tricky part of such an application is the response to the request "I want the x nearest points around me". 这种应用程序的棘手部分是对请求“我希望我周围有x个最近的点”的响应。 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. 空间数据存储在我的应用程序本地(因此使用sqlLite),因此我不能使用MyGis或PostGis之类的库。 On SqlLite I saw "SpatiaLite" but it seems that it is not very convenient to use with iPhone. 在SqlLite上,我看到了“ SpatiaLite”,但似乎与iPhone配合使用不是很方便。

Anyone know an library to do that easily ?... or a convenient way to perform this task ? 有谁知道图书馆可以轻松地做到这一点?...或执行此任务的便捷方法?

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. 在SQL查询中,您需要计算给定点与每个存储点之间的距离,并根据该值对结果进行排序并返回前x行。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM