iOS: storing large data file with location coordinates for frequent queries

早过忘川 提交于 2020-01-06 02:57:05

问题


I would like to find an optimal way to store a the information from a large data file (up to 1.5 GB) containing location data coordinates. The file contains also additional information on the location such as: location name, location icon.

I need to be able to query the datastructure based on the current user location and retrieve "n" nearest locations (where n is usually a relatively small number, such as 30) to the current user location.

I have read some post suggesting to use a "grid" data structure, which really reflects the current geographical coordinate system (latitiude and longitide).

My current solution would be to initialize a matrix as a location grid where each cell represents a parallel and a meridian. The cell then contains the reference to an array of locations in that specific "area" (defined by the parallel and meridian).

In datatype terms: one NSArray is initialized as the maximum number of meridians and the other one as the maximum number of parallels. Then every cell will contain a NSMutableArray of all the locations in that specific cell (e.g. latitude 50.-, longitude 0.-). From here I will have a list of all locations in that cell and I can retrieve data such as the nearest location from the current user location.

Does this datastructure sound sensible to you or is there a "state of the art" approach or library for doing this?

The downside of this solution is that in case most of the file's location are in a certain geographical area the datastructure, as defined, would have areas (cells) with a high intensity of locations and areas with a lower intensity. Hence my gut instinct I need some sort of datastructure that dynamically balances itself.

Any suggestions?


回答1:


I'm copy pasting my answer from another question which basically asks for the same thing:

Have a look at m-tree. There are also many other spacial indexes: http://en.wikipedia.org/wiki/Spatial_database Initially, you construct the data structure (the index) and later just perform a range query.

From the wiki page for m-trees:

For a given query object Q ∈ D and a maximum search distance r(Q), the range query range(Q, r(Q)) selects all the indexed objects Oj such that d(Oj, Q) ≤ r(Q).[2] The wikipedia page for the m-tree also has the algorithm for range queries.

You can perform range queries in sub linear time. Also this works only if the distance measure you are using obeys trianlge inequality. If haversine (I have never head of it before), obeys triangle inequality, this should work for you.



来源:https://stackoverflow.com/questions/23606820/ios-storing-large-data-file-with-location-coordinates-for-frequent-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!