@math.gl/dggs 5.0.0-alpha.2
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 +77 -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 +37 -0
- package/dist/dggs-decoder.d.ts.map +1 -0
- package/dist/dggs-decoder.js +28 -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 +108 -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 +87 -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 +615 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -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 +88 -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 +106 -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 +26 -0
- package/dist/s2-decoder.d.ts.map +1 -0
- package/dist/s2-decoder.js +76 -0
- package/dist/s2-decoder.js.map +1 -0
- package/dist/s2-geometry/s2-geometry.d.ts +13 -0
- package/dist/s2-geometry/s2-geometry.d.ts.map +1 -0
- package/dist/s2-geometry/s2-geometry.js +126 -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 +13 -0
- package/dist/s2-geometry/s2-token.d.ts.map +1 -0
- package/dist/s2-geometry/s2-token.js +61 -0
- package/dist/s2-geometry/s2-token.js.map +1 -0
- package/dist/s2.cjs +278 -0
- package/dist/s2.cjs.map +6 -0
- package/dist/s2.d.ts +3 -0
- package/dist/s2.d.ts.map +1 -0
- package/dist/s2.js +6 -0
- package/dist/s2.js.map +1 -0
- package/package.json +80 -0
- package/src/a5-decoder.ts +42 -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 +71 -0
- package/src/geohash-decoder.ts +99 -0
- package/src/geohash.ts +5 -0
- package/src/h3-decoder.ts +53 -0
- package/src/h3.ts +5 -0
- package/src/index.ts +61 -0
- package/src/open-location-code.d.ts +19 -0
- package/src/plus-code-decoder.ts +56 -0
- package/src/plus-code.ts +5 -0
- package/src/quadkey-decoder.ts +98 -0
- package/src/quadkey.ts +5 -0
- package/src/s2-decoder.ts +87 -0
- package/src/s2-geometry/s2-geometry.ts +166 -0
- package/src/s2-geometry/s2-to-boundary.ts +76 -0
- package/src/s2-geometry/s2-token.ts +70 -0
- package/src/s2.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Uber Technologies, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Some primitive tessellation approaches were originally inspired by the TDL WebGL samples under
|
|
26
|
+
the New BSD License:
|
|
27
|
+
|
|
28
|
+
Copyright (c) 2011, Google Inc. All rights reserved.
|
|
29
|
+
|
|
30
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
31
|
+
provided that the following conditions are met:
|
|
32
|
+
|
|
33
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
34
|
+
and the following disclaimer.
|
|
35
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
36
|
+
conditions and the following disclaimer in the documentation and/or other materials provided
|
|
37
|
+
with the distribution.
|
|
38
|
+
3. Neither the name of Google Inc. nor the names of its contributors may be used to endorse or
|
|
39
|
+
promote products derived from this software without specific prior written permission.
|
|
40
|
+
|
|
41
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
42
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
44
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
45
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
46
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
47
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
48
|
+
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
math.gl builds on docs and code from "gl-matrix", which is MIT licensed as follows:
|
|
53
|
+
|
|
54
|
+
Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
|
|
55
|
+
|
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
57
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
58
|
+
in the Software without restriction, including without limitation the rights
|
|
59
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
60
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
61
|
+
furnished to do so, subject to the following conditions:
|
|
62
|
+
|
|
63
|
+
The above copyright notice and this permission notice shall be included in
|
|
64
|
+
all copies or substantial portions of the Software.
|
|
65
|
+
|
|
66
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
67
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
68
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
69
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
70
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
71
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
72
|
+
THE SOFTWARE.
|
|
73
|
+
|
|
74
|
+
--
|
|
75
|
+
|
|
76
|
+
math.gl builds on docs and code from THREE.js, which is MIT licensed as follows:
|
|
77
|
+
|
|
78
|
+
The MIT License
|
|
79
|
+
|
|
80
|
+
Copyright © 2010-2017 three.js authors
|
|
81
|
+
|
|
82
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
83
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
84
|
+
in the Software without restriction, including without limitation the rights
|
|
85
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
86
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
87
|
+
furnished to do so, subject to the following conditions:
|
|
88
|
+
|
|
89
|
+
The above copyright notice and this permission notice shall be included in
|
|
90
|
+
all copies or substantial portions of the Software.
|
|
91
|
+
|
|
92
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
93
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
94
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
95
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
96
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
97
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
98
|
+
THE SOFTWARE.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
math.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium) under the Apache 2 License:
|
|
103
|
+
|
|
104
|
+
Copyright 2011-2018 CesiumJS Contributors
|
|
105
|
+
|
|
106
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
107
|
+
you may not use this file except in compliance with the License.
|
|
108
|
+
You may obtain a copy of the License at
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and limitations under the License.
|
|
115
|
+
|
|
116
|
+
Cesium-derived code can be found in the submodule: modules/3d-tiles
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
The @math.gl/geometry primitive tessellators are adapted from luma.gl under the MIT License:
|
|
121
|
+
|
|
122
|
+
Copyright (c) 2020 vis.gl contributors
|
|
123
|
+
|
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
125
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
126
|
+
in the Software without restriction, including without limitation the rights
|
|
127
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
128
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
129
|
+
furnished to do so, subject to the following conditions:
|
|
130
|
+
|
|
131
|
+
The above copyright notice and this permission notice shall be included in
|
|
132
|
+
all copies or substantial portions of the Software.
|
|
133
|
+
|
|
134
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
135
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
136
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
137
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
138
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
139
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
140
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @math.gl/dggs
|
|
2
|
+
|
|
3
|
+
[math.gl](https://math.gl/docs) is a suite of math modules for 3D and geospatial applications.
|
|
4
|
+
|
|
5
|
+
This module contains lightweight geometry decoders and cell-column detection for A5, GeoHash, H3, Google Plus Code, Quadkey, and S2 identifiers. Decoder-specific entry points are available as package subpaths such as `@math.gl/dggs/a5` and `@math.gl/dggs/h3`.
|
|
6
|
+
|
|
7
|
+
For documentation please visit the [website](https://math.gl).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Bounds2D } from '@math.gl/types';
|
|
2
|
+
import { type DGGSCell } from "./dggs-decoder.js";
|
|
3
|
+
/** Lightweight cell geometry decoder for the A5 pentagonal DGGS. */
|
|
4
|
+
export declare const A5Decoder: {
|
|
5
|
+
readonly name: "a5";
|
|
6
|
+
readonly hasNumericRepresentation: true;
|
|
7
|
+
readonly cellColumnNames: readonly ["a5", "a5Token", "a5_token", "a5Cell", "a5_cell", "a5CellId", "a5_cell_id", "pentagon"];
|
|
8
|
+
readonly tokenToCell: (token: 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
|
+
};
|
|
15
|
+
//# sourceMappingURL=a5-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a5-decoder.d.ts","sourceRoot":"","sources":["../src/a5-decoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,KAAK,QAAQ,EAAsC,0BAAuB;AAElF,oEAAoE;AACpE,eAAO,MAAM,SAAS;;;;kCAaC,MAAM,KAAG,MAAM;iCAChB,QAAQ,KAAG,MAAM;kCAEhB,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;CACV,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { cellToBoundary, cellToLonLat, hexToU64, u64ToHex } from 'a5-js';
|
|
5
|
+
import { getDGGSCellBounds } from "./dggs-decoder.js";
|
|
6
|
+
/** Lightweight cell geometry decoder for the A5 pentagonal DGGS. */
|
|
7
|
+
export const A5Decoder = {
|
|
8
|
+
name: 'a5',
|
|
9
|
+
hasNumericRepresentation: true,
|
|
10
|
+
cellColumnNames: [
|
|
11
|
+
'a5',
|
|
12
|
+
'a5Token',
|
|
13
|
+
'a5_token',
|
|
14
|
+
'a5Cell',
|
|
15
|
+
'a5_cell',
|
|
16
|
+
'a5CellId',
|
|
17
|
+
'a5_cell_id',
|
|
18
|
+
'pentagon'
|
|
19
|
+
],
|
|
20
|
+
tokenToCell: (token) => hexToU64(removeHexPrefix(token)),
|
|
21
|
+
cellToToken: (cell) => typeof cell === 'string' ? removeHexPrefix(cell) : u64ToHex(cell),
|
|
22
|
+
cellToLngLat: (cell) => cellToLonLat(getA5CellIndex(cell)),
|
|
23
|
+
cellToBoundary: (cell) => getA5Boundary(cell),
|
|
24
|
+
cellToBoundaryFlat: (cell) => getA5Boundary(cell).flat(),
|
|
25
|
+
cellToBounds: (cell) => getDGGSCellBounds(getA5Boundary(cell))
|
|
26
|
+
};
|
|
27
|
+
function getA5CellIndex(cell) {
|
|
28
|
+
return typeof cell === 'bigint' ? cell : hexToU64(removeHexPrefix(cell));
|
|
29
|
+
}
|
|
30
|
+
function getA5Boundary(cell) {
|
|
31
|
+
return cellToBoundary(getA5CellIndex(cell)).map(([longitude, latitude]) => [longitude, latitude]);
|
|
32
|
+
}
|
|
33
|
+
function removeHexPrefix(token) {
|
|
34
|
+
return token.startsWith('0x') || token.startsWith('0X') ? token.slice(2) : token;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=a5-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a5-decoder.js","sourceRoot":"","sources":["../src/a5-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEvE,OAAO,EAAkC,iBAAiB,EAAC,0BAAuB;AAElF,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,IAAI;IACV,wBAAwB,EAAE,IAAI;IAC9B,eAAe,EAAE;QACf,IAAI;QACJ,SAAS;QACT,UAAU;QACV,QAAQ;QACR,SAAS;QACT,UAAU;QACV,YAAY;QACZ,UAAU;KACX;IACD,WAAW,EAAE,CAAC,KAAa,EAAU,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACxE,WAAW,EAAE,CAAC,IAAc,EAAU,EAAE,CACtC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnE,YAAY,EAAE,CAAC,IAAc,EAAoB,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACtF,cAAc,EAAE,CAAC,IAAc,EAAsB,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;IAC3E,kBAAkB,EAAE,CAAC,IAAc,EAAY,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;IAC5E,YAAY,EAAE,CAAC,IAAc,EAAY,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;CACpD,CAAC;AAEjC,SAAS,cAAc,CAAC,IAAc;IACpC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,aAAa,CAAC,IAAc;IACnC,OAAO,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACnF,CAAC"}
|
package/dist/a5.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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/a5.js
|
|
20
|
+
var a5_exports = {};
|
|
21
|
+
__export(a5_exports, {
|
|
22
|
+
A5Decoder: () => A5Decoder
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(a5_exports);
|
|
25
|
+
|
|
26
|
+
// dist/a5-decoder.js
|
|
27
|
+
var import_a5_js = require("a5-js");
|
|
28
|
+
|
|
29
|
+
// dist/dggs-decoder.js
|
|
30
|
+
function getDGGSCellBounds(boundary) {
|
|
31
|
+
let west = Infinity;
|
|
32
|
+
let south = Infinity;
|
|
33
|
+
let east = -Infinity;
|
|
34
|
+
let north = -Infinity;
|
|
35
|
+
for (const [longitude, latitude] of boundary) {
|
|
36
|
+
west = Math.min(west, longitude);
|
|
37
|
+
south = Math.min(south, latitude);
|
|
38
|
+
east = Math.max(east, longitude);
|
|
39
|
+
north = Math.max(north, latitude);
|
|
40
|
+
}
|
|
41
|
+
return [
|
|
42
|
+
[west, south],
|
|
43
|
+
[east, north]
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// dist/a5-decoder.js
|
|
48
|
+
var A5Decoder = {
|
|
49
|
+
name: "a5",
|
|
50
|
+
hasNumericRepresentation: true,
|
|
51
|
+
cellColumnNames: [
|
|
52
|
+
"a5",
|
|
53
|
+
"a5Token",
|
|
54
|
+
"a5_token",
|
|
55
|
+
"a5Cell",
|
|
56
|
+
"a5_cell",
|
|
57
|
+
"a5CellId",
|
|
58
|
+
"a5_cell_id",
|
|
59
|
+
"pentagon"
|
|
60
|
+
],
|
|
61
|
+
tokenToCell: (token) => (0, import_a5_js.hexToU64)(removeHexPrefix(token)),
|
|
62
|
+
cellToToken: (cell) => typeof cell === "string" ? removeHexPrefix(cell) : (0, import_a5_js.u64ToHex)(cell),
|
|
63
|
+
cellToLngLat: (cell) => (0, import_a5_js.cellToLonLat)(getA5CellIndex(cell)),
|
|
64
|
+
cellToBoundary: (cell) => getA5Boundary(cell),
|
|
65
|
+
cellToBoundaryFlat: (cell) => getA5Boundary(cell).flat(),
|
|
66
|
+
cellToBounds: (cell) => getDGGSCellBounds(getA5Boundary(cell))
|
|
67
|
+
};
|
|
68
|
+
function getA5CellIndex(cell) {
|
|
69
|
+
return typeof cell === "bigint" ? cell : (0, import_a5_js.hexToU64)(removeHexPrefix(cell));
|
|
70
|
+
}
|
|
71
|
+
function getA5Boundary(cell) {
|
|
72
|
+
return (0, import_a5_js.cellToBoundary)(getA5CellIndex(cell)).map(([longitude, latitude]) => [longitude, latitude]);
|
|
73
|
+
}
|
|
74
|
+
function removeHexPrefix(token) {
|
|
75
|
+
return token.startsWith("0x") || token.startsWith("0X") ? token.slice(2) : token;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=a5.cjs.map
|
package/dist/a5.cjs.map
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/a5.ts", "../src/a5-decoder.ts", "../src/dggs-decoder.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACIA,mBAA+D;;;ACiDzD,SAAU,kBAAkB,UAA4B;AAC5D,MAAI,OAAO;AACX,MAAI,QAAQ;AACZ,MAAI,OAAO;AACX,MAAI,QAAQ;AAEZ,aAAW,CAAC,WAAW,QAAQ,KAAK,UAAU;AAC5C,WAAO,KAAK,IAAI,MAAM,SAAS;AAC/B,YAAQ,KAAK,IAAI,OAAO,QAAQ;AAChC,WAAO,KAAK,IAAI,MAAM,SAAS;AAC/B,YAAQ,KAAK,IAAI,OAAO,QAAQ;EAClC;AAEA,SAAO;IACL,CAAC,MAAM,KAAK;IACZ,CAAC,MAAM,KAAK;;AAEhB;;;AD7DO,IAAM,YAAY;EACvB,MAAM;EACN,0BAA0B;EAC1B,iBAAiB;IACf;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAEF,aAAa,CAAC,cAA0B,uBAAS,gBAAgB,KAAK,CAAC;EACvE,aAAa,CAAC,SACZ,OAAO,SAAS,WAAW,gBAAgB,IAAI,QAAI,uBAAS,IAAI;EAClE,cAAc,CAAC,aAAqC,2BAAa,eAAe,IAAI,CAAC;EACrF,gBAAgB,CAAC,SAAuC,cAAc,IAAI;EAC1E,oBAAoB,CAAC,SAA6B,cAAc,IAAI,EAAE,KAAI;EAC1E,cAAc,CAAC,SAA6B,kBAAkB,cAAc,IAAI,CAAC;;AAGnF,SAAS,eAAe,MAAc;AACpC,SAAO,OAAO,SAAS,WAAW,WAAO,uBAAS,gBAAgB,IAAI,CAAC;AACzE;AAEA,SAAS,cAAc,MAAc;AACnC,aAAO,6BAAe,eAAe,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,WAAW,QAAQ,MAAM,CAAC,WAAW,QAAQ,CAAC;AAClG;AAEA,SAAS,gBAAgB,OAAa;AACpC,SAAO,MAAM,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI;AAC7E;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/a5.d.ts
ADDED
package/dist/a5.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a5.d.ts","sourceRoot":"","sources":["../src/a5.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,SAAS,EAAC,wBAAqB"}
|
package/dist/a5.js
ADDED
package/dist/a5.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a5.js","sourceRoot":"","sources":["../src/a5.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,SAAS,EAAC,wBAAqB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type S2HeightInfo = {
|
|
2
|
+
minimumHeight: number;
|
|
3
|
+
maximumHeight: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Converts S2HeightInfo to corner points of an oriented bounding box
|
|
7
|
+
* Can be used to constuct an OrientedBoundingBox instance
|
|
8
|
+
*
|
|
9
|
+
* @param s2bv - s2 bounding volume to convert
|
|
10
|
+
* @param [result] Optional object onto which to store the result.
|
|
11
|
+
* @returns The modified result parameter or a new `OrientedBoundingBox` instance if not provided.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getS2OrientedBoundingBoxCornerPoints(s2token: string, // This can be an S2 key or token
|
|
14
|
+
heighInfo?: S2HeightInfo): number[][];
|
|
15
|
+
//# sourceMappingURL=s2-to-obb-points.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-obb-points.d.ts","sourceRoot":"","sources":["../../src/converters/s2-to-obb-points.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,MAAM,EAAE,iCAAiC;AAClD,SAAS,CAAC,EAAE,YAAY,GACvB,MAAM,EAAE,EAAE,CA2BZ"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getS2Cell } from "../s2-geometry/s2-geometry.js";
|
|
5
|
+
import { getS2Region } from "./s2-to-region.js";
|
|
6
|
+
import { getS2IndexFromToken } from "../s2-geometry/s2-token.js";
|
|
7
|
+
/**
|
|
8
|
+
* Converts S2HeightInfo to corner points of an oriented bounding box
|
|
9
|
+
* Can be used to constuct an OrientedBoundingBox instance
|
|
10
|
+
*
|
|
11
|
+
* @param s2bv - s2 bounding volume to convert
|
|
12
|
+
* @param [result] Optional object onto which to store the result.
|
|
13
|
+
* @returns The modified result parameter or a new `OrientedBoundingBox` instance if not provided.
|
|
14
|
+
*/
|
|
15
|
+
export function getS2OrientedBoundingBoxCornerPoints(s2token, // This can be an S2 key or token
|
|
16
|
+
heighInfo) {
|
|
17
|
+
const min = heighInfo?.minimumHeight || 0;
|
|
18
|
+
const max = heighInfo?.maximumHeight || 0;
|
|
19
|
+
const s2index = getS2IndexFromToken(s2token);
|
|
20
|
+
const s2cell = getS2Cell(s2index);
|
|
21
|
+
const region = getS2Region(s2cell);
|
|
22
|
+
// region is {lngWest, latSouth, lngEast, latNorth} in degrees
|
|
23
|
+
const W = region[0];
|
|
24
|
+
const S = region[1];
|
|
25
|
+
const E = region[2];
|
|
26
|
+
const N = region[3];
|
|
27
|
+
const points = [];
|
|
28
|
+
points.push([W, N, min]);
|
|
29
|
+
points.push([E, N, min]);
|
|
30
|
+
points.push([E, S, min]);
|
|
31
|
+
points.push([W, S, min]);
|
|
32
|
+
points.push([W, N, max]);
|
|
33
|
+
points.push([E, N, max]);
|
|
34
|
+
points.push([E, S, max]);
|
|
35
|
+
points.push([W, S, max]);
|
|
36
|
+
return points;
|
|
37
|
+
}
|
|
38
|
+
/*
|
|
39
|
+
function convertCartToXYZ(longitude, latitude, height, result?) {
|
|
40
|
+
const point = Ellipsoid.WGS84.cartographicToCartesian([longitude, latitude, height]);
|
|
41
|
+
return new Vector3(point[0], point[1], point[2]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Add a point that doesn't allow the box dive under the Earth
|
|
45
|
+
// This point is actually a center of a face that could be a tangent to the Earth surface if max==0
|
|
46
|
+
points.push(convertCartToXYZ((W + E) / 2.0, (S + N) / 2.0, max));
|
|
47
|
+
|
|
48
|
+
// points should be an array of Vector3 (XYZ)
|
|
49
|
+
// Passing result===null throws an exception from makeOrientedBoundingBoxFromPoints
|
|
50
|
+
const obb: OrientedBoundingBox = makeOrientedBoundingBoxFromPoints(
|
|
51
|
+
points,
|
|
52
|
+
result !== null ? result : undefined
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const box: number[] = [...obb.center, ...obb.halfAxes];
|
|
56
|
+
|
|
57
|
+
return box;
|
|
58
|
+
}
|
|
59
|
+
*/
|
|
60
|
+
//# sourceMappingURL=s2-to-obb-points.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-obb-points.js","sourceRoot":"","sources":["../../src/converters/s2-to-obb-points.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,SAAS,EAAC,sCAAmC;AACrD,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAC3C,OAAO,EAAC,mBAAmB,EAAC,mCAAgC;AAU5D;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,OAAe,EAAE,iCAAiC;AAClD,SAAwB;IAExB,MAAM,GAAG,GAAW,SAAS,EAAE,aAAa,IAAI,CAAC,CAAC;IAClD,MAAM,GAAG,GAAW,SAAS,EAAE,aAAa,IAAI,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAEnC,8DAA8D;IAC9D,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpB,MAAM,MAAM,GAAe,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACzB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;EAqBE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-region.d.ts","sourceRoot":"","sources":["../../src/converters/s2-to-region.ts"],"names":[],"mappings":"AAMA,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,EAAE,CAIjG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getS2GeoBoundsFromCell } from "../s2-geometry/s2-to-boundary.js";
|
|
5
|
+
export function getS2Region(s2cell) {
|
|
6
|
+
const corners = getS2GeoBoundsFromCell(s2cell);
|
|
7
|
+
const region = getRegionFromS2Corners(corners);
|
|
8
|
+
return region;
|
|
9
|
+
}
|
|
10
|
+
function getRegionFromS2Corners(corners) {
|
|
11
|
+
const longitudes = [];
|
|
12
|
+
const latitudes = [];
|
|
13
|
+
for (let i = 0; i < corners.length; i += 2) {
|
|
14
|
+
longitudes.push(corners[i]);
|
|
15
|
+
latitudes.push(corners[i + 1]);
|
|
16
|
+
}
|
|
17
|
+
longitudes.sort((a, b) => a - b);
|
|
18
|
+
latitudes.sort((a, b) => a - b);
|
|
19
|
+
// Return the region in degrees
|
|
20
|
+
return [
|
|
21
|
+
longitudes[0],
|
|
22
|
+
latitudes[0],
|
|
23
|
+
longitudes[longitudes.length - 1],
|
|
24
|
+
latitudes[latitudes.length - 1]
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=s2-to-region.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-region.js","sourceRoot":"","sources":["../../src/converters/s2-to-region.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,sBAAsB,EAAC,yCAAsC;AAErE,MAAM,UAAU,WAAW,CAAC,MAA2D;IACrF,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAqB;IACnD,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEhC,+BAA+B;IAC/B,OAAO;QACL,UAAU,CAAC,CAAC,CAAC;QACb,SAAS,CAAC,CAAC,CAAC;QACZ,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACjC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Bounds2D } from '@math.gl/types';
|
|
2
|
+
/** Cell identifiers used by the lightweight decoder API. */
|
|
3
|
+
export type DGGSCell = string | bigint;
|
|
4
|
+
/**
|
|
5
|
+
* A deliberately small common API for decoding DGGS and DGGS-like cell tokens.
|
|
6
|
+
* Decoder objects satisfy this interface so visualization code can use them interchangeably.
|
|
7
|
+
*/
|
|
8
|
+
export type DGGSDecoder = {
|
|
9
|
+
/** The name of the DGGS */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Whether cells have a 64-bit numeric representation. */
|
|
12
|
+
hasNumericRepresentation: boolean;
|
|
13
|
+
/** Conventional data column names that identify cells in this grid. */
|
|
14
|
+
cellColumnNames: readonly string[];
|
|
15
|
+
/** Convert a string token to a binary cell index. */
|
|
16
|
+
tokenToCell?: (token: string) => bigint;
|
|
17
|
+
/** Convert a cell to its string token. */
|
|
18
|
+
cellToToken?: (cell: DGGSCell) => string;
|
|
19
|
+
/** Return the center of the cell as `[longitude, latitude]`. */
|
|
20
|
+
cellToLngLat: (cell: DGGSCell) => [number, number];
|
|
21
|
+
/** Return the closed cell boundary as longitude/latitude pairs. */
|
|
22
|
+
cellToBoundary: (cell: DGGSCell) => [number, number][];
|
|
23
|
+
/** @returns the boundary of the cell, as a flat array */
|
|
24
|
+
cellToBoundaryFlat: (cell: DGGSCell) => number[];
|
|
25
|
+
/** @returns the longitude/latitude bounds of the cell */
|
|
26
|
+
cellToBounds: (cell: DGGSCell) => Bounds2D;
|
|
27
|
+
};
|
|
28
|
+
/** A cell column and the decoder selected for it. */
|
|
29
|
+
export type DGGSCellColumn = {
|
|
30
|
+
columnName: string;
|
|
31
|
+
decoder: DGGSDecoder;
|
|
32
|
+
};
|
|
33
|
+
/** Require a string cell identifier for string-only grids. */
|
|
34
|
+
export declare function getDGGSCellToken(cell: DGGSCell, gridName: string): string;
|
|
35
|
+
/** Calculate longitude/latitude bounds from a cell boundary. */
|
|
36
|
+
export declare function getDGGSCellBounds(boundary: [number, number][]): Bounds2D;
|
|
37
|
+
//# sourceMappingURL=dggs-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dggs-decoder.d.ts","sourceRoot":"","sources":["../src/dggs-decoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAE7C,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IAEb,0DAA0D;IAC1D,wBAAwB,EAAE,OAAO,CAAC;IAElC,uEAAuE;IACvE,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAEnC,qDAAqD;IACrD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,0CAA0C;IAC1C,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC;IACzC,gEAAgE;IAChE,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,mEAAmE;IACnE,cAAc,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAEvD,yDAAyD;IACzD,kBAAkB,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC;IACjD,yDAAyD;IACzD,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,QAAQ,CAAC;CAC5C,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,QAAQ,CAiBxE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Require a string cell identifier for string-only grids. */
|
|
5
|
+
export function getDGGSCellToken(cell, gridName) {
|
|
6
|
+
if (typeof cell !== 'string') {
|
|
7
|
+
throw new Error(`${gridName} cell identifiers must be strings`);
|
|
8
|
+
}
|
|
9
|
+
return cell;
|
|
10
|
+
}
|
|
11
|
+
/** Calculate longitude/latitude bounds from a cell boundary. */
|
|
12
|
+
export function getDGGSCellBounds(boundary) {
|
|
13
|
+
let west = Infinity;
|
|
14
|
+
let south = Infinity;
|
|
15
|
+
let east = -Infinity;
|
|
16
|
+
let north = -Infinity;
|
|
17
|
+
for (const [longitude, latitude] of boundary) {
|
|
18
|
+
west = Math.min(west, longitude);
|
|
19
|
+
south = Math.min(south, latitude);
|
|
20
|
+
east = Math.max(east, longitude);
|
|
21
|
+
north = Math.max(north, latitude);
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
[west, south],
|
|
25
|
+
[east, north]
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=dggs-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dggs-decoder.js","sourceRoot":"","sources":["../src/dggs-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AA0CpC,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,QAAgB;IAC/D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,mCAAmC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,QAA4B;IAC5D,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,KAAK,GAAG,QAAQ,CAAC;IACrB,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC;IACrB,IAAI,KAAK,GAAG,CAAC,QAAQ,CAAC;IAEtB,KAAK,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACjC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAClC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACjC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,CAAC,IAAI,EAAE,KAAK,CAAC;QACb,CAAC,IAAI,EAAE,KAAK,CAAC;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Bounds2D } from '@math.gl/types';
|
|
2
|
+
import { type DGGSCell } from "./dggs-decoder.js";
|
|
3
|
+
/** Decoder for the geohash dggs */
|
|
4
|
+
export declare const GeohashDecoder: {
|
|
5
|
+
readonly name: "geohash";
|
|
6
|
+
readonly hasNumericRepresentation: false;
|
|
7
|
+
readonly cellColumnNames: readonly ["geohash", "geohashId", "geohash_id"];
|
|
8
|
+
readonly cellToLngLat: (cell: DGGSCell) => [number, number];
|
|
9
|
+
readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
|
|
10
|
+
readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
|
|
11
|
+
readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @note Adapted from ngeohash decode_bbox
|
|
15
|
+
*/
|
|
16
|
+
export declare function getGeohashBounds(geohash: string): Bounds2D;
|
|
17
|
+
//# sourceMappingURL=geohash-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash-decoder.d.ts","sourceRoot":"","sources":["../src/geohash-decoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,KAAK,QAAQ,EAAqC,0BAAuB;AAEjF,mCAAmC;AACnC,eAAO,MAAM,cAAc;;;;kCAIJ,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCAEzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCAEzB,QAAQ,KAAG,MAAM,EAAE;kCAEzB,QAAQ,KAAG,QAAQ;CACV,CAAC;AAqCjC;;GAEG;AAEH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAsC1D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getDGGSCellToken } from "./dggs-decoder.js";
|
|
5
|
+
/** Decoder for the geohash dggs */
|
|
6
|
+
export const GeohashDecoder = {
|
|
7
|
+
name: 'geohash',
|
|
8
|
+
hasNumericRepresentation: false,
|
|
9
|
+
cellColumnNames: ['geohash', 'geohashId', 'geohash_id'],
|
|
10
|
+
cellToLngLat: (cell) => getGeohashLngLat(getDGGSCellToken(cell, 'GeoHash')),
|
|
11
|
+
cellToBoundary: (cell) => getGeohashBoundary(getDGGSCellToken(cell, 'GeoHash')),
|
|
12
|
+
cellToBoundaryFlat: (cell) => getGeohashBoundaryFlat(getDGGSCellToken(cell, 'GeoHash')),
|
|
13
|
+
cellToBounds: (cell) => getGeohashBounds(getDGGSCellToken(cell, 'GeoHash'))
|
|
14
|
+
};
|
|
15
|
+
const BASE32_CODES = '0123456789bcdefghjkmnpqrstuvwxyz';
|
|
16
|
+
const BASE32_CODES_DICT = {};
|
|
17
|
+
for (let i = 0; i < BASE32_CODES.length; i++) {
|
|
18
|
+
BASE32_CODES_DICT[BASE32_CODES.charAt(i)] = i;
|
|
19
|
+
}
|
|
20
|
+
const MIN_LAT = -90;
|
|
21
|
+
const MAX_LAT = 90;
|
|
22
|
+
const MIN_LON = -180;
|
|
23
|
+
const MAX_LON = 180;
|
|
24
|
+
/** Return center lng,lat of geohash cell */
|
|
25
|
+
function getGeohashLngLat(geohash) {
|
|
26
|
+
const [[w, s], [e, n]] = getGeohashBounds(geohash);
|
|
27
|
+
return [(e + w) / 2, (n + s) / 2];
|
|
28
|
+
}
|
|
29
|
+
/** Return boundary polygon of geohash cell as lng,lat array */
|
|
30
|
+
function getGeohashBoundary(geohash) {
|
|
31
|
+
const [[w, s], [e, n]] = getGeohashBounds(geohash);
|
|
32
|
+
return [
|
|
33
|
+
[e, n],
|
|
34
|
+
[e, s],
|
|
35
|
+
[w, s],
|
|
36
|
+
[w, n],
|
|
37
|
+
[e, n]
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/** Return boundary polygon of geohash cell as flat array */
|
|
41
|
+
function getGeohashBoundaryFlat(geohash) {
|
|
42
|
+
const [[w, s], [e, n]] = getGeohashBounds(geohash);
|
|
43
|
+
return [e, n, e, s, w, s, w, n, e, n];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @note Adapted from ngeohash decode_bbox
|
|
47
|
+
*/
|
|
48
|
+
/* eslint-disable max-depth */
|
|
49
|
+
export function getGeohashBounds(geohash) {
|
|
50
|
+
let isLon = true;
|
|
51
|
+
let maxLat = MAX_LAT;
|
|
52
|
+
let minLat = MIN_LAT;
|
|
53
|
+
let maxLon = MAX_LON;
|
|
54
|
+
let minLon = MIN_LON;
|
|
55
|
+
let mid;
|
|
56
|
+
let hashValue = 0;
|
|
57
|
+
for (let i = 0, l = geohash.length; i < l; i++) {
|
|
58
|
+
const code = geohash[i].toLowerCase();
|
|
59
|
+
hashValue = BASE32_CODES_DICT[code];
|
|
60
|
+
for (let bits = 4; bits >= 0; bits--) {
|
|
61
|
+
const bit = (hashValue >> bits) & 1;
|
|
62
|
+
if (isLon) {
|
|
63
|
+
mid = (maxLon + minLon) / 2;
|
|
64
|
+
if (bit === 1) {
|
|
65
|
+
minLon = mid;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
maxLon = mid;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
mid = (maxLat + minLat) / 2;
|
|
73
|
+
if (bit === 1) {
|
|
74
|
+
minLat = mid;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
maxLat = mid;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isLon = !isLon;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [
|
|
84
|
+
[minLon, minLat],
|
|
85
|
+
[maxLon, maxLat]
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=geohash-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash-decoder.js","sourceRoot":"","sources":["../src/geohash-decoder.ts"],"names":[],"mappings":"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"}
|