Example #1
0
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
Example #2
0
    async def _send_weather_webhook(self, s2cellId, weatherId, severe, warn, day, time):
        if self.__application_args.weather_webhook:
            log.debug("Send Weather Webhook")

            cell = Cell(CellId(s2cellId))
            coords = []
            for v in range(0, 4):
                vertex = LatLng.from_point(cell.get_vertex(v))
                coords.append([vertex.lat().degrees, vertex.lng().degrees])

            data = weather_webhook_payload.format(s2cellId, coords, weatherId, severe, warn, day, time)

            log.debug(data)
            payload = json.loads(data)
            log.info("Sending weather webhook: %s" % str(payload))
            try:
                response = requests.post(
                    self.__application_args.webhook_url, data=json.dumps(payload),
                    headers={'Content-Type': 'application/json'},
                    timeout=5
                )
                if response.status_code != 200:
                    log.warning("Go status code other than 200 OK from webhook destination: %s" % str(response.status_code))
                else:
                    log.info("Success sending webhook")
            except Exception as e:
                log.warning("Exception occured while sending webhook: %s" % str(e))
        else:
            log.debug("Weather Webhook Disabled")
Example #3
0
def get_border_cell(s2_id):
    locs = []
    s2_cell = Cell(s2_id)
    for i in [0, 1]:
        for j in [0, 1]:
            locs.append([s2_cell.get_latitude(i, j) * 180 / pi, s2_cell.get_longitude(i, j) * 180 / pi])
    output = [locs[0], locs[1], locs[3], locs[2], locs[0]]
    return output
Example #4
0
def get_border_cell(s2_id):
    locs = []
    s2_cell = Cell(s2_id)
    for i in [0, 1]:
        for j in [0, 1]:
            locs.append([
                s2_cell.get_latitude(i, j) * 180 / pi,
                s2_cell.get_longitude(i, j) * 180 / pi
            ])
    output = [locs[0], locs[1], locs[3], locs[2], locs[0]]
    return output
Example #5
0
def bounds(cell_id):
    cell = Cell(cell_id)

    url_string = 'http://maps.googleapis.com/maps/api/staticmap?size=400x400&path='

    coords = []
    for i in range(4) + [0]:
        point = cell.get_vertex(i)
        coords.append("{},{}".format(LatLng.latitude(point).degrees, LatLng.longitude(point).degrees))

    url_string += "|".join(coords)
    print url_string
Example #6
0
    def locate_step(self, location):
        (lat, lon) = location
        origin = LatLng.from_degrees(lat, lon)
        parent = CellId.from_lat_lng(origin).parent(15)
        h = self.niantic.heartbit(location)
        hs = [h]

        for child in parent.children():
            latlng = LatLng.from_point(Cell(child).get_center())
            child_location = (latlng.lat().degrees, latlng.lng().degrees)
            hs.append(self.niantic.heartbit(child_location))

        visible = self.__parse_pokemons(hs)

        current_time_ms = int(round(time.time() * 1000))
        for poke in visible.values():
            pokeid = str(poke.pokemon.PokemonId)
            pokename = POKEMON_NAMES[pokeid]
            expires = poke.LastModifiedMs + poke.TimeTillHiddenMs

            self.data.pokemons[poke.SpawnPointId] = {
                "lat": poke.Latitude,
                "lng": poke.Longitude,
                "expires": expires,
                'expiresAfter': (expires - current_time_ms) / 1000,
                "id": poke.pokemon.PokemonId,
                "name": pokename
            }
        logger.debug('-- step {} {}: found {} pokemons, {} pokestops, {} gyms'.format(
            lat, lon,
            len(self.data.pokemons), len(self.data.pokestops), len(self.data.gyms)))
Example #7
0
    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("")
Example #8
0
    def cover_cell(self, cid):
        lats = []
        lngs = []
        output = []
        s2_cell = Cell(cid)
        lvl = s2_cell.level()
        for i in [0, 1]:
            for j in [0, 1]:
                lats.append(s2_cell.get_latitude(i, j)/pi*180)
                lngs.append(s2_cell.get_longitude(i, j)/pi*180)
        locations = self.cover_region((min(lats),min(lngs)),(max(lats),max(lngs)))
        for location in locations:
            testid = CellId.from_lat_lng(LatLng.from_degrees(location[0],location[1])).parent(lvl)
            if testid == cid:
                output.append(location)

        return output
Example #9
0
def assign_class_index(cell: s2.Cell, mapping: dict) -> Union[int, None]:

    for l in range(2, 30):
        cell_parent = cell.id().parent(l)
        hexid = cell_parent.to_token()
        if hexid in mapping:
            return int(mapping[hexid])  # class index

    return None  # valid return since not all regions are covered
Example #10
0
def get_cell_edges(cellid):
    
    cell = Cell(cellid)
    cell_edges = []
    
    for i in range(4):
        cell_edges.append(get_cell_edge(cell,i))
    
    return cell_edges
Example #11
0
 def get_cellid_center_coordinate(self, cellid):
     """
     get one cell's center point's coordinate [longitude, latitude]
     :param cellid: lnglat_to_cellid生成的cellid
     :return:tuple(center_longitude, center_latitude)
     """
     center = Cell(cell_id=CellId(cellid)).get_center()
     return (LatLng.longitude(center).degrees,
             LatLng.latitude(center).degrees)
Example #12
0
    def cover_cell(self, cid):
        lats = []
        lngs = []
        output = []
        s2_cell = Cell(cid)
        lvl = s2_cell.level()
        for i in [0, 1]:
            for j in [0, 1]:
                lats.append(s2_cell.get_latitude(i, j) / pi * 180)
                lngs.append(s2_cell.get_longitude(i, j) / pi * 180)
        locations = self.cover_region((min(lats), min(lngs)),
                                      (max(lats), max(lngs)))
        for location in locations:
            testid = CellId.from_lat_lng(
                LatLng.from_degrees(location[0], location[1])).parent(lvl)
            if testid == cid:
                output.append(location)

        return output
Example #13
0
    async def _send_weather_webhook(self, s2cellId, weatherId, severe, warn,
                                    day, time):
        if self.__application_args.weather_webhook:
            log.debug("Send Weather Webhook")

            cell = Cell(CellId(s2cellId))
            coords = []
            for v in range(0, 4):
                vertex = LatLng.from_point(cell.get_vertex(v))
                coords.append([vertex.lat().degrees, vertex.lng().degrees])

            data = weather_webhook_payload.format(s2cellId, coords, weatherId,
                                                  severe, warn, day, time)

            log.debug(data)
            payload = json.loads(data)
            self.__sendToWebhook(payload)
        else:
            log.debug("Weather Webhook Disabled")
Example #14
0
def send_weather_webhook(s2cellId, weatherId, severe, warn, day, time):
    if args.weather_webhook:
        log.debug("Send Weather Webhook")

        cell = Cell(CellId(s2cellId))
        coords = []
        for v in range(0, 4):
            vertex = LatLng.from_point(cell.get_vertex(v))
            coords.append([vertex.lat().degrees, vertex.lng().degrees])

        data = weather_webhook_payload.format(s2cellId, coords, weatherId,
                                              severe, warn, day, time)

        log.debug(data)
        payload = json.loads(data)
        response = requests.post(args.webhook_url,
                                 data=json.dumps(payload),
                                 headers={'Content-Type': 'application/json'})
    else:
        log.debug("Weather Webhook Disabled")
Example #15
0
 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], []))
Example #16
0
    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]
Example #17
0
 def generateGeohash(self, geoPoint: 'GeoPoint'):
     latLng = S2LatLng.from_degrees(
         geoPoint.getLatitude(), geoPoint.getLongitude())
     cell = S2Cell.from_lat_lng(latLng)
     cellId = cell.id()
     return cellId.id()
Example #18
0
def _token_to_cell(s2_address):
    return Cell(CellId.from_token(s2_address))
 def calc_s2id(lat, lng, level):
     s2id = Cell.from_lat_lng(LatLng(lat, lng)).id().parent(level).id()
     return f"{s2id:016x}"