s2_cells v2.0.0
Crystal Lang S2 Cells
Maps Lat Lon coordinates to S2 Cells. Useful for things like storing points in InfluxDB
Installation
-
Add the dependency to your
shard.yml
:dependencies: s2_cells: github: spider-gazelle/s2_cells
-
Run
shards install
Usage
require "s2_cells"
# index a location in your database
lat = -33.870456
lon = 151.208889
level = 24
cell = S2Cells.at(lat, lon).parent(level)
token = cell.to_token # => "3ba32f81"
# or
id = cell.id # => Int64
# find all the indexes in an area
p1 = S2Cells::LatLng.from_degrees(33.0, -122.0)
p2 = S2Cells::LatLng.from_degrees(33.1, -122.1)
cells = S2Cells.in(p1, p2) # => Array(CellId)
# then can search your index:
# loc_index = ANY(cells.map(&.id))
Reference
a crystal clone of https://github.com/sidewalklabs/s2sphere
Repository
s2_cells
Owner
Statistic
- 0
- 0
- 0
- 2
- 1
- 4 months ago
- October 8, 2020
License
MIT License
Links
Synced at
Sat, 21 Dec 2024 08:17:40 GMT
Languages