Exemple #1
0
def cover_region_s2(location1,location2):
    rc = RegionCoverer()
    rc.max_level = lvl_big
    rc.min_level = lvl_big
    rc.max_cells = 1000
    locations = []

    if location1[0] > location2[0]:
        lat1,lat2 = location2[0],location1[0]
    else:
        lat1, lat2 = location1[0], location2[0]


    if location1[1] > location2[1]:
        lng1, lng2 = location2[1], location1[1]
    else:
        lng1, lng2 = location1[1], location2[1]

    lng1 = (lng1 + 180) % 360 - 180
    lng2 = (lng2 + 180) % 360 - 180

    lngs = []
    if lng2 > lng1:
        lngs.append((lng1,lng2))
    elif lng2 < lng1:
        lngs.append((-180.0,lng2))
        lngs.append((lng1,180.0))

    for lng1,lng2 in lngs:
        cids = rc.get_covering(LatLngRect(LatLng.from_degrees(lat1,lng1),LatLng.from_degrees(lat2,lng2)))

        for cid in cids:
            ll_cid = cid.to_lat_lng()
            locations.append((ll_cid.lat().degrees,ll_cid.lng().degrees))
    return locations
Exemple #2
0
def cover_circle(lat, lng, radius, level):
    EARTH_RADIUS = 6371 * 1000
    region = Cap.from_axis_angle(LatLng.from_degrees(lat, lng).to_point(), \
                                 Angle.from_degrees(360*radius/(2*math.pi*EARTH_RADIUS)))
    coverer = RegionCoverer()
    coverer.min_level = level
    coverer.max_level = level
    cells = coverer.get_covering(region)
    return cells
Exemple #3
0
def cover_circle(lat, lng, radius, level=15):
    EARTH = 6371000
    region = Cap.from_axis_angle(\
             LatLng.from_degrees(lat, lng).to_point(), \
             Angle.from_degrees(360*radius/(2*math.pi*EARTH)))
    coverer = RegionCoverer()
    coverer.min_level = level
    coverer.max_level = level
    cells = coverer.get_covering(region)
    return cells
Exemple #4
0
def get_cell_ids(lat, long, radius=1000):
    # Max values allowed by server according to this comment:
    # https://github.com/AeonLucid/POGOProtos/issues/83#issuecomment-235612285
    if radius > 1500:
        radius = 1500  # radius = 1500 is max allowed by the server
    region = Cap.from_axis_angle(LatLng.from_degrees(lat, long).to_point(), Angle.from_degrees(360*radius/(2*math.pi*EARTH_RADIUS)))
    coverer = RegionCoverer()
    coverer.min_level = 15
    coverer.max_level = 15
    cells = coverer.get_covering(region)
    cells = cells[:100]  # len(cells) = 100 is max allowed by the server
    return sorted([x.id() for x in cells])
Exemple #5
0
def get_cell_ids(lat, long, radius=500):
    if radius > 500:
        radius = 500
    region = Cap.from_axis_angle(
        LatLng.from_degrees(lat, long).to_point(),
        Angle.from_degrees(360 * radius / (2 * math.pi * EARTH_RADIUS)))
    coverer = RegionCoverer()
    coverer.min_level = 15
    coverer.max_level = 15
    cells = coverer.get_covering(region)
    cells = cells[:21]
    return sorted([x.id() for x in cells])
Exemple #6
0
def get_cell_ids(lat, long, radius=1000):
    # Max values allowed by server according to this comment:
    # https://github.com/AeonLucid/POGOProtos/issues/83#issuecomment-235612285
    if radius > 1500:
        radius = 1500  # radius = 1500 is max allowed by the server
    region = Cap.from_axis_angle(LatLng.from_degrees(lat, long).to_point(), Angle.from_degrees(360*radius/(2*math.pi*EARTH_RADIUS)))
    coverer = RegionCoverer()
    coverer.min_level = 15
    coverer.max_level = 15
    cells = coverer.get_covering(region)
    cells = cells[:100]  # len(cells) = 100 is max allowed by the server
    return sorted([x.id() for x in cells])
Exemple #7
0
def cover_square(lat, lng, width, level=15):
    offset = int(width / 2)
    g = Geodesic.WGS84  # @UndefinedVariable
    r = RegionCoverer()
    r.min_level, r.min_level = level, level
    g1 = g.Direct(lat, lng, 360, offset)
    g1 = g.Direct(g1['lat2'], g1['lon2'], 270, offset)
    p1 = LatLng.from_degrees(g1['lat2'], g1['lon2'])
    g2 = g.Direct(lat, lng, 180, offset)
    g2 = g.Direct(g2['lat2'], g2['lon2'], 90, offset)
    p2 = LatLng.from_degrees(g2['lat2'], g2['lon2'])
    cells = r.get_covering(LatLngRect.from_point_pair(p1, p2))
    return cells
Exemple #8
0
def cover_square(lat, lng, width, level=15):
    offset = int(width / 2)
    g = Geodesic.WGS84  # @UndefinedVariable
    r = RegionCoverer()
    r.min_level, r.min_level = level, level
    g1 = g.Direct(lat, lng, 360, offset)
    g1 = g.Direct(g1['lat2'],g1['lon2'],270,offset)
    p1 = LatLng.from_degrees(g1['lat2'],g1['lon2'])
    g2 = g.Direct(lat, lng, 180, offset)
    g2 = g.Direct(g2['lat2'],g2['lon2'], 90,offset)
    p2 = LatLng.from_degrees(g2['lat2'],g2['lon2'])
    cells = r.get_covering(LatLngRect.from_point_pair(p1, p2))
    return cells
Exemple #9
0
def _bbox_polyfill(
    geo_json,
    res,
):
    """returns list of S2 ids"""

    lat, lon = _geo_json_to_extremes(geo_json)

    p1 = LatLng.from_degrees(min(lat), min(lon))
    p2 = LatLng.from_degrees(max(lat), max(lon))

    region = LatLngRect.from_point_pair(p1, p2)

    coverer = RegionCoverer()
    coverer.min_level = res
    coverer.max_level = res
    return coverer.get_covering(region)
Exemple #10
0
def build_cap_coverage(lat, lng, cell_count=21, radius=100.0):
    # these are the zoom levels for s2cells
    min_zoom_level = 15
    max_zoom_level = 30

    # radius of the earth in meters
    R = 6378137.0;

    cap_height = ((radius/R)**2)/2
    axis = LatLng.from_degrees(lat, lng).to_point()
    cap = Cap.from_axis_height(axis, cap_height)

    coverer = RegionCoverer()
    coverer.min_level = min_zoom_level
    coverer.max_level = max_zoom_level
    coverer.max_cells = cell_count
    covering = list(coverer.get_covering(cap))
    while(len(covering) < cell_count):
        covering.append(covering[-1].next())
    return covering
Exemple #11
0
def special_getCoveringRect(lat, lng, radius):
    radius_radians = earthMetersToRadians(radius)
    latlng = LatLng.from_degrees(float(lat),
                                 float(lng)).normalized().to_point()
    region = Cap.from_axis_height(latlng,
                                  (radius_radians * radius_radians) / 2)
    coverer = RegionCoverer()
    coverer.min_level = 5
    coverer.max_level = 5
    coverer.max_cells = MAX_S2_CELLS
    covering = coverer.get_covering(region)
    return covering
Exemple #12
0
def cover_region_s2(location1, location2):
    rc = RegionCoverer()
    rc.max_level = lvl_big
    rc.min_level = lvl_big
    rc.max_cells = 1000
    locations = []

    if location1[0] > location2[0]:
        lat1, lat2 = location2[0], location1[0]
    else:
        lat1, lat2 = location1[0], location2[0]

    if location1[1] > location2[1]:
        lng1, lng2 = location2[1], location1[1]
    else:
        lng1, lng2 = location1[1], location2[1]

    lng1 = (lng1 + 180) % 360 - 180
    lng2 = (lng2 + 180) % 360 - 180

    lngs = []
    if lng2 > lng1:
        lngs.append((lng1, lng2))
    elif lng2 < lng1:
        lngs.append((-180.0, lng2))
        lngs.append((lng1, 180.0))

    for lng1, lng2 in lngs:
        cids = rc.get_covering(
            LatLngRect(LatLng.from_degrees(lat1, lng1),
                       LatLng.from_degrees(lat2, lng2)))

        for cid in cids:
            ll_cid = cid.to_lat_lng()
            locations.append((ll_cid.lat().degrees, ll_cid.lng().degrees))
    return locations