# Determining if two locations are duplicate

I'm working on an app that will display drugstores in a map. I have a table that has all drugstores, each with its Lat/Lon.

We used several different sources to add the data to the table: the Walgreens location app, Waze, Google Maps, among others. Naturally, one location can be in all three sources, so there are many duplicates.

The problem is that one specific location may be in Waze and the Walgreens app, but they both have slightly different coordinates.

How do I determine if two sets of coordinates are for the same location? Is there a "difference" I can calculate and then determine if they're different locations?

• You may find that there's more than one kind of distance involved. What if one facility is called "Bob's Hardware" in one database, and "Bob's True Value" in another, and "Anytown True Value" in a third? What if there really are two Starbucks on either side of a busy intersection? Working with crowd-sourced data means spelling errors, positioning errors, and phantom features. Commented Dec 13, 2019 at 11:43

You could apply a clustering algorithm to regroup points, such as `ST_ClusterDBSCAN`. You could either use only the geometries (if your dataset is sparse) or you could break down by name (or other attributes). You might want not to use exact name match but rather string similarity (ex: via pg_trm).
Let's note that this clustering algorithm will regroup geometries that are within a given distance of any feature already in the cluster. It is better than using only the distance. For example, if you acceptable distance is 5 meters and there are 3 points that are linearly located 4 meters away from the previous point (`X----X----X`), then the clustering algorithm will regroup the 3 points while considering only the distance would remove the central point and leave the 2 other ones.