@mailwoman/spatial 8.1.0 → 8.3.0
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/bbox.ts +14 -3
- package/coordinate-formats.ts +58 -21
- package/feature.ts +1 -1
- package/geometries/point.ts +7 -5
- package/geometries/polygon.ts +5 -0
- package/h3/cell.ts +72 -0
- package/h3/index.ts +2 -60
- package/index.ts +1 -0
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +11 -3
- package/out/bbox.js.map +1 -1
- package/out/coordinate-formats.d.ts +18 -6
- package/out/coordinate-formats.d.ts.map +1 -1
- package/out/coordinate-formats.js +47 -21
- package/out/coordinate-formats.js.map +1 -1
- package/out/feature.d.ts +1 -1
- package/out/feature.d.ts.map +1 -1
- package/out/feature.js +1 -2
- package/out/feature.js.map +1 -1
- package/out/geometries/point.d.ts +2 -2
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +4 -2
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +4 -0
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +4 -0
- package/out/geometries/polygon.js.map +1 -1
- package/out/h3/cell.d.ts +37 -0
- package/out/h3/cell.d.ts.map +1 -0
- package/out/h3/cell.js +44 -0
- package/out/h3/cell.js.map +1 -0
- package/out/h3/index.d.ts +2 -26
- package/out/h3/index.d.ts.map +1 -1
- package/out/h3/index.js +2 -33
- package/out/h3/index.js.map +1 -1
- package/out/index.d.ts +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +1 -0
- package/out/index.js.map +1 -1
- package/out/polyline.d.ts +28 -0
- package/out/polyline.d.ts.map +1 -0
- package/out/polyline.js +58 -0
- package/out/polyline.js.map +1 -0
- package/out/position.d.ts +3 -3
- package/out/position.d.ts.map +1 -1
- package/out/position.js +24 -7
- package/out/position.js.map +1 -1
- package/out/sdk/well-known-text.d.ts.map +1 -1
- package/out/sdk/well-known-text.js.map +1 -1
- package/out/tsconfig.test.tsbuildinfo +1 -0
- package/out/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/polyline.ts +73 -0
- package/position.ts +30 -8
- package/sdk/well-known-text.ts +1 -0
package/bbox.ts
CHANGED
|
@@ -10,6 +10,16 @@ import type { PolygonLiteral, SolidPolygonPath } from "./geometries/polygon.ts"
|
|
|
10
10
|
import { clampLatitude, wrapLongitude } from "./position.ts"
|
|
11
11
|
import { CoordinateProjection } from "./projection.ts"
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Arity of a 2D bounding box: `[west, south, east, north]`.
|
|
15
|
+
*/
|
|
16
|
+
const BBOX_2D_LENGTH = 4
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Arity of a 3D bounding box: `[west, south, minElevation, east, north, maxElevation]`.
|
|
20
|
+
*/
|
|
21
|
+
const BBOX_3D_LENGTH = 6
|
|
22
|
+
|
|
13
23
|
//#region Bounding Box Literals
|
|
14
24
|
|
|
15
25
|
/**
|
|
@@ -116,7 +126,7 @@ export type BBox3DLiteral = [
|
|
|
116
126
|
* @category Bounding Box
|
|
117
127
|
*/
|
|
118
128
|
export function is2DBBox(input: unknown): input is BBox2DLiteral {
|
|
119
|
-
return Array.isArray(input) && input.length ===
|
|
129
|
+
return Array.isArray(input) && input.length === BBOX_2D_LENGTH
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
/**
|
|
@@ -128,7 +138,7 @@ export function is2DBBox(input: unknown): input is BBox2DLiteral {
|
|
|
128
138
|
* @category Bounding Box
|
|
129
139
|
*/
|
|
130
140
|
export function is3DBBox(input: unknown): input is BBox3DLiteral {
|
|
131
|
-
return Array.isArray(input) && input.length ===
|
|
141
|
+
return Array.isArray(input) && input.length === BBOX_3D_LENGTH
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
/**
|
|
@@ -138,7 +148,7 @@ export function is3DBBox(input: unknown): input is BBox3DLiteral {
|
|
|
138
148
|
* @category Bounding Box
|
|
139
149
|
*/
|
|
140
150
|
export function isBBox(input: unknown): input is BBox2DLiteral | BBox3DLiteral {
|
|
141
|
-
return Array.isArray(input) && (input.length ===
|
|
151
|
+
return Array.isArray(input) && (input.length === BBOX_2D_LENGTH || input.length === BBOX_3D_LENGTH)
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
/**
|
|
@@ -415,6 +425,7 @@ export class GeoBoundingBox {
|
|
|
415
425
|
*/
|
|
416
426
|
public to2DPolygon(): PolygonLiteral {
|
|
417
427
|
const { minLatitude, maxLatitude, minLongitude, maxLongitude } = this
|
|
428
|
+
|
|
418
429
|
const path: SolidPolygonPath = [
|
|
419
430
|
[
|
|
420
431
|
[minLongitude, minLatitude],
|
package/coordinate-formats.ts
CHANGED
|
@@ -11,6 +11,21 @@
|
|
|
11
11
|
|
|
12
12
|
import type { AnnotationSet, Annotator } from "@mailwoman/annotations"
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Bits packed into each base-32 geohash character.
|
|
16
|
+
*/
|
|
17
|
+
const GEOHASH_BITS_PER_CHAR = 5
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Southern limit of the MGRS lettered bands. Below it MGRS is undefined and the UPS grid applies instead.
|
|
21
|
+
*/
|
|
22
|
+
const MGRS_LAT_MIN = -80
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Northern limit of the MGRS lettered bands. Band X is extended to 84°, so there is no 84–90° band.
|
|
26
|
+
*/
|
|
27
|
+
const MGRS_LAT_MAX = 84
|
|
28
|
+
|
|
14
29
|
const toRad = (d: number): number => (d * Math.PI) / 180
|
|
15
30
|
const toDeg = (r: number): number => (r * 180) / Math.PI
|
|
16
31
|
|
|
@@ -28,14 +43,18 @@ function dmsComponent(value: number, hemispheres: [string, string], secondsDp =
|
|
|
28
43
|
return `${degrees}° ${minutes}′ ${seconds.toFixed(secondsDp)}″ ${hemisphere}`
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Degrees-minutes-seconds for a coordinate.
|
|
48
|
+
*/
|
|
32
49
|
export function toDMS(lat: number, lon: number): { lat: string; lon: string } {
|
|
33
50
|
return { lat: dmsComponent(lat, ["N", "S"]), lon: dmsComponent(lon, ["E", "W"]) }
|
|
34
51
|
}
|
|
35
52
|
|
|
36
|
-
const WEB_MERCATOR_R =
|
|
53
|
+
const WEB_MERCATOR_R = 6_378_137
|
|
37
54
|
|
|
38
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Web Mercator (EPSG:3857) projection of a coordinate.
|
|
57
|
+
*/
|
|
39
58
|
export function toMercator(lat: number, lon: number): { x: number; y: number } {
|
|
40
59
|
const clampedLat = Math.max(-85.05112878, Math.min(85.05112878, lat))
|
|
41
60
|
|
|
@@ -47,7 +66,9 @@ export function toMercator(lat: number, lon: number): { x: number; y: number } {
|
|
|
47
66
|
|
|
48
67
|
const KAABA = { lat: 21.4225, lon: 39.8262 }
|
|
49
68
|
|
|
50
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Initial great-circle bearing (degrees from true north) from a coordinate toward the Kaaba.
|
|
71
|
+
*/
|
|
51
72
|
export function qiblaBearing(lat: number, lon: number): number {
|
|
52
73
|
const phi1 = toRad(lat)
|
|
53
74
|
const phi2 = toRad(KAABA.lat)
|
|
@@ -60,7 +81,9 @@ export function qiblaBearing(lat: number, lon: number): number {
|
|
|
60
81
|
|
|
61
82
|
const GEOHASH_BASE32 = "0123456789bcdefghjkmnpqrstuvwxyz"
|
|
62
83
|
|
|
63
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Encode a coordinate as a geohash of the given precision (default 9 ≈ 4.8 m).
|
|
86
|
+
*/
|
|
64
87
|
export function toGeohash(lat: number, lon: number, precision = 9): string {
|
|
65
88
|
let latMin = -90
|
|
66
89
|
let latMax = 90
|
|
@@ -93,9 +116,10 @@ export function toGeohash(lat: number, lon: number, precision = 9): string {
|
|
|
93
116
|
latMax = mid
|
|
94
117
|
}
|
|
95
118
|
}
|
|
119
|
+
|
|
96
120
|
evenBit = !evenBit
|
|
97
121
|
|
|
98
|
-
if (++bit ===
|
|
122
|
+
if (++bit === GEOHASH_BITS_PER_CHAR) {
|
|
99
123
|
hash += GEOHASH_BASE32[bits]
|
|
100
124
|
bit = 0
|
|
101
125
|
bits = 0
|
|
@@ -107,10 +131,13 @@ export function toGeohash(lat: number, lon: number, precision = 9): string {
|
|
|
107
131
|
|
|
108
132
|
const A_CODE = "A".charCodeAt(0)
|
|
109
133
|
|
|
110
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Maidenhead grid locator (default 6-char: field uppercase, square digits, subsquare lowercase).
|
|
136
|
+
*/
|
|
111
137
|
export function toMaidenhead(lat: number, lon: number, pairs = 3): string {
|
|
112
138
|
const lonAdj = lon + 180
|
|
113
139
|
const latAdj = lat + 90
|
|
140
|
+
|
|
114
141
|
const out = [
|
|
115
142
|
String.fromCharCode(A_CODE + Math.floor(lonAdj / 20)),
|
|
116
143
|
String.fromCharCode(A_CODE + Math.floor(latAdj / 10)),
|
|
@@ -123,8 +150,8 @@ export function toMaidenhead(lat: number, lon: number, pairs = 3): string {
|
|
|
123
150
|
return out.slice(0, pairs * 2).join("")
|
|
124
151
|
}
|
|
125
152
|
|
|
126
|
-
const J2000 =
|
|
127
|
-
const unixEpochJulian =
|
|
153
|
+
const J2000 = 2_451_545
|
|
154
|
+
const unixEpochJulian = 2_440_587.5
|
|
128
155
|
|
|
129
156
|
/**
|
|
130
157
|
* Sunrise / solar-noon / sunset for a coordinate on a date, as UTC epoch seconds, via the standard sunrise equation.
|
|
@@ -136,7 +163,7 @@ export function sunTimes(
|
|
|
136
163
|
lon: number,
|
|
137
164
|
date: Date = new Date()
|
|
138
165
|
): { rise?: number; set?: number; noon: number } {
|
|
139
|
-
const julian = date.getTime() /
|
|
166
|
+
const julian = date.getTime() / 86_400_000 + unixEpochJulian
|
|
140
167
|
const n = Math.round(julian - J2000 - 0.0009 + lon / 360)
|
|
141
168
|
const meanSolarTime = n + 0.0009 - lon / 360
|
|
142
169
|
const M = (357.5291 + 0.98560028 * meanSolarTime) % 360
|
|
@@ -146,9 +173,11 @@ export function sunTimes(
|
|
|
146
173
|
const transit = J2000 + meanSolarTime + 0.0053 * Math.sin(Mr) - 0.0069 * Math.sin(2 * lambda)
|
|
147
174
|
const declination = Math.asin(Math.sin(lambda) * Math.sin(toRad(23.4397)))
|
|
148
175
|
const latR = toRad(lat)
|
|
176
|
+
|
|
149
177
|
const cosH =
|
|
150
178
|
(Math.sin(toRad(-0.833)) - Math.sin(latR) * Math.sin(declination)) / (Math.cos(latR) * Math.cos(declination))
|
|
151
|
-
|
|
179
|
+
|
|
180
|
+
const toEpoch = (j: number): number => Math.round((j - unixEpochJulian) * 86_400)
|
|
152
181
|
const noon = toEpoch(transit)
|
|
153
182
|
|
|
154
183
|
if (cosH >= 1 || cosH <= -1) return { noon }
|
|
@@ -157,8 +186,10 @@ export function sunTimes(
|
|
|
157
186
|
return { rise: toEpoch(transit - hourAngle / 360), set: toEpoch(transit + hourAngle / 360), noon }
|
|
158
187
|
}
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
|
|
189
|
+
/**
|
|
190
|
+
* MGRS / UTM (WGS84). The forward Transverse Mercator series + the military grid lettering.
|
|
191
|
+
*/
|
|
192
|
+
const UTM_A = 6_378_137
|
|
162
193
|
const UTM_F = 1 / 298.257223563
|
|
163
194
|
const UTM_K0 = 0.9996
|
|
164
195
|
const UTM_E2 = UTM_F * (2 - UTM_F)
|
|
@@ -172,15 +203,18 @@ function latLonToUtm(lat: number, lon: number): { zone: number; easting: number;
|
|
|
172
203
|
const T = Math.tan(phi) ** 2
|
|
173
204
|
const C = UTM_EP2 * Math.cos(phi) ** 2
|
|
174
205
|
const A = Math.cos(phi) * (toRad(lon) - lon0)
|
|
206
|
+
|
|
175
207
|
const M =
|
|
176
208
|
UTM_A *
|
|
177
209
|
((1 - UTM_E2 / 4 - (3 * UTM_E2 ** 2) / 64 - (5 * UTM_E2 ** 3) / 256) * phi -
|
|
178
210
|
((3 * UTM_E2) / 8 + (3 * UTM_E2 ** 2) / 32 + (45 * UTM_E2 ** 3) / 1024) * Math.sin(2 * phi) +
|
|
179
211
|
((15 * UTM_E2 ** 2) / 256 + (45 * UTM_E2 ** 3) / 1024) * Math.sin(4 * phi) -
|
|
180
212
|
((35 * UTM_E2 ** 3) / 3072) * Math.sin(6 * phi))
|
|
213
|
+
|
|
181
214
|
const easting =
|
|
182
215
|
UTM_K0 * N * (A + ((1 - T + C) * A ** 3) / 6 + ((5 - 18 * T + T ** 2 + 72 * C - 58 * UTM_EP2) * A ** 5) / 120) +
|
|
183
|
-
|
|
216
|
+
500_000
|
|
217
|
+
|
|
184
218
|
let northing =
|
|
185
219
|
UTM_K0 *
|
|
186
220
|
(M +
|
|
@@ -191,7 +225,7 @@ function latLonToUtm(lat: number, lon: number): { zone: number; easting: number;
|
|
|
191
225
|
((61 - 58 * T + T ** 2 + 600 * C - 330 * UTM_EP2) * A ** 6) / 720))
|
|
192
226
|
|
|
193
227
|
if (lat < 0) {
|
|
194
|
-
northing +=
|
|
228
|
+
northing += 10_000_000
|
|
195
229
|
}
|
|
196
230
|
|
|
197
231
|
return { zone, easting, northing }
|
|
@@ -205,23 +239,26 @@ const MGRS_ROW_LETTERS = "ABCDEFGHJKLMNPQRSTUV"
|
|
|
205
239
|
* Military Grid Reference System for a coordinate (`"18SUJ2340806479"`); `""` outside MGRS bands (±80°/84°).
|
|
206
240
|
*/
|
|
207
241
|
export function toMGRS(lat: number, lon: number): string {
|
|
208
|
-
if (lat <
|
|
242
|
+
if (lat < MGRS_LAT_MIN || lat > MGRS_LAT_MAX) return ""
|
|
209
243
|
const band = MGRS_LAT_BANDS[Math.floor((lat + 80) / 8)]!
|
|
210
244
|
const { zone, easting, northing } = latLonToUtm(lat, lon)
|
|
211
|
-
const colLetter = MGRS_COL_SETS[(zone - 1) % 3]![Math.floor(easting /
|
|
212
|
-
let row = Math.floor(northing /
|
|
245
|
+
const colLetter = MGRS_COL_SETS[(zone - 1) % 3]![Math.floor(easting / 100_000) - 1]!
|
|
246
|
+
let row = Math.floor(northing / 100_000) % 20
|
|
213
247
|
|
|
214
248
|
if (zone % 2 === 0) {
|
|
215
249
|
row = (row + 5) % 20
|
|
216
250
|
}
|
|
251
|
+
|
|
217
252
|
const rowLetter = MGRS_ROW_LETTERS[row]!
|
|
218
|
-
const e = String(Math.floor(easting %
|
|
219
|
-
const n = String(Math.floor(northing %
|
|
253
|
+
const e = String(Math.floor(easting % 100_000)).padStart(5, "0")
|
|
254
|
+
const n = String(Math.floor(northing % 100_000)).padStart(5, "0")
|
|
220
255
|
|
|
221
256
|
return `${zone}${band}${colLetter}${rowLetter}${e}${n}`
|
|
222
257
|
}
|
|
223
258
|
|
|
224
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* Fill the coordinate-format slice of an {@link AnnotationSet} from a `{lat, lon}`.
|
|
261
|
+
*/
|
|
225
262
|
export const coordinateFormatAnnotator: Annotator = ({ lat, lon, date }): Partial<AnnotationSet> => ({
|
|
226
263
|
dms: toDMS(lat, lon),
|
|
227
264
|
geohash: toGeohash(lat, lon),
|
package/feature.ts
CHANGED
package/geometries/point.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { convert as convertCoords } from "geo-coordinates-parser"
|
|
|
11
11
|
import { latLngToCell } from "h3-js"
|
|
12
12
|
|
|
13
13
|
import { type BBox2DLiteral, type BBox3DLiteral, GeoBoundingBox, isBBox } from "../bbox.ts"
|
|
14
|
-
import { type H3Cell, shortenH3Cell } from "../h3/
|
|
14
|
+
import { type H3Cell, shortenH3Cell } from "../h3/cell.ts"
|
|
15
15
|
import { type GeoObjectLiteral, GeometryType } from "../objects.ts"
|
|
16
16
|
import {
|
|
17
17
|
type InternalPointCoordinates,
|
|
@@ -153,9 +153,9 @@ export class GeoPoint implements PointLiteral {
|
|
|
153
153
|
this.#altitude = typeof altitude === "number" ? altitude : 0
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
#latitude
|
|
157
|
-
#longitude
|
|
158
|
-
#altitude
|
|
156
|
+
#latitude = 0
|
|
157
|
+
#longitude = 0
|
|
158
|
+
#altitude = 0
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* The longitude of the point in degrees, i.e. the x-coordinate.
|
|
@@ -249,6 +249,8 @@ export class GeoPoint implements PointLiteral {
|
|
|
249
249
|
constructor(input: GeoPointInput, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox)
|
|
250
250
|
constructor(input?: GeoPointInput, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox) {
|
|
251
251
|
if (isCoordPairLiteral(input)) {
|
|
252
|
+
// A ternary does not carry the narrowing through, and inferGeoJSONCoordOrder needs the 2-tuple.
|
|
253
|
+
// oxlint-disable-next-line unicorn/prefer-ternary -- the if/else is what narrows `input`
|
|
252
254
|
if (input.length === 2) {
|
|
253
255
|
this.coordinates = inferGeoJSONCoordOrder(input)
|
|
254
256
|
} else {
|
|
@@ -301,7 +303,7 @@ export class GeoPoint implements PointLiteral {
|
|
|
301
303
|
if (point.isNullIsland()) return null
|
|
302
304
|
|
|
303
305
|
return point
|
|
304
|
-
} catch
|
|
306
|
+
} catch {
|
|
305
307
|
return null
|
|
306
308
|
}
|
|
307
309
|
}
|
package/geometries/polygon.ts
CHANGED
|
@@ -132,6 +132,7 @@ export interface MultiPolygonLiteral<P extends PolygonPath = SolidPolygonPath> e
|
|
|
132
132
|
*/
|
|
133
133
|
coordinates: P[][]
|
|
134
134
|
}
|
|
135
|
+
|
|
135
136
|
/**
|
|
136
137
|
* Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
|
|
137
138
|
*/
|
|
@@ -176,6 +177,10 @@ export const OSMNodeTag = {
|
|
|
176
177
|
|
|
177
178
|
export type OSMNodeTag = (typeof OSMNodeTag)[keyof typeof OSMNodeTag]
|
|
178
179
|
|
|
180
|
+
/**
|
|
181
|
+
* OSM node tags that disqualify a node from being treated as residential — a node carrying one of these is
|
|
182
|
+
* infrastructure or commercial, whatever else it claims.
|
|
183
|
+
*/
|
|
179
184
|
export const ForbiddenResidentialOSMNodeTags: ReadonlySet<OSMNodeTag> = new Set<OSMNodeTag>([
|
|
180
185
|
OSMNodeTag.Shop,
|
|
181
186
|
OSMNodeTag.Brand,
|
package/h3/cell.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file H3 cell primitives — the index types and the widen/shorten conversions.
|
|
6
|
+
*
|
|
7
|
+
* Split out from `./index.ts` because these carry no dependency on `GeoPoint`, while the
|
|
8
|
+
* point-valued helpers there do. `geometries/point.ts` needs the primitives and is itself imported
|
|
9
|
+
* by `./index.ts`, so keeping them together closed an import cycle.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Tagged } from "type-fest"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A H3 cell index, full 64 bits.
|
|
16
|
+
*
|
|
17
|
+
* @type {string}
|
|
18
|
+
* @title H3 Cell Index
|
|
19
|
+
* @pattern ^[0-9a-f]{15}$
|
|
20
|
+
*/
|
|
21
|
+
export type H3Cell = Tagged<string, "H3Cell">
|
|
22
|
+
|
|
23
|
+
export function isH3Cell(value: string): value is H3Cell {
|
|
24
|
+
return /^[0-9a-f]{15}$/.test(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A H3 cell index, shortened to 48 bits.
|
|
29
|
+
*
|
|
30
|
+
* @type {string}
|
|
31
|
+
* @title H3 Cell Index (Short)
|
|
32
|
+
* @pattern ^[0-9a-f]{12}$
|
|
33
|
+
*/
|
|
34
|
+
export type H3CellShort = Tagged<string, "H3CellShort">
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Given a full H3 cell index, shorten it to 48 bits.
|
|
38
|
+
*/
|
|
39
|
+
export function shortenH3Cell(cell: H3Cell): H3CellShort {
|
|
40
|
+
// ...and convert it to a 48-bit cell address.
|
|
41
|
+
const cellBigInt = BigInt(`0x${cell}`)
|
|
42
|
+
// 8 f 2 aa 84 5a 18 ac 6b
|
|
43
|
+
// aa 84 5a 18 ac 6b
|
|
44
|
+
|
|
45
|
+
// Extract the cell address without the resolution
|
|
46
|
+
const h3CellShortBigInt = cellBigInt & 0xf_ff_ff_ff_ff_ff_ffn
|
|
47
|
+
|
|
48
|
+
const h3CellShortHex = h3CellShortBigInt.toString(16)
|
|
49
|
+
|
|
50
|
+
return h3CellShortHex as H3CellShort
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//2 aa 84 5a 18 ac 6b
|
|
54
|
+
|
|
55
|
+
// 8 f2 aa 84 5a 18 ac 6b
|
|
56
|
+
/**
|
|
57
|
+
* Given a short cell address, expand it to a full H3 cell index.
|
|
58
|
+
*/
|
|
59
|
+
export function expandH3Cell(h3CellShort: H3CellShort, resolution = 15): H3Cell {
|
|
60
|
+
// Convert the short cell address back to BigInt
|
|
61
|
+
const h3CellShortBigInt = BigInt(`0x${h3CellShort}`)
|
|
62
|
+
|
|
63
|
+
const resolutionHex = resolution.toString(16)
|
|
64
|
+
// Reassemble the H3 cell index portion...
|
|
65
|
+
const cellBigInt = h3CellShortBigInt << BigInt(8 * (15 - resolution))
|
|
66
|
+
// Back to a string...
|
|
67
|
+
const partialCell = cellBigInt.toString(16)
|
|
68
|
+
// Finally, we add the resolution back to the cell index.
|
|
69
|
+
const cell = `8${resolutionHex}${partialCell}`
|
|
70
|
+
|
|
71
|
+
return cell as H3Cell
|
|
72
|
+
}
|
package/h3/index.ts
CHANGED
|
@@ -5,69 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { cellToLatLng } from "h3-js"
|
|
8
|
-
import type { Tagged } from "type-fest"
|
|
9
8
|
|
|
10
9
|
import { GeoPoint, type PointLiteral } from "../geometries/point.ts"
|
|
10
|
+
import { type H3Cell, type H3CellShort, expandH3Cell } from "./cell.ts"
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
* A H3 cell index, full 64 bits.
|
|
14
|
-
*
|
|
15
|
-
* @type {string}
|
|
16
|
-
* @title H3 Cell Index
|
|
17
|
-
* @pattern ^[0-9a-f]{15}$
|
|
18
|
-
*/
|
|
19
|
-
export type H3Cell = Tagged<string, "H3Cell">
|
|
20
|
-
|
|
21
|
-
export function isH3Cell(value: string): value is H3Cell {
|
|
22
|
-
return /^[0-9a-f]{15}$/.test(value)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A H3 cell index, shortened to 48 bits.
|
|
27
|
-
*
|
|
28
|
-
* @type {string}
|
|
29
|
-
* @title H3 Cell Index (Short)
|
|
30
|
-
* @pattern ^[0-9a-f]{12}$
|
|
31
|
-
*/
|
|
32
|
-
export type H3CellShort = Tagged<string, "H3CellShort">
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Given a full H3 cell index, shorten it to 48 bits.
|
|
36
|
-
*/
|
|
37
|
-
export function shortenH3Cell(cell: H3Cell): H3CellShort {
|
|
38
|
-
// ...and convert it to a 48-bit cell address.
|
|
39
|
-
const cellBigInt = BigInt(`0x${cell}`)
|
|
40
|
-
// 8 f 2 aa 84 5a 18 ac 6b
|
|
41
|
-
// aa 84 5a 18 ac 6b
|
|
42
|
-
|
|
43
|
-
// Extract the cell address without the resolution
|
|
44
|
-
const h3CellShortBigInt = cellBigInt & 0xfffffffffffffn
|
|
45
|
-
|
|
46
|
-
const h3CellShortHex = h3CellShortBigInt.toString(16)
|
|
47
|
-
|
|
48
|
-
return h3CellShortHex as H3CellShort
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//2 aa 84 5a 18 ac 6b
|
|
52
|
-
|
|
53
|
-
// 8 f2 aa 84 5a 18 ac 6b
|
|
54
|
-
/**
|
|
55
|
-
* Given a short cell address, expand it to a full H3 cell index.
|
|
56
|
-
*/
|
|
57
|
-
export function expandH3Cell(h3CellShort: H3CellShort, resolution = 15): H3Cell {
|
|
58
|
-
// Convert the short cell address back to BigInt
|
|
59
|
-
const h3CellShortBigInt = BigInt(`0x${h3CellShort}`)
|
|
60
|
-
|
|
61
|
-
const resolutionHex = resolution.toString(16)
|
|
62
|
-
// Reassemble the H3 cell index portion...
|
|
63
|
-
const cellBigInt = h3CellShortBigInt << BigInt(8 * (15 - resolution))
|
|
64
|
-
// Back to a string...
|
|
65
|
-
const partialCell = cellBigInt.toString(16)
|
|
66
|
-
// Finally, we add the resolution back to the cell index.
|
|
67
|
-
const cell = `8${resolutionHex}${partialCell}`
|
|
68
|
-
|
|
69
|
-
return cell as H3Cell
|
|
70
|
-
}
|
|
12
|
+
export * from "./cell.ts"
|
|
71
13
|
|
|
72
14
|
/**
|
|
73
15
|
* Given a geographic point, return a short cell address.
|
package/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./geometries/index.ts"
|
|
|
12
12
|
export * from "./google/index.ts"
|
|
13
13
|
export * from "./h3/index.ts"
|
|
14
14
|
export * from "./objects.ts"
|
|
15
|
+
export * from "./polyline.ts"
|
|
15
16
|
export * from "./position.ts"
|
|
16
17
|
export * from "./projection.ts"
|
|
17
18
|
export * from "./regions/index.ts"
|
package/out/bbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,yBAAyB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IACI,QAAQ,IAAI,aAAa;IAYzB,MAAM,IAAI,aAAa,GAAG,aAAa;IAM9C;;OAEG;IACI,WAAW,IAAI,cAAc;IAgBpC;;;;OAIG;IACI,QAAQ,IAAI,MAAM;CAOzB"}
|
package/out/bbox.js
CHANGED
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { clampLatitude, wrapLongitude } from "./position.js";
|
|
9
9
|
import { CoordinateProjection } from "./projection.js";
|
|
10
|
+
/**
|
|
11
|
+
* Arity of a 2D bounding box: `[west, south, east, north]`.
|
|
12
|
+
*/
|
|
13
|
+
const BBOX_2D_LENGTH = 4;
|
|
14
|
+
/**
|
|
15
|
+
* Arity of a 3D bounding box: `[west, south, minElevation, east, north, maxElevation]`.
|
|
16
|
+
*/
|
|
17
|
+
const BBOX_3D_LENGTH = 6;
|
|
10
18
|
//#endregion
|
|
11
19
|
//#region Type Predicates
|
|
12
20
|
/**
|
|
@@ -18,7 +26,7 @@ import { CoordinateProjection } from "./projection.js";
|
|
|
18
26
|
* @category Bounding Box
|
|
19
27
|
*/
|
|
20
28
|
export function is2DBBox(input) {
|
|
21
|
-
return Array.isArray(input) && input.length ===
|
|
29
|
+
return Array.isArray(input) && input.length === BBOX_2D_LENGTH;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Type-predicate for 3-dimensional bounding boxes.
|
|
@@ -29,7 +37,7 @@ export function is2DBBox(input) {
|
|
|
29
37
|
* @category Bounding Box
|
|
30
38
|
*/
|
|
31
39
|
export function is3DBBox(input) {
|
|
32
|
-
return Array.isArray(input) && input.length ===
|
|
40
|
+
return Array.isArray(input) && input.length === BBOX_3D_LENGTH;
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* Type-predicate to determine if the given input is a bounding box.
|
|
@@ -38,7 +46,7 @@ export function is3DBBox(input) {
|
|
|
38
46
|
* @category Bounding Box
|
|
39
47
|
*/
|
|
40
48
|
export function isBBox(input) {
|
|
41
|
-
return Array.isArray(input) && (input.length ===
|
|
49
|
+
return Array.isArray(input) && (input.length === BBOX_2D_LENGTH || input.length === BBOX_3D_LENGTH);
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* Type-predicate to determine if the given input is a GeoBoundingBox instance.
|
package/out/bbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AA+
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAA;AA+FxB,YAAY;AAEZ,yBAAyB;AAEzB;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc,CAAA;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc,CAAA;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,cAAc,IAAI,KAAK,CAAC,MAAM,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9
9
|
* `@mailwoman/annotations` `Annotator`.
|
|
10
10
|
*/
|
|
11
11
|
import type { Annotator } from "@mailwoman/annotations";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Degrees-minutes-seconds for a coordinate.
|
|
14
|
+
*/
|
|
13
15
|
export declare function toDMS(lat: number, lon: number): {
|
|
14
16
|
lat: string;
|
|
15
17
|
lon: string;
|
|
16
18
|
};
|
|
17
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Web Mercator (EPSG:3857) projection of a coordinate.
|
|
21
|
+
*/
|
|
18
22
|
export declare function toMercator(lat: number, lon: number): {
|
|
19
23
|
x: number;
|
|
20
24
|
y: number;
|
|
21
25
|
};
|
|
22
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Initial great-circle bearing (degrees from true north) from a coordinate toward the Kaaba.
|
|
28
|
+
*/
|
|
23
29
|
export declare function qiblaBearing(lat: number, lon: number): number;
|
|
24
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Encode a coordinate as a geohash of the given precision (default 9 ≈ 4.8 m).
|
|
32
|
+
*/
|
|
25
33
|
export declare function toGeohash(lat: number, lon: number, precision?: number): string;
|
|
26
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Maidenhead grid locator (default 6-char: field uppercase, square digits, subsquare lowercase).
|
|
36
|
+
*/
|
|
27
37
|
export declare function toMaidenhead(lat: number, lon: number, pairs?: number): string;
|
|
28
38
|
/**
|
|
29
39
|
* Sunrise / solar-noon / sunset for a coordinate on a date, as UTC epoch seconds, via the standard sunrise equation.
|
|
@@ -39,6 +49,8 @@ export declare function sunTimes(lat: number, lon: number, date?: Date): {
|
|
|
39
49
|
* Military Grid Reference System for a coordinate (`"18SUJ2340806479"`); `""` outside MGRS bands (±80°/84°).
|
|
40
50
|
*/
|
|
41
51
|
export declare function toMGRS(lat: number, lon: number): string;
|
|
42
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Fill the coordinate-format slice of an {@link AnnotationSet} from a `{lat, lon}`.
|
|
54
|
+
*/
|
|
43
55
|
export declare const coordinateFormatAnnotator: Annotator;
|
|
44
56
|
//# sourceMappingURL=coordinate-formats.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-formats.d.ts","sourceRoot":"","sources":["../coordinate-formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"coordinate-formats.d.ts","sourceRoot":"","sources":["../coordinate-formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAkCtE;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAE5E;AAID;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAO7E;AAID;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ7D;AAID;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CA2CzE;AAID;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAcxE;AAKD;;;;GAIG;AACH,wBAAgB,QAAQ,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,IAAiB,GAC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