[GIS] Spatial databases in location based search

algorithmgeolocationMySQLPHPselect-by-location

I'm developing a location based application in which i was in the plan of dividing the globe into grids and when the client requests information, will create a table or similar data model which will expire in 5 mins and serving the same data for the clients within the same grid within that period. Which i explained in the following StackOverflow question.

https://stackoverflow.com/questions/19667637/caching-location-based-data-cluster

But i come across the term spatial databases today and now i like to know how it differs from the traditional model when searching from the databases of million records especially in terms of speed? Will it really speed up data retrieval of location based data? If so, can you explain how?

Problem: The problem is, i was in the idea of using traditional database, but if i use traditional DB and if i have more than a million records, when we execute each search query it needs to search through the the database of million records, so i planned to,

  1. Divide the globe by some sort of grid each of around 1 sq.km and when we showed all the values from that grid,then the next nearby grid and so on which i need to save in some buffer.
  2. And when someone request the data from the same grid in the next 5 mins, i don't want to search the entire DB again, and i need to give the values from the buffer and not querying the entire DB again.

Here the main problem is, buffering the data and retrieval from it to speed up the process and minimizing the server load. So i like to know that this spatial DB simplify these process in any way? Or is there any DB already available which provides any grid system like this?

@ike: What i meant as speed is the performance, i.e., the number of rows returned against the number of rows on which the query runs on(may be the entire table of few million records). I'm trying to find some way to reduce the number of rows(or the entire table) on which the query runs

Best Answer

How do spatial algorithms help?

There are many ways spatially based algorithms can improve upon traditional algorithms. Often, you can use spatial algorithms to drastically lower the amount of records you have to loop through, such as when using distance in your calculation.

Give me an example!

Let's use this question that was asked today as an example. The question asker wants to find the nearest location to certain points. He knows that there will always be at least one location within some distance, so instead of looping through every single record and getting the distance between the two, he creates a circular buffer around his target point so that he only loops through the locations within the buffer (he doesn't care about the other ones, he only wants the point with the smallest distance, so anything outside the buffer obviously couldn't be the nearest location).

The end result is that he speeds up his program significantly from implementing a spatial algorithm. This is a simple example of how to use spatial location to improve upon algorithms that are related to distance and location. However, as Ike noted in comments above, oftentimes the answer is not so simple.

Related Question