2017-06-20 176 views
2

什麼S2Region,我應該如何使用,以獲得在一定父級別的所有S2細胞(比方說9)覆蓋從LAT給出,長和半徑畫出的圓圈。下面是一個使用Python S2庫得到一個矩形下的所有小區的例子。使用Python S2/S2sphere庫 - 找到一個特定級別的所有S2細胞圓(緯度,經度和半徑給出)

region_rect = S2LatLngRect(
       S2LatLng.FromDegrees(-51.264871, -30.241701), 
       S2LatLng.FromDegrees(-51.04618, -30.000003)) 
coverer = S2RegionCoverer() 
coverer.set_min_level(8) 
coverer.set_max_level(15) 
coverer.set_max_cells(500) 
covering = coverer.GetCovering(region_rect) 

例如http://blog.christianperone.com/2015/08/googles-s2-geometry-on-the-sphere-cells-and-hilbert-curve/

的來源,我尋找類似

region_circle = S2latLangCircle(lat,lang,radius) 

我覺得這個問題對谷歌S2庫在C++中Using google s2 library - find all s2 cells of a certain level within the circle, given lat/lng and radius in miles/km實現的答案,但我需要這個Python編寫的。

感謝

回答

1

隨着link的幫助下,我制定了蟒蛇的解決方案。

我使用python s2sphere庫。

earthCircumferenceMeters = 1000 * 40075.017 
def earthMetersToRadians(meters): 
    return (2 * math.pi) * (float(meters)/
    const.earthCircumferenceMeters) 


def getCoveringRect(lat, lng, radius, parent_level): 
    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 = int(parent_level) 
    coverer.max_level = int(parent_level) 
    coverer.max_cells = const.MAX_S2_CELLS 
    covering = coverer.get_covering(region) 
    s2_rect = [] 
    for cell_id in covering: 
    new_cell = Cell(cell_id) 
    vertices = [] 
    for i in range(4): 
     vertex = new_cell.get_vertex(i) 
     latlng = LatLng.from_point(vertex) 
     vertices.append((math.degrees(latlng.lat().radians), 
         math.degrees(latlng.lng().radians))) 
    s2_rect.append(vertices) 
    return s2_rect 

getCoveringRect方法返回以給定父級別是由圓圈涵蓋了從給定緯度繪製,只要中心和給定半徑

所有S2細胞(矩形邊界)
相關問題