Using Python S2/S2sphere library - find all s2 cells of a particular level with in a circle(lat, long and radius is given)
With the help of link, I worked out for python solution.
I am using python s2sphere library.
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 method returns all s2 cells(Rectangle boundary) at given parent level which is covered by circle drawn from given lat, long as center and given radius