Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation queries in PostgreSQL

We are working on a ride sharing service, where we are using PostgreSQL as our database management system to store ride details. We haven't used any special datatypes for storing our latitude and longitude info, but are currently saving them as string objects. In order to improve the performance of our search queries on geolocation data, could we use PostGIS or is there any other location-related support from PostgreSQL? Something to improve the database's performance in a situation like this? (We are using Django btw.)

Our data would look something like this: Ride1 starts from pointA(lat,long) and goes to pointB(lat,long) with routePoints(lat,long)(lat,long)... along the way. We need to perform complex queries on this data, for example:

  1. Who is travelling from pointA1 which is 5% of the total distance from A->B? and
  2. Is there a point in the route points array that coincides with the location of someone else to the user could pick them up?

Thanks for reading through this. Please help me out in choosing the best database architecture for the geolocation querying system described above.

like image 665
Shirish Gone Avatar asked Jun 01 '13 03:06

Shirish Gone


1 Answers

Postgis is an excellent choice if you already have your data stored into Postgres (well, it actually is THE choice).

Postgis has functions that will convert your textual coordinate representation into geometry/geography objects and then others that can be used to perform all sorts of calculations.

Django has a Postgis module, even though I have never used it, so YMMV.

like image 53
unicoletti Avatar answered Oct 13 '22 18:10

unicoletti