-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeoQuery.py
More file actions
35 lines (28 loc) · 1.45 KB
/
GeoQuery.py
File metadata and controls
35 lines (28 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
__author__ = 'junpan'
from pymongo import MongoClient, GEO2D, ASCENDING, DESCENDING
if __name__ == "__main__":
#connect mongo server
client = MongoClient('localhost', 27017)
#connect to yelpdb
db = client['yelpdb']
#get business collection
business_collection = db['business']
cluster_collection = db['cluster']
#make sure city and state fields are indexed
business_collection.ensure_index([("city", ASCENDING)])
business_collection.ensure_index([("state", ASCENDING)])
# business_collection.ensure_index([("ClusterBearBy", ASCENDING)])
business_collection.ensure_index([("city",ASCENDING),("categories", ASCENDING)])
business_collection.ensure_index([("loc", GEO2D)])
#Total business
food_Trucks = business_collection.find({"city": {"$in":["Phoenix","Glendale","Scottsdale","Tempe","Mesa","Gilbert","Chandler"]},"categories": {"$in": ["Food Trucks","Street Vendors", "Food Stands", "Caterers","Delis"]}})
print food_Trucks.count()
# business_collection.update({}, {"$unset": {"ClusterNearBy":""}},upsert=True,multi=True)
count = 0
for food_Truck in food_Trucks:
loc = food_Truck['loc'];
nearby_business = business_collection.find({"loc": {"$within": {"$center": [loc, 0.015]}}})
# print nearby_business.count()
for business in nearby_business:
business_collection.update({'_id': business['_id']}, {'$push': {"ClusterNearBy":count}})
count +=1