Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/s2_cells
maps latitude and longitude to S2 Cells https://s2geometry.io/
https://github.com/spider-gazelle/s2_cells
Last synced: 25 days ago
JSON representation
maps latitude and longitude to S2 Cells https://s2geometry.io/
- Host: GitHub
- URL: https://github.com/spider-gazelle/s2_cells
- Owner: spider-gazelle
- License: mit
- Created: 2020-10-08T14:57:05.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-27T14:10:12.000Z (5 months ago)
- Last Synced: 2024-08-05T01:10:59.361Z (4 months ago)
- Language: Crystal
- Size: 47.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - s2_cells - [S2 Geometry](https://s2geometry.io/devguide/s2cell_hierarchy.html) for spatial indexing (Algorithms and Data structures)
README
# Crystal Lang S2 Cells
[![CI](https://github.com/spider-gazelle/s2_cells/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/s2_cells/actions/workflows/ci.yml)
Maps Lat Lon coordinates to S2 Cells.
Useful for things like storing points [in InfluxDB](https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/experimental/geo/#geo-schema-requirements)## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
s2_cells:
github: spider-gazelle/s2_cells
```2. Run `shards install`
## Usage
```crystal
require "s2_cells"
# index a location in your database
lat = -33.870456
lon = 151.208889
level = 24cell = 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