本文整理汇总了Python中s2sphere.LatLng.from_point方法的典型用法代码示例。如果您正苦于以下问题:Python LatLng.from_point方法的具体用法?Python LatLng.from_point怎么用?Python LatLng.from_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类s2sphere.LatLng
的用法示例。
在下文中一共展示了LatLng.from_point方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def main():
origin_lat_i, origin_lng_i = f2i(origin_lat), f2i(origin_lng)
api_endpoint, access_token, profile_response = login(origin_lat_i, origin_lng_i)
with sqlite3.connect('database.db') as db:
create_tables(db)
while True:
pos = 1
x = 0
y = 0
dx = 0
dy = -1
steplimit2 = steplimit**2
for step in range(steplimit2):
#print('looping: step {} of {}'.format(step + 1, steplimit**2))
# Scan location math
if -steplimit2 / 2 < x <= steplimit2 / 2 and -steplimit2 / 2 < y <= steplimit2 / 2:
step_lat = x * 0.0025 + origin_lat
step_lng = y * 0.0025 + origin_lng
step_lat_i = f2i(step_lat)
step_lng_i = f2i(step_lng)
if x == y or x < 0 and x == -y or x > 0 and x == 1 - y:
(dx, dy) = (-dy, dx)
(x, y) = (x + dx, y + dy)
#print('[+] Searching for Pokemon at location {} {}'.format(step_lat, step_lng))
origin = LatLng.from_degrees(step_lat, step_lng)
parent = CellId.from_lat_lng(origin).parent(15)
h = get_heartbeat(api_endpoint, access_token, profile_response, step_lat, step_lng, step_lat_i, step_lng_i)
hs = [h]
for child in parent.children():
latlng = LatLng.from_point(Cell(child).get_center())
child_lat, child_lng = latlng.lat().degrees, latlng.lng().degrees
child_lat_i, child_lng_i = f2i(child_lat), f2i(child_lng)
hs.append(get_heartbeat(api_endpoint, access_token, profile_response, child_lat, child_lng, child_lat_i, child_lng_i))
visible = []
data = []
for hh in hs:
for cell in hh.cells:
for poke in cell.WildPokemon:
disappear_ms = cell.AsOfTimeMs + poke.TimeTillHiddenMs
data.append((
poke.SpawnPointId,
poke.pokemon.PokemonId,
poke.Latitude,
poke.Longitude,
disappear_ms,
))
if data:
print('Upserting {} pokemon'.format(len(data)))
with sqlite3.connect('database.db') as db:
insert_data(db, data)
示例2: add_plan
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def add_plan():
location = (request.args.get('lat', type=float),request.args.get('lng', type=float))
all_loc,border,cid = mapl.get_area_cell(location,True)
# grid = mapl.Hexgrid()
# all_loc = grid.cover_cell(cid)
center = LatLng.from_point(Cell(cid).get_center())
center = (center.lat().degrees, center.lng().degrees)
token = cid.to_token()
lock_plans.acquire()
list_plans.append(token)
lock_plans.release()
return jsonify((all_loc, border,[center,token],[]))
示例3: neighbor_s2_circle
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def neighbor_s2_circle(location, i_dir=0.0, j_dir=0.0): # input location can be list, tuple or Point
if type(location) in (list, tuple):
ll_location = LatLng.from_degrees(location[0], location[1])
elif type(location) is Point:
ll_location = LatLng.from_point(location)
elif type(location) is LatLng:
ll_location = location
else:
return None
cid_large = CellId.from_lat_lng(ll_location).parent(lvl_big)
cid_small = cid_large.child_begin(lvl_small)
vec_to_j = (Cell(ij_offs(cid_small, 0, 1)).get_center() - Cell(cid_small).get_center()).normalize()
vec_to_i = (Cell(ij_offs(cid_small, 1, 0)).get_center() - Cell(cid_small).get_center()).normalize()
vec_newlocation = ll_location.to_point() + safety * HEX_R / earth_Rrect * (i_dir * 3 ** 0.5 * vec_to_i + j_dir * 1.5 * vec_to_j)
return vec_newlocation # output is Point
示例4: get_meta_cell
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def get_meta_cell(self):
location = self.position[0:2]
cells = self.find_close_cells(*location)
# Combine all cells into a single dict of the items we care about.
forts = []
wild_pokemons = []
catchable_pokemons = []
nearby_pokemons = []
for cell in cells:
if "forts" in cell and len(cell["forts"]):
forts += cell["forts"]
if "wild_pokemons" in cell and len(cell["wild_pokemons"]):
wild_pokemons += cell["wild_pokemons"]
if "catchable_pokemons" in cell and len(cell["catchable_pokemons"]):
catchable_pokemons += cell["catchable_pokemons"]
if "nearby_pokemons" in cell and len(cell["nearby_pokemons"]):
latlng = LatLng.from_point(Cell(CellId(cell["s2_cell_id"])).get_center())
for p in cell["nearby_pokemons"]:
p["latitude"] = latlng.lat().degrees
p["longitude"] = latlng.lng().degrees
p["s2_cell_id"] = cell["s2_cell_id"]
nearby_pokemons += cell["nearby_pokemons"]
# If there are forts present in the cells sent from the server or we don't yet have any cell data, return all data retrieved
if len(forts) > 1 or not self.cell:
return {
"forts": forts,
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons,
"nearby_pokemons": nearby_pokemons
}
# If there are no forts present in the data from the server, keep our existing fort data and only update the pokemon cells.
else:
return {
"forts": self.cell["forts"],
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons,
"nearby_pokemons": nearby_pokemons
}
示例5: get_search_points
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def get_search_points(self, cell_id):
points = []
# For cell level 15
for c in Cell(CellId(cell_id)).subdivide():
for cc in c.subdivide():
latlng = LatLng.from_point(cc.get_center())
point = (latlng.lat().degrees, latlng.lng().degrees)
points.append(point)
points[0], points[1] = points[1], points[0]
points[14], points[15] = points[15], points[14]
point = points.pop(2)
points.insert(7, point)
point = points.pop(13)
points.insert(8, point)
closest = min(points, key=lambda p: great_circle(self.bot.position, p).meters)
index = points.index(closest)
return points[index:] + points[:index]
示例6: get_area_cell
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def get_area_cell(location,unfilled=False):
border = []
locs = []
cid_large = CellId.from_lat_lng(LatLng.from_degrees(location[0], location[1])).parent(lvl_big)
border.append(get_border_cell(cid_large))
if unfilled:
return [], border, cid_large
corner = neighbor_s2_circle(LatLng.from_degrees(border[-1][0][0], border[-1][0][1]), safety_border*0.5, safety_border/3.0)
j_maxpoint = LatLng.from_point(neighbor_s2_circle(LatLng.from_degrees(border[-1][1][0], border[-1][1][1]), safety_border*0.5, (1-safety_border)/3.0))
i_maxpoint = LatLng.from_point(neighbor_s2_circle(LatLng.from_degrees(border[-1][3][0], border[-1][3][1]), (1-safety_border)*0.5, safety_border/3.0))
base = corner
p_start = base
dist_j = j_maxpoint.get_distance(LatLng.from_point(p_start))
last_dist_j = None
j = 0
while last_dist_j is None or dist_j < last_dist_j:
dist_i = i_maxpoint.get_distance(LatLng.from_point(p_start))
last_dist_i = None
while last_dist_i is None or dist_i < last_dist_i:
locs.append(LatLng.from_point(p_start))
p_start = neighbor_s2_circle(p_start, 1.0, 0.0)
last_dist_i = dist_i
dist_i = i_maxpoint.get_distance(LatLng.from_point(p_start))
base = neighbor_s2_circle(base, 0.0, 1.0)
last_dist_j = dist_j
dist_j = j_maxpoint.get_distance(LatLng.from_point(base))
if j % 2 == 1:
p_start = base
else:
p_start = neighbor_s2_circle(base, -0.5, 0.0)
j += 1
all_loc = []
for loc in locs:
all_loc.append([loc.lat().degrees, loc.lng().degrees])
return all_loc, border,cid_large
示例7: writeplans
# 需要导入模块: from s2sphere import LatLng [as 别名]
# 或者: from s2sphere.LatLng import from_point [as 别名]
def writeplans():
subplans = request.args.get('subplans', type=int)
plans = []
lock_plans.acquire()
for token in list_plans:
center = LatLng.from_point(Cell(CellId.from_token(token)).get_center())
center = (center.lat().degrees, center.lng().degrees)
for ind_sub in range(1,subplans+1):
plans.append({'type': 'seikur0_s2', 'token': token, 'location': [center[0],center[1]], 'subplans': subplans, 'subplan_index': ind_sub})
lock_plans.release()
for plan in plans:
filename = '{}_{}_{}.plan'.format(plan['token'],plan['subplan_index'],plan['subplans'])
try:
f = open(plandir+'/'+filename, 'w', 0)
json.dump(plan, f, indent=1, separators=(',', ': '))
print('[+] Plan file {} was written.'.format(filename))
except Exception as e:
print('[+] Error while writing plan file, error : {}'.format(e))
finally:
if 'f' in vars() and not f.closed:
f.close()
return jsonify("")