Skip to content

Commit

Permalink
Use cellToParent
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Nov 7, 2023
1 parent 2e3f30e commit f87a8e4
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/metadata-service/src/model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Sequelize, STRING, Model, DataTypes } from "sequelize";
import AWS from "aws-sdk";
import * as pg from "pg";
import { cellToLatLng, latLngToCell } from "h3-js";
import BN from "bn.js";

const parseH3BNLocation = (location: BN) =>
cellToLatLng(location.toString("hex"));
import { cellToLatLng, cellToParent } from "h3-js";
import * as pg from "pg";
import { DataTypes, Model, STRING, Sequelize } from "sequelize";

const host = process.env.PGHOST || "localhost";
const port = Number(process.env.PGPORT) || 5432;
Expand Down Expand Up @@ -62,8 +59,7 @@ class WithRes8LatLgn extends Model {
_long: number | undefined = undefined;

setLatLng() {
const [lat, long] = parseH3BNLocation(new BN(this.location));
const res8 = latLngToCell(lat, long, 8);
const res8 = cellToParent(new BN(this.location).toString("hex"), 8);
const [latRes8, longRes8] = cellToLatLng(res8);
this._lat = latRes8;
this._long = longRes8;
Expand Down

0 comments on commit f87a8e4

Please sign in to comment.