-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlbs_buy.py
executable file
·47 lines (39 loc) · 1.27 KB
/
lbs_buy.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
from conf_examples import get_tair
from tair import ResponseError
# Add a service store geographical scope.
# @param key the key
# @param storeName the store name
# @param storeWkt the store wkt
# @return success: true, fail: false
def add_polygon(key: str, store_name: str, store_wkt) -> bool:
try:
tair = get_tair()
ret = tair.gis_add(key, {store_name: store_wkt})
return ret == 1
except ResponseError as e:
print(e)
return False
# Determine whether the user's location is within the service range of the store.
# @param key the key
# @param userLocation the user location
# @return Stores that can serve users
def get_service_store(key: str, user_location: str):
try:
tair = get_tair()
return tair.gis_contains(key, user_location)
except:
return None
if __name__ == "__main__":
key = "LbsBuy"
add_polygon(
key,
"store-1",
"POLYGON ((120.058897 30.283681, 120.093033 30.286363, 120.097632 30.269147, 120.050705 30.252863))",
)
add_polygon(
key,
"store-2",
"POLYGON ((120.026343 30.285739, 120.029289 30.280749, 120.0382 30.281997, 120.037051 30.288109))",
)
print(get_service_store(key, "POINT(120.072264 30.27501)"))