I am building a program that interacts with the Google Places API to identify all establishments of a given type within a U.S. County. Google accepts searches in the form of radiuses - so in order to cover an entire area, I am building my search radiuses out from one another sequentially. However, this algorithm creates a lot of overlapping circles that I would like to filter out. So:
Given a list of circles, with each's center and radius, how can I tell if a single circle is completely covered by any combination of other circles?
I can already tell if a circle is enveloped by another single circle - my problem is that a lot of them are enveloped by a combination of several others.
Someone asked for my existing code - the code I currently have tests if a circle is completely overlapped by another circle - not a combination of them. But here is what I have. You can see that I'm approximating the current problem by ruling it out if it overlaps with 20 other circles, at which point it's probably encompassed:
def radiusIsInsidePreviousQuery(self, testQuery):
newSearchCoordinates = (testQuery['center']['lat'], testQuery['center']['lng'])
alreadyBeenSearched = False
numberOfIntersectingCircles = 0
for queryNumber in self.results.keys():
previousQuery = self.results[queryNumber]
previousSearchCoordinates = (previousQuery['center']['lat'],
previousQuery['center']['lng'])
centroidDistance = VincentyDistance(newSearchCoordinates,
previousSearchCoordinates)
centroidDistanceMeters = centroidDistance.meters
newQueryRadius = testQuery['radius']
fullSearchDistance = centroidDistanceMeters + newQueryRadius
#If the full search distance (the sum of the distance between
#the two searches' centroids and the new search's radius) is less
#than the previous search's radius, then the new search is encompassed
#entirely by the old search.
previousQueryRadius = previousQuery['radius']
if fullSearchDistance <= previousQueryRadius:
print "Search area encompassed"
alreadyBeenSearched = True
elif centroidDistanceMeters < newQueryRadius + previousQueryRadius:
numberOfIntersectingCircles += 1
elif self.queriesAreEqual(testQuery, previousQuery):
print "found duplicate"
alreadyBeenSearched = True
#If it intersects with 20 other circles, it's not doing any more good.
if numberOfIntersectingCircles > 20:
alreadyBeenSearched = True
return alreadyBeenSearched