私は、Google Places API とやり取りして、米国郡内の特定のタイプの施設をすべて識別するプログラムを構築しています。Google は半径の形で検索を受け入れます。そのため、エリア全体をカバーするために、検索半径を順次構築しています。ただし、このアルゴリズムは、フィルターで除外したい重複する円を多数作成します。そう:
それぞれの中心と半径を含む円のリストが与えられた場合、単一の円が他の円の組み合わせによって完全に覆われているかどうかをどのように判断できますか?
円が別の単一の円に囲まれているかどうかは、すでにわかります。私の問題は、それらの多くが他のいくつかの円の組み合わせによって囲まれていることです。
誰かが私の既存のコードを求めました - 私が現在持っているコードは、円が別の円と完全に重なっているかどうかをテストします - それらの組み合わせではありません。しかし、ここに私が持っているものがあります。他の 20 個の円と重複する場合は除外することで、現在の問題を概算していることがわかります。その時点で、おそらく包含されています。
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