in reply to Sort by distance

Hi, it might be a little of an overkill for your needs, but consider using PostGIS for your most complicated geographical vector analyses. Having your data points in a PostgreSQL database and accessing it with DBI is a great idea. I use it almost on a daily basis.