@math.gl/dggs 5.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +140 -0
- package/README.md +7 -0
- package/dist/a5-decoder.d.ts +15 -0
- package/dist/a5-decoder.d.ts.map +1 -0
- package/dist/a5-decoder.js +36 -0
- package/dist/a5-decoder.js.map +1 -0
- package/dist/a5.cjs +134 -0
- package/dist/a5.cjs.map +6 -0
- package/dist/a5.d.ts +2 -0
- package/dist/a5.d.ts.map +1 -0
- package/dist/a5.js +5 -0
- package/dist/a5.js.map +1 -0
- package/dist/converters/s2-to-obb-points.d.ts +15 -0
- package/dist/converters/s2-to-obb-points.d.ts.map +1 -0
- package/dist/converters/s2-to-obb-points.js +60 -0
- package/dist/converters/s2-to-obb-points.js.map +1 -0
- package/dist/converters/s2-to-region.d.ts +6 -0
- package/dist/converters/s2-to-region.d.ts.map +1 -0
- package/dist/converters/s2-to-region.js +27 -0
- package/dist/converters/s2-to-region.js.map +1 -0
- package/dist/dggs-decoder.d.ts +46 -0
- package/dist/dggs-decoder.d.ts.map +1 -0
- package/dist/dggs-decoder.js +52 -0
- package/dist/dggs-decoder.js.map +1 -0
- package/dist/geohash-decoder.d.ts +17 -0
- package/dist/geohash-decoder.d.ts.map +1 -0
- package/dist/geohash-decoder.js +88 -0
- package/dist/geohash-decoder.js.map +1 -0
- package/dist/geohash.cjs +181 -0
- package/dist/geohash.cjs.map +6 -0
- package/dist/geohash.d.ts +2 -0
- package/dist/geohash.d.ts.map +1 -0
- package/dist/geohash.js +5 -0
- package/dist/geohash.js.map +1 -0
- package/dist/h3-decoder.d.ts +15 -0
- package/dist/h3-decoder.d.ts.map +1 -0
- package/dist/h3-decoder.js +46 -0
- package/dist/h3-decoder.js.map +1 -0
- package/dist/h3.cjs +144 -0
- package/dist/h3.cjs.map +6 -0
- package/dist/h3.d.ts +2 -0
- package/dist/h3.d.ts.map +1 -0
- package/dist/h3.js +5 -0
- package/dist/h3.js.map +1 -0
- package/dist/index.cjs +863 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/plus-code-decoder.d.ts +16 -0
- package/dist/plus-code-decoder.d.ts.map +1 -0
- package/dist/plus-code-decoder.js +50 -0
- package/dist/plus-code-decoder.js.map +1 -0
- package/dist/plus-code.cjs +161 -0
- package/dist/plus-code.cjs.map +6 -0
- package/dist/plus-code.d.ts +2 -0
- package/dist/plus-code.d.ts.map +1 -0
- package/dist/plus-code.js +5 -0
- package/dist/plus-code.js.map +1 -0
- package/dist/quadkey-decoder.d.ts +14 -0
- package/dist/quadkey-decoder.d.ts.map +1 -0
- package/dist/quadkey-decoder.js +86 -0
- package/dist/quadkey-decoder.js.map +1 -0
- package/dist/quadkey.cjs +179 -0
- package/dist/quadkey.cjs.map +6 -0
- package/dist/quadkey.d.ts +2 -0
- package/dist/quadkey.d.ts.map +1 -0
- package/dist/quadkey.js +5 -0
- package/dist/quadkey.js.map +1 -0
- package/dist/s2-decoder.d.ts +36 -0
- package/dist/s2-decoder.d.ts.map +1 -0
- package/dist/s2-decoder.js +144 -0
- package/dist/s2-decoder.js.map +1 -0
- package/dist/s2-geometry/s2-geometry.d.ts +33 -0
- package/dist/s2-geometry/s2-geometry.d.ts.map +1 -0
- package/dist/s2-geometry/s2-geometry.js +249 -0
- package/dist/s2-geometry/s2-geometry.js.map +1 -0
- package/dist/s2-geometry/s2-to-boundary.d.ts +14 -0
- package/dist/s2-geometry/s2-to-boundary.d.ts.map +1 -0
- package/dist/s2-geometry/s2-to-boundary.js +60 -0
- package/dist/s2-geometry/s2-to-boundary.js.map +1 -0
- package/dist/s2-geometry/s2-token.d.ts +43 -0
- package/dist/s2-geometry/s2-token.d.ts.map +1 -0
- package/dist/s2-geometry/s2-token.js +127 -0
- package/dist/s2-geometry/s2-token.js.map +1 -0
- package/dist/s2.cjs +543 -0
- package/dist/s2.cjs.map +6 -0
- package/dist/s2.d.ts +5 -0
- package/dist/s2.d.ts.map +1 -0
- package/dist/s2.js +7 -0
- package/dist/s2.js.map +1 -0
- package/dist/unwrap-dggs-boundary.d.ts +12 -0
- package/dist/unwrap-dggs-boundary.d.ts.map +1 -0
- package/dist/unwrap-dggs-boundary.js +49 -0
- package/dist/unwrap-dggs-boundary.js.map +1 -0
- package/package.json +80 -0
- package/src/a5-decoder.ts +47 -0
- package/src/a5.ts +5 -0
- package/src/converters/s2-to-obb-points.ts +78 -0
- package/src/converters/s2-to-region.ts +30 -0
- package/src/dggs-decoder.ts +108 -0
- package/src/geohash-decoder.ts +104 -0
- package/src/geohash.ts +5 -0
- package/src/h3-decoder.ts +58 -0
- package/src/h3.ts +5 -0
- package/src/index.ts +72 -0
- package/src/open-location-code.d.ts +19 -0
- package/src/plus-code-decoder.ts +61 -0
- package/src/plus-code.ts +5 -0
- package/src/quadkey-decoder.ts +103 -0
- package/src/quadkey.ts +5 -0
- package/src/s2-decoder.ts +157 -0
- package/src/s2-geometry/s2-geometry.ts +303 -0
- package/src/s2-geometry/s2-to-boundary.ts +76 -0
- package/src/s2-geometry/s2-token.ts +139 -0
- package/src/s2.ts +15 -0
- package/src/unwrap-dggs-boundary.ts +54 -0
package/dist/quadkey.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// dist/quadkey.js
|
|
20
|
+
var quadkey_exports = {};
|
|
21
|
+
__export(quadkey_exports, {
|
|
22
|
+
QuadkeyDecoder: () => QuadkeyDecoder,
|
|
23
|
+
quadkeyToWorldBounds: () => quadkeyToWorldBounds
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(quadkey_exports);
|
|
26
|
+
|
|
27
|
+
// dist/unwrap-dggs-boundary.js
|
|
28
|
+
function unwrapDGGSBoundary(boundary, referenceLongitude) {
|
|
29
|
+
const result = boundary.map(([longitude, latitude]) => [longitude, latitude]);
|
|
30
|
+
if (result.length === 0) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
let west = Infinity;
|
|
34
|
+
let east = -Infinity;
|
|
35
|
+
for (const [longitude] of boundary) {
|
|
36
|
+
west = Math.min(west, longitude);
|
|
37
|
+
east = Math.max(east, longitude);
|
|
38
|
+
}
|
|
39
|
+
if (east - west >= 360) {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
let previous = referenceLongitude ?? result[0][0];
|
|
43
|
+
for (const point of result) {
|
|
44
|
+
const delta = point[0] - previous;
|
|
45
|
+
if (delta > 180) {
|
|
46
|
+
point[0] -= 360 * Math.ceil((delta - 180) / 360);
|
|
47
|
+
} else if (delta < -180) {
|
|
48
|
+
point[0] += 360 * Math.ceil((-delta - 180) / 360);
|
|
49
|
+
}
|
|
50
|
+
previous = point[0];
|
|
51
|
+
}
|
|
52
|
+
const first = boundary[0];
|
|
53
|
+
const last = boundary[boundary.length - 1];
|
|
54
|
+
if (first[0] === last[0] && first[1] === last[1]) {
|
|
55
|
+
if (Math.abs(result[result.length - 1][0] - result[0][0]) > 180) {
|
|
56
|
+
return boundary.map(([longitude, latitude]) => [longitude, latitude]);
|
|
57
|
+
}
|
|
58
|
+
result[result.length - 1] = [...result[0]];
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// dist/dggs-decoder.js
|
|
64
|
+
function getDGGSCellToken(cell, gridName) {
|
|
65
|
+
if (typeof cell !== "string") {
|
|
66
|
+
throw new Error(`${gridName} cell identifiers must be strings`);
|
|
67
|
+
}
|
|
68
|
+
return cell;
|
|
69
|
+
}
|
|
70
|
+
function getDGGSCellBounds(boundary) {
|
|
71
|
+
let west = Infinity;
|
|
72
|
+
let south = Infinity;
|
|
73
|
+
let east = -Infinity;
|
|
74
|
+
let north = -Infinity;
|
|
75
|
+
for (const [longitude, latitude] of boundary) {
|
|
76
|
+
west = Math.min(west, longitude);
|
|
77
|
+
south = Math.min(south, latitude);
|
|
78
|
+
east = Math.max(east, longitude);
|
|
79
|
+
north = Math.max(north, latitude);
|
|
80
|
+
}
|
|
81
|
+
return [
|
|
82
|
+
[west, south],
|
|
83
|
+
[east, north]
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
function withDGGSBoundaryOptions(decoder) {
|
|
87
|
+
const cellToBoundary = (cell, options) => {
|
|
88
|
+
const boundary = decoder.cellToBoundary(cell);
|
|
89
|
+
return (options == null ? void 0 : options.unwrap) ? unwrapDGGSBoundary(boundary, options.referenceLongitude) : boundary;
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
...decoder,
|
|
93
|
+
cellToBoundary,
|
|
94
|
+
cellToBoundaryFlat: (cell, options) => (options == null ? void 0 : options.unwrap) ? cellToBoundary(cell, options).flat() : decoder.cellToBoundaryFlat(cell),
|
|
95
|
+
cellToBounds: (cell, options) => {
|
|
96
|
+
const bounds = decoder.cellToBounds(cell);
|
|
97
|
+
if (!(options == null ? void 0 : options.unwrap) || bounds[1][0] - bounds[0][0] >= 360) {
|
|
98
|
+
return bounds;
|
|
99
|
+
}
|
|
100
|
+
const unwrapped = getDGGSCellBounds(cellToBoundary(cell, options));
|
|
101
|
+
unwrapped[0][1] = bounds[0][1];
|
|
102
|
+
unwrapped[1][1] = bounds[1][1];
|
|
103
|
+
return unwrapped;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// dist/quadkey-decoder.js
|
|
109
|
+
var TILE_SIZE = 512;
|
|
110
|
+
var QuadkeyDecoder = withDGGSBoundaryOptions({
|
|
111
|
+
name: "quadkey",
|
|
112
|
+
hasNumericRepresentation: false,
|
|
113
|
+
cellColumnNames: ["quadkey", "quadkeyId", "quadkey_id"],
|
|
114
|
+
cellToLngLat: (cell) => getQuadkeyLngLat(getDGGSCellToken(cell, "Quadkey")),
|
|
115
|
+
cellToBoundary: (cell) => getQuadkeyBoundary(getDGGSCellToken(cell, "Quadkey")),
|
|
116
|
+
cellToBoundaryFlat: (cell) => getQuadkeyBoundaryFlat(getDGGSCellToken(cell, "Quadkey")),
|
|
117
|
+
cellToBounds: (cell) => getQuadkeyBounds(getDGGSCellToken(cell, "Quadkey"))
|
|
118
|
+
});
|
|
119
|
+
function getQuadkeyLngLat(quadkey) {
|
|
120
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
121
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
122
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
123
|
+
return [(e + w) / 2, (s + n) / 2];
|
|
124
|
+
}
|
|
125
|
+
function getQuadkeyBoundary(quadkey) {
|
|
126
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
127
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
128
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
129
|
+
return [
|
|
130
|
+
[e, n],
|
|
131
|
+
[e, s],
|
|
132
|
+
[w, s],
|
|
133
|
+
[w, n],
|
|
134
|
+
[e, n]
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
function getQuadkeyBoundaryFlat(quadkey) {
|
|
138
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
139
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
140
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
141
|
+
return [e, n, e, s, w, s, w, n, e, n];
|
|
142
|
+
}
|
|
143
|
+
function getQuadkeyBounds(quadkey) {
|
|
144
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
145
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
146
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
147
|
+
return [
|
|
148
|
+
[w, s],
|
|
149
|
+
[e, n]
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
function quadkeyToWorldBounds(quadkey) {
|
|
153
|
+
let x = 0;
|
|
154
|
+
let y = 0;
|
|
155
|
+
let mask = 1 << quadkey.length;
|
|
156
|
+
const scale = mask / TILE_SIZE;
|
|
157
|
+
for (let i = 0; i < quadkey.length; i++) {
|
|
158
|
+
mask >>= 1;
|
|
159
|
+
const q = parseInt(quadkey[i], 10);
|
|
160
|
+
if (q % 2)
|
|
161
|
+
x |= mask;
|
|
162
|
+
if (q > 1)
|
|
163
|
+
y |= mask;
|
|
164
|
+
}
|
|
165
|
+
return [
|
|
166
|
+
[x / scale, TILE_SIZE - y / scale],
|
|
167
|
+
[(x + 0.99) / scale, TILE_SIZE - (y + 0.99) / scale]
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
var PI = Math.PI;
|
|
171
|
+
var PI_4 = PI / 4;
|
|
172
|
+
var RADIANS_TO_DEGREES = 180 / PI;
|
|
173
|
+
function worldToLngLat(xy) {
|
|
174
|
+
const [x, y] = xy;
|
|
175
|
+
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
176
|
+
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
177
|
+
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=quadkey.cjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/quadkey.ts", "../src/unwrap-dggs-boundary.ts", "../src/dggs-decoder.ts", "../src/quadkey-decoder.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACcM,SAAU,mBACd,UACA,oBAA2B;AAE3B,QAAM,SAA6B,SAAS,IAAI,CAAC,CAAC,WAAW,QAAQ,MAAM,CAAC,WAAW,QAAQ,CAAC;AAChG,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;EACT;AAEA,MAAI,OAAO;AACX,MAAI,OAAO;AACX,aAAW,CAAC,SAAS,KAAK,UAAU;AAClC,WAAO,KAAK,IAAI,MAAM,SAAS;AAC/B,WAAO,KAAK,IAAI,MAAM,SAAS;EACjC;AACA,MAAI,OAAO,QAAQ,KAAK;AACtB,WAAO;EACT;AAEA,MAAI,WAAW,sBAAsB,OAAO,CAAC,EAAE,CAAC;AAChD,aAAW,SAAS,QAAQ;AAC1B,UAAM,QAAQ,MAAM,CAAC,IAAI;AACzB,QAAI,QAAQ,KAAK;AACf,YAAM,CAAC,KAAK,MAAM,KAAK,MAAM,QAAQ,OAAO,GAAG;IACjD,WAAW,QAAQ,MAAM;AACvB,YAAM,CAAC,KAAK,MAAM,KAAK,MAAM,CAAC,QAAQ,OAAO,GAAG;IAClD;AACA,eAAW,MAAM,CAAC;EACpB;AAEA,QAAM,QAAQ,SAAS,CAAC;AACxB,QAAM,OAAO,SAAS,SAAS,SAAS,CAAC;AACzC,MAAI,MAAM,CAAC,MAAM,KAAK,CAAC,KAAK,MAAM,CAAC,MAAM,KAAK,CAAC,GAAG;AAChD,QAAI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ts","sourceRoot":"","sources":["../src/quadkey.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,cAAc,EAAE,oBAAoB,EAAC,6BAA0B"}
|
package/dist/quadkey.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quadkey.js","sourceRoot":"","sources":["../src/quadkey.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,cAAc,EAAE,oBAAoB,EAAC,6BAA0B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Bounds2D } from '@math.gl/types';
|
|
2
|
+
import { type DGGSCell, type DGGSDecoder } from "./dggs-decoder.js";
|
|
3
|
+
/** Decoder for the S2 DGGS */
|
|
4
|
+
export declare const S2Decoder: Omit<{
|
|
5
|
+
readonly name: "s2";
|
|
6
|
+
readonly hasNumericRepresentation: true;
|
|
7
|
+
readonly cellColumnNames: readonly ["s2", "s2Token", "s2_token", "s2Cell", "s2_cell", "s2CellId", "s2_cell_id"];
|
|
8
|
+
readonly tokenToCell: (s2Token: string) => bigint;
|
|
9
|
+
readonly cellToToken: (cell: DGGSCell) => string;
|
|
10
|
+
readonly cellToLngLat: (cell: DGGSCell) => [number, number];
|
|
11
|
+
readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
|
|
12
|
+
readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
|
|
13
|
+
readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
|
|
14
|
+
}, "cellToBoundary" | "cellToBoundaryFlat" | "cellToBounds"> & Pick<DGGSDecoder, "cellToBoundary" | "cellToBoundaryFlat" | "cellToBounds">;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve S2 geometry center
|
|
17
|
+
*/
|
|
18
|
+
export declare function getS2LngLat(cell: DGGSCell): [number, number];
|
|
19
|
+
/**
|
|
20
|
+
* Get a polygon with corner coordinates for an s2 cell
|
|
21
|
+
* @param - This can be an S2 key or token
|
|
22
|
+
* @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
|
|
23
|
+
* - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
|
|
24
|
+
*/
|
|
25
|
+
export declare function getS2BoundaryFlat(cell: DGGSCell): number[];
|
|
26
|
+
/**
|
|
27
|
+
* Returns conservative longitude/latitude bounds for an S2 cell.
|
|
28
|
+
*
|
|
29
|
+
* Longitudes are unwrapped so `east >= west`; either endpoint may lie outside `[-180, 180]` for
|
|
30
|
+
* antimeridian cells. The two level-zero polar faces span a complete 360-degree longitude range.
|
|
31
|
+
*
|
|
32
|
+
* @param cell - S2 token or 64-bit cell index.
|
|
33
|
+
* @returns Bounds in `[[west, south], [east, north]]` order and degrees.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getS2Bounds(cell: DGGSCell): Bounds2D;
|
|
36
|
+
//# sourceMappingURL=s2-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-decoder.d.ts","sourceRoot":"","sources":["../src/s2-decoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAC,0BAAuB;AAMxF,8BAA8B;AAC9B,eAAO,MAAM,SAAS;;;;oCAIG,MAAM,KAAG,MAAM;iCAClB,QAAQ,KAAG,MAAM;kCAChB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCACzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCACzB,QAAQ,KAAG,MAAM,EAAE;kCACzB,QAAQ,KAAG,QAAQ;0IACT,CAAC;AAElC;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAU5D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CAK1D;AAWD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CA4CpD"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { withDGGSBoundaryOptions } from "./dggs-decoder.js";
|
|
5
|
+
import { getS2IndexFromToken, getS2TokenFromIndex } from "./s2-geometry/s2-token.js";
|
|
6
|
+
import { getS2GeoBounds } from "./s2-geometry/s2-to-boundary.js";
|
|
7
|
+
import { getS2Cell, IJToST, STToUV, FaceUVToXYZ, XYZToLngLat } from "./s2-geometry/s2-geometry.js";
|
|
8
|
+
/** Decoder for the S2 DGGS */
|
|
9
|
+
export const S2Decoder = withDGGSBoundaryOptions({
|
|
10
|
+
name: 's2',
|
|
11
|
+
hasNumericRepresentation: true,
|
|
12
|
+
cellColumnNames: ['s2', 's2Token', 's2_token', 's2Cell', 's2_cell', 's2CellId', 's2_cell_id'],
|
|
13
|
+
tokenToCell: (s2Token) => getS2IndexFromToken(s2Token),
|
|
14
|
+
cellToToken: (cell) => getS2TokenFromIndex(getS2CellIndex(cell)),
|
|
15
|
+
cellToLngLat: (cell) => getS2LngLat(cell),
|
|
16
|
+
cellToBoundary: (cell) => getS2Boundary(cell),
|
|
17
|
+
cellToBoundaryFlat: (cell) => getS2BoundaryFlat(cell),
|
|
18
|
+
cellToBounds: (cell) => getS2Bounds(cell)
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve S2 geometry center
|
|
22
|
+
*/
|
|
23
|
+
export function getS2LngLat(cell) {
|
|
24
|
+
const s2Index = getS2CellIndex(cell);
|
|
25
|
+
const s2Cell = getS2Cell(s2Index);
|
|
26
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
|
|
27
|
+
const uv = STToUV(st);
|
|
28
|
+
const xyz = FaceUVToXYZ(s2Cell.face, uv);
|
|
29
|
+
const lngLat = XYZToLngLat(xyz);
|
|
30
|
+
return lngLat;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a polygon with corner coordinates for an s2 cell
|
|
34
|
+
* @param - This can be an S2 key or token
|
|
35
|
+
* @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
|
|
36
|
+
* - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
|
|
37
|
+
*/
|
|
38
|
+
export function getS2BoundaryFlat(cell) {
|
|
39
|
+
const s2Index = getS2CellIndex(cell);
|
|
40
|
+
const float64Array = getS2GeoBounds(s2Index);
|
|
41
|
+
// TODO - inefficient
|
|
42
|
+
return Array.from(float64Array);
|
|
43
|
+
}
|
|
44
|
+
function getS2Boundary(cell) {
|
|
45
|
+
const flatBoundary = getS2BoundaryFlat(cell);
|
|
46
|
+
const boundary = [];
|
|
47
|
+
for (let i = 0; i < flatBoundary.length; i += 2) {
|
|
48
|
+
boundary.push([flatBoundary[i], flatBoundary[i + 1]]);
|
|
49
|
+
}
|
|
50
|
+
return boundary;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns conservative longitude/latitude bounds for an S2 cell.
|
|
54
|
+
*
|
|
55
|
+
* Longitudes are unwrapped so `east >= west`; either endpoint may lie outside `[-180, 180]` for
|
|
56
|
+
* antimeridian cells. The two level-zero polar faces span a complete 360-degree longitude range.
|
|
57
|
+
*
|
|
58
|
+
* @param cell - S2 token or 64-bit cell index.
|
|
59
|
+
* @returns Bounds in `[[west, south], [east, north]]` order and degrees.
|
|
60
|
+
*/
|
|
61
|
+
export function getS2Bounds(cell) {
|
|
62
|
+
const s2Cell = getS2Cell(getS2CellIndex(cell));
|
|
63
|
+
if (s2Cell.level === 0) {
|
|
64
|
+
return getS2RootBounds(s2Cell.face);
|
|
65
|
+
}
|
|
66
|
+
// For non-root S2 cells, latitude and longitude extrema occur at vertices. Root cells require
|
|
67
|
+
// the special cases above because their curved edges or interiors contain the extrema.
|
|
68
|
+
// https://github.com/google/s2geometry/blob/master/src/s2/s2cell.cc
|
|
69
|
+
const offsets = [
|
|
70
|
+
[0, 0],
|
|
71
|
+
[0, 1],
|
|
72
|
+
[1, 1],
|
|
73
|
+
[1, 0]
|
|
74
|
+
];
|
|
75
|
+
let west = Infinity;
|
|
76
|
+
let south = Infinity;
|
|
77
|
+
let east = -Infinity;
|
|
78
|
+
let north = -Infinity;
|
|
79
|
+
let previousLongitude;
|
|
80
|
+
for (const offset of offsets) {
|
|
81
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, offset);
|
|
82
|
+
const uv = STToUV(st);
|
|
83
|
+
const [x, y, z] = FaceUVToXYZ(s2Cell.face, uv);
|
|
84
|
+
let [longitude, latitude] = XYZToLngLat([x, y, z]);
|
|
85
|
+
if (x === 0 && y === 0 && previousLongitude !== undefined) {
|
|
86
|
+
longitude = previousLongitude;
|
|
87
|
+
}
|
|
88
|
+
if (previousLongitude !== undefined) {
|
|
89
|
+
const longitudeDelta = longitude - previousLongitude;
|
|
90
|
+
longitude += longitudeDelta > 180 ? -360 : longitudeDelta < -180 ? 360 : 0;
|
|
91
|
+
}
|
|
92
|
+
previousLongitude = longitude;
|
|
93
|
+
west = Math.min(west, longitude);
|
|
94
|
+
south = Math.min(south, latitude);
|
|
95
|
+
east = Math.max(east, longitude);
|
|
96
|
+
north = Math.max(north, latitude);
|
|
97
|
+
}
|
|
98
|
+
const angularEpsilon = (2 * Number.EPSILON * 180) / Math.PI;
|
|
99
|
+
return [
|
|
100
|
+
[west - angularEpsilon, Math.max(-90, south - angularEpsilon)],
|
|
101
|
+
[east + angularEpsilon, Math.min(90, north + angularEpsilon)]
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
function getS2CellIndex(cell) {
|
|
105
|
+
return typeof cell === 'bigint' ? cell : getS2IndexFromToken(cell);
|
|
106
|
+
}
|
|
107
|
+
function getS2RootBounds(face) {
|
|
108
|
+
const polarLatitude = (Math.asin(Math.sqrt(1 / 3)) * 180) / Math.PI;
|
|
109
|
+
switch (face) {
|
|
110
|
+
case 0:
|
|
111
|
+
return [
|
|
112
|
+
[-45, -45],
|
|
113
|
+
[45, 45]
|
|
114
|
+
];
|
|
115
|
+
case 1:
|
|
116
|
+
return [
|
|
117
|
+
[45, -45],
|
|
118
|
+
[135, 45]
|
|
119
|
+
];
|
|
120
|
+
case 2:
|
|
121
|
+
return [
|
|
122
|
+
[-180, polarLatitude],
|
|
123
|
+
[180, 90]
|
|
124
|
+
];
|
|
125
|
+
case 3:
|
|
126
|
+
return [
|
|
127
|
+
[135, -45],
|
|
128
|
+
[225, 45]
|
|
129
|
+
];
|
|
130
|
+
case 4:
|
|
131
|
+
return [
|
|
132
|
+
[-135, -45],
|
|
133
|
+
[-45, 45]
|
|
134
|
+
];
|
|
135
|
+
case 5:
|
|
136
|
+
return [
|
|
137
|
+
[-180, -90],
|
|
138
|
+
[180, -polarLatitude]
|
|
139
|
+
];
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(`Invalid S2 face: ${face}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=s2-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-decoder.js","sourceRoot":"","sources":["../src/s2-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,uBAAuB,EAAkC,0BAAuB;AAExF,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,kCAA+B;AAChF,OAAO,EAAC,cAAc,EAAC,wCAAqC;AAC5D,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAC,qCAAkC;AAE9F,8BAA8B;AAC9B,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAC;IAC/C,IAAI,EAAE,IAAI;IACV,wBAAwB,EA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V,CAAC;QACJ,KAAK,CAAC;YACJ,OAAO;gBACL,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;gBACX,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC;aACtB,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type S2Cell = {
|
|
2
|
+
face: number;
|
|
3
|
+
ij: [number, number];
|
|
4
|
+
level: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function getS2Cell(s2Index: bigint): S2Cell;
|
|
7
|
+
export declare function fromHilbertQuadKey(hilbertQuadkey: string): S2Cell;
|
|
8
|
+
export declare function toHilbertQuadkey(id: bigint): string;
|
|
9
|
+
/**
|
|
10
|
+
* Converts face-local integer coordinates into an S2 cell index.
|
|
11
|
+
*
|
|
12
|
+
* @param s2Cell - Face, `(i, j)` coordinates, and level of an S2 cell.
|
|
13
|
+
* @returns The corresponding 64-bit S2 cell index.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getS2IndexFromCell(s2Cell: S2Cell): bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a spatially addressed descendant of an S2 cell.
|
|
18
|
+
*
|
|
19
|
+
* Unlike {@link getS2ChildIndex}, `x` and `y` address the descendant along increasing face-local
|
|
20
|
+
* `i` and `j` axes. This accounts for Hilbert orientation changes across faces and levels.
|
|
21
|
+
*
|
|
22
|
+
* @param rootIndex - Valid S2 cell index at the root of the relative grid.
|
|
23
|
+
* @param relativeLevel - Number of subdivision levels below the root.
|
|
24
|
+
* @param x - Descendant coordinate along the root cell's increasing `i` axis.
|
|
25
|
+
* @param y - Descendant coordinate along the root cell's increasing `j` axis.
|
|
26
|
+
* @returns The descendant S2 cell index.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getS2DescendantIndex(rootIndex: bigint, relativeLevel: number, x: number, y: number): bigint;
|
|
29
|
+
export declare function IJToST(ij: [number, number], order: number, offsets: [number, number]): [number, number];
|
|
30
|
+
export declare function STToUV(st: [number, number]): [number, number];
|
|
31
|
+
export declare function FaceUVToXYZ(face: number, [u, v]: [number, number]): [number, number, number];
|
|
32
|
+
export declare function XYZToLngLat([x, y, z]: [number, number, number]): [number, number];
|
|
33
|
+
//# sourceMappingURL=s2-geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-geometry.d.ts","sourceRoot":"","sources":["../../src/s2-geometry/s2-geometry.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOjD;AA8CD,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAwCjE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAgCnD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA4BzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,MAAM,CAyBR;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GACxB,CAAC,MAAM,EAAE,MAAM,CAAC,CAIlB;AASD,wBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,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