@mailwoman/spatial 9.4.0 → 10.1.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/README.md +2 -2
- package/lib/bbox.ts +41 -34
- package/lib/{coordinate-bounds.ts → coordinate/bounds.ts} +2 -2
- package/lib/{coordinate-formats.ts → coordinate/formats.ts} +11 -28
- package/lib/distance.ts +53 -27
- package/lib/feature.ts +2 -2
- package/lib/geometries/point.ts +41 -33
- package/lib/geometries/polygon.ts +24 -128
- package/lib/geometries/ring-blob.ts +33 -130
- package/lib/google/place-id.ts +4 -2
- package/lib/h3/cell.ts +21 -76
- package/lib/h3/coverage.ts +11 -7
- package/lib/h3/interior-cells.ts +13 -34
- package/lib/h3/polygon-cells.ts +59 -165
- package/lib/{h3/index.ts → h3.ts} +1 -1
- package/lib/index.ts +6 -6
- package/lib/objects.ts +6 -6
- package/lib/open-location-code.ts +11 -42
- package/lib/osgb36.ts +28 -187
- package/lib/polyline.ts +5 -3
- package/lib/position.ts +20 -4
- package/lib/projection/transform.ts +114 -0
- package/lib/projection.ts +1 -1
- package/lib/well-known-text.ts +8 -8
- package/out/bbox.d.ts +16 -13
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +32 -23
- package/out/bbox.js.map +1 -1
- package/out/{coordinate-bounds.d.ts → coordinate/bounds.d.ts} +3 -3
- package/out/coordinate/bounds.d.ts.map +1 -0
- package/out/{coordinate-bounds.js → coordinate/bounds.js} +3 -3
- package/out/coordinate/bounds.js.map +1 -0
- package/out/{coordinate-formats.d.ts → coordinate/formats.d.ts} +9 -12
- package/out/coordinate/formats.d.ts.map +1 -0
- package/out/{coordinate-formats.js → coordinate/formats.js} +12 -29
- package/out/coordinate/formats.js.map +1 -0
- package/out/distance.d.ts +48 -25
- package/out/distance.d.ts.map +1 -1
- package/out/distance.js +53 -27
- package/out/distance.js.map +1 -1
- package/out/feature.d.ts +2 -2
- package/out/feature.d.ts.map +1 -1
- package/out/geometries/point.d.ts +30 -22
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +35 -29
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +23 -122
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +13 -41
- package/out/geometries/polygon.js.map +1 -1
- package/out/geometries/ring-blob.d.ts +23 -109
- package/out/geometries/ring-blob.d.ts.map +1 -1
- package/out/geometries/ring-blob.js +29 -115
- package/out/geometries/ring-blob.js.map +1 -1
- package/out/{geometries/index.js → geometries.d.ts} +1 -1
- package/out/geometries.d.ts.map +1 -0
- package/out/{geometries/index.d.ts → geometries.js} +1 -1
- package/out/geometries.js.map +1 -0
- package/out/google/place-id.d.ts +4 -2
- package/out/google/place-id.d.ts.map +1 -1
- package/out/google/place-id.js.map +1 -1
- package/out/{google/index.d.ts → google.d.ts} +1 -1
- package/out/google.d.ts.map +1 -0
- package/out/{google/index.js → google.js} +1 -1
- package/out/google.js.map +1 -0
- package/out/h3/cell.d.ts +19 -73
- package/out/h3/cell.d.ts.map +1 -1
- package/out/h3/cell.js +20 -63
- package/out/h3/cell.js.map +1 -1
- package/out/h3/coverage.d.ts +11 -7
- package/out/h3/coverage.d.ts.map +1 -1
- package/out/h3/coverage.js +11 -7
- package/out/h3/coverage.js.map +1 -1
- package/out/h3/interior-cells.d.ts +9 -28
- package/out/h3/interior-cells.d.ts.map +1 -1
- package/out/h3/interior-cells.js +13 -32
- package/out/h3/interior-cells.js.map +1 -1
- package/out/h3/polygon-cells.d.ts +28 -120
- package/out/h3/polygon-cells.d.ts.map +1 -1
- package/out/h3/polygon-cells.js +48 -146
- package/out/h3/polygon-cells.js.map +1 -1
- package/out/{h3/index.d.ts → h3.d.ts} +2 -2
- package/out/h3.d.ts.map +1 -0
- package/out/{h3/index.js → h3.js} +2 -2
- package/out/h3.js.map +1 -0
- package/out/index.d.ts +6 -6
- package/out/index.d.ts.map +1 -1
- package/out/index.js +6 -6
- package/out/index.js.map +1 -1
- package/out/objects.d.ts +6 -6
- package/out/objects.d.ts.map +1 -1
- package/out/open-location-code.d.ts +11 -22
- package/out/open-location-code.d.ts.map +1 -1
- package/out/open-location-code.js +9 -40
- package/out/open-location-code.js.map +1 -1
- package/out/osgb36.d.ts +21 -97
- package/out/osgb36.d.ts.map +1 -1
- package/out/osgb36.js +12 -165
- package/out/osgb36.js.map +1 -1
- package/out/polyline.d.ts +5 -3
- package/out/polyline.d.ts.map +1 -1
- package/out/polyline.js +5 -3
- package/out/polyline.js.map +1 -1
- package/out/position.d.ts +17 -3
- package/out/position.d.ts.map +1 -1
- package/out/position.js +2 -2
- package/out/position.js.map +1 -1
- package/out/projection/transform.d.ts +70 -0
- package/out/projection/transform.d.ts.map +1 -0
- package/out/{projection-transform.js → projection/transform.js} +15 -17
- package/out/projection/transform.js.map +1 -0
- package/out/projection.d.ts +1 -1
- package/out/projection.d.ts.map +1 -1
- package/out/projection.js +1 -1
- package/out/regions/codes.d.ts.map +1 -1
- package/out/{regions/index.js → regions.d.ts} +1 -1
- package/out/regions.d.ts.map +1 -0
- package/out/{regions/index.d.ts → regions.js} +1 -1
- package/out/regions.js.map +1 -0
- package/out/tools/ogr/stream.d.ts +44 -0
- package/out/tools/ogr/stream.d.ts.map +1 -0
- package/out/tools/{ogr-stream.js → ogr/stream.js} +17 -10
- package/out/tools/ogr/stream.js.map +1 -0
- package/out/tools/ogr.d.ts +13 -10
- package/out/tools/ogr.d.ts.map +1 -1
- package/out/tools/ogr.js +18 -14
- package/out/tools/ogr.js.map +1 -1
- package/out/tools/tsconfig.tsbuildinfo +1 -0
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/out/well-known-text.d.ts +8 -8
- package/out/well-known-text.js +7 -7
- package/package.json +35 -127
- package/{lib/tools/ogr-stream.ts → tools/ogr/stream.ts} +25 -14
- package/{lib/tools → tools}/ogr.ts +26 -20
- package/lib/projection-transform.ts +0 -115
- package/out/coordinate-bounds.d.ts.map +0 -1
- package/out/coordinate-bounds.js.map +0 -1
- package/out/coordinate-formats.d.ts.map +0 -1
- package/out/coordinate-formats.js.map +0 -1
- package/out/geometries/index.d.ts.map +0 -1
- package/out/geometries/index.js.map +0 -1
- package/out/google/index.d.ts.map +0 -1
- package/out/google/index.js.map +0 -1
- package/out/h3/index.d.ts.map +0 -1
- package/out/h3/index.js.map +0 -1
- package/out/projection-transform.d.ts +0 -67
- package/out/projection-transform.d.ts.map +0 -1
- package/out/projection-transform.js.map +0 -1
- package/out/regions/index.d.ts.map +0 -1
- package/out/regions/index.js.map +0 -1
- package/out/tools/ogr-stream.d.ts +0 -34
- package/out/tools/ogr-stream.d.ts.map +0 -1
- package/out/tools/ogr-stream.js.map +0 -1
- /package/lib/{geometries/index.ts → geometries.ts} +0 -0
- /package/lib/{google/index.ts → google.ts} +0 -0
- /package/lib/{regions/index.ts → regions.ts} +0 -0
package/out/bbox.js
CHANGED
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
* GeoJSON Bounding Boxes
|
|
7
7
|
*/
|
|
8
|
-
import { toRad } from "#coordinate
|
|
8
|
+
import { toRad } from "#coordinate/formats";
|
|
9
9
|
import { clampLatitude, wrapLongitude } from "#position";
|
|
10
10
|
import { CoordinateProjection } from "#projection";
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Kilometers per degree of latitude.
|
|
13
|
+
* The value is nearly constant on a sphere.
|
|
13
14
|
*/
|
|
14
15
|
const KM_PER_DEGREE_LATITUDE = 111;
|
|
15
16
|
/**
|
|
16
|
-
* Floor for cos(latitude) so a polar bbox stays finite.
|
|
17
|
+
* Floor for cos(latitude) so a polar bbox stays finite.
|
|
18
|
+
*
|
|
19
|
+
* See {@linkcode bboxAround}.
|
|
17
20
|
*/
|
|
18
21
|
const MIN_COS_LATITUDE = 1e-6;
|
|
19
22
|
/**
|
|
@@ -24,8 +27,8 @@ const BBOX_2D_LENGTH = 4;
|
|
|
24
27
|
* Arity of a 3D bounding box: `[west, south, minElevation, east, north, maxElevation]`.
|
|
25
28
|
*/
|
|
26
29
|
const BBOX_3D_LENGTH = 6;
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
// #endregion
|
|
31
|
+
// #region Type Predicates
|
|
29
32
|
/**
|
|
30
33
|
* Type-predicate for 2-dimensional bounding boxes (`[west, south, east, north]`).
|
|
31
34
|
*
|
|
@@ -60,8 +63,8 @@ export function isBBox(input) {
|
|
|
60
63
|
/**
|
|
61
64
|
* Type-predicate to determine if the given input is a GeoBoundingBox instance.
|
|
62
65
|
*
|
|
63
|
-
* Note that this function only checks if the input is an instance of the GeoBoundingBox class.
|
|
64
|
-
* not reliable in JavaScript, so this function should be used with caution.
|
|
66
|
+
* Note that this function only checks if the input is an instance of the GeoBoundingBox class.
|
|
67
|
+
* `instanceof` checks are not reliable in JavaScript, so this function should be used with caution.
|
|
65
68
|
*
|
|
66
69
|
* @category GeoJSON
|
|
67
70
|
*/
|
|
@@ -72,11 +75,11 @@ export function isGeoBoundingBox(input) {
|
|
|
72
75
|
/**
|
|
73
76
|
* A bounding box to represent the coordinate range of a GeoJSON object.
|
|
74
77
|
*
|
|
75
|
-
* This is useful when defining the extent of a GeoJSON object, such as the minimum
|
|
76
|
-
* object's Geometries, Features, or Feature Collections.
|
|
78
|
+
* This is useful when defining the extent of a GeoJSON object, such as the minimum
|
|
79
|
+
* and maximum coordinates of the object's Geometries, Features, or Feature Collections.
|
|
77
80
|
*/
|
|
78
81
|
export class GeoBoundingBox {
|
|
79
|
-
|
|
82
|
+
// #region Properties
|
|
80
83
|
projection;
|
|
81
84
|
/**
|
|
82
85
|
* The most western longitude (in decimal degrees) of the coordinate range.
|
|
@@ -114,8 +117,8 @@ export class GeoBoundingBox {
|
|
|
114
117
|
* Altitude of the most eastern longitude (in decimal degrees) of the coordinate range.
|
|
115
118
|
*/
|
|
116
119
|
#maxAltitude;
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
// #endregion
|
|
121
|
+
// #region Accessors
|
|
119
122
|
get minLongitude() {
|
|
120
123
|
return this.#minLongitude;
|
|
121
124
|
}
|
|
@@ -213,16 +216,16 @@ export class GeoBoundingBox {
|
|
|
213
216
|
this.#maxAltitude = maxAltitude;
|
|
214
217
|
this.projection = projection ?? CoordinateProjection.WGS84;
|
|
215
218
|
}
|
|
216
|
-
|
|
217
|
-
|
|
219
|
+
// #endregion
|
|
220
|
+
// #region Predicates
|
|
218
221
|
is3D() {
|
|
219
222
|
return this.#minAltitude !== 0 || this.#maxAltitude !== 0;
|
|
220
223
|
}
|
|
221
224
|
is2D() {
|
|
222
225
|
return !this.is3D();
|
|
223
226
|
}
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
// #endregion
|
|
228
|
+
// #region Conversion
|
|
226
229
|
/**
|
|
227
230
|
* Converts the 2D GeoBoundingBox to an array literal.
|
|
228
231
|
*/
|
|
@@ -283,15 +286,21 @@ export class GeoBoundingBox {
|
|
|
283
286
|
/**
|
|
284
287
|
* Approximate bounds `radiusKM` in each direction around a point.
|
|
285
288
|
*
|
|
286
|
-
* The spherical-Earth equirectangular approximation: 1° latitude ≈ 111 km globally,
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
289
|
+
* The spherical-Earth equirectangular approximation: 1° latitude ≈ 111 km globally,
|
|
290
|
+
* 1° longitude ≈ 111 km × cos(lat).
|
|
291
|
+
* It is a filter rather than an answer.
|
|
292
|
+
*
|
|
293
|
+
* It over-selects near the poles and along a long east-west span.
|
|
294
|
+
* Callers must re-check survivors with an exact haversine distance.
|
|
295
|
+
*
|
|
296
|
+
* The approximation may admit points outside the radius.
|
|
297
|
+
* It includes every point within the radius.
|
|
290
298
|
*/
|
|
291
299
|
export function bboxAround(lat, lon, radiusKM) {
|
|
292
300
|
const latDelta = radiusKM / KM_PER_DEGREE_LATITUDE;
|
|
293
|
-
// cos(±90°) is 0
|
|
294
|
-
//
|
|
301
|
+
// cos(±90°) is 0.
|
|
302
|
+
// A zero denominator would make the longitude delta infinite and select the whole globe.
|
|
303
|
+
// Clamp so a polar query stays a wide band rather than becoming unbounded.
|
|
295
304
|
const cosLat = Math.max(Math.cos(toRad(lat)), MIN_COS_LATITUDE);
|
|
296
305
|
const lonDelta = radiusKM / (KM_PER_DEGREE_LATITUDE * cosLat);
|
|
297
306
|
return {
|
|
@@ -301,5 +310,5 @@ export function bboxAround(lat, lon, radiusKM) {
|
|
|
301
310
|
maxLon: lon + lonDelta,
|
|
302
311
|
};
|
|
303
312
|
}
|
|
304
|
-
|
|
313
|
+
// #endregion
|
|
305
314
|
//# sourceMappingURL=bbox.js.map
|
package/out/bbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../lib/bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../lib/bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAElC;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAE7B;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAA;AAgGxB,aAAa;AAEb,0BAA0B;AAE1B;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,O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I,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,CAAA;IAC9C,CAAC;IAED;;;;OAIG;IACI,QAAQ;QACd,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,IAAI,CAAA;QAErE,OAAO,QAAQ,IAAI,CAAC,UAAU,aAAa,YAAY,IAAI,WAAW,KAAK,YAAY,IAAI,WAAW,KAAK,YAAY,IAAI,WAAW,KAAK,YAAY,IAAI,WAAW,KAAK,YAAY,IAAI,WAAW,IAAI,CAAA;IAC3M,CAAC;CAGD;AAcD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW,EAAE,QAAgB;IACpE,MAAM,QAAQ,GAAG,QAAQ,GAAG,sBAAsB,CAAA;IAClD,kBAAkB;IAClB,yFAAyF;IACzF,2EAA2E;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,QAAQ,GAAG,CAAC,sBAAsB,GAAG,MAAM,CAAC,CAAA;IAE7D,OAAO;QACN,MAAM,EAAE,GAAG,GAAG,QAAQ;QACtB,MAAM,EAAE,GAAG,GAAG,QAAQ;QACtB,MAAM,EAAE,GAAG,GAAG,QAAQ;QACtB,MAAM,EAAE,GAAG,GAAG,QAAQ;KACtB,CAAA;AACF,CAAC;AAED,aAAa"}
|
|
@@ -22,8 +22,8 @@ export declare const LONGITUDE_MIN = -180;
|
|
|
22
22
|
*/
|
|
23
23
|
export declare const LONGITUDE_MAX = 180;
|
|
24
24
|
/**
|
|
25
|
-
* Southern limit of the Web Mercator projection in WGS-84 degrees — the latitude at
|
|
26
|
-
* vertical extent equals its horizontal one.
|
|
25
|
+
* Southern limit of the Web Mercator projection in WGS-84 degrees — the latitude at
|
|
26
|
+
* which the square projection's vertical extent equals its horizontal one.
|
|
27
27
|
*/
|
|
28
28
|
export declare const MERCATOR_LATITUDE_MIN = -85.05112878;
|
|
29
29
|
/**
|
|
@@ -38,4 +38,4 @@ export declare function isValidLatitude(value: number): boolean;
|
|
|
38
38
|
* Whether a finite number is a longitude on the globe, including the antimeridian.
|
|
39
39
|
*/
|
|
40
40
|
export declare function isValidLongitude(value: number): boolean;
|
|
41
|
-
//# sourceMappingURL=
|
|
41
|
+
//# sourceMappingURL=bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../lib/coordinate/bounds.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,YAAY,MAAM,CAAA;AAE/B;;GAEG;AACH,eAAO,MAAM,YAAY,KAAK,CAAA;AAE9B;;GAEG;AACH,eAAO,MAAM,aAAa,OAAO,CAAA;AAEjC;;GAEG;AACH,eAAO,MAAM,aAAa,MAAM,CAAA;AAEhC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAA;AAEjD;;GAEG;AACH,eAAO,MAAM,qBAAqB,cAAc,CAAA;AAEhD;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|
|
@@ -22,8 +22,8 @@ export const LONGITUDE_MIN = -180;
|
|
|
22
22
|
*/
|
|
23
23
|
export const LONGITUDE_MAX = 180;
|
|
24
24
|
/**
|
|
25
|
-
* Southern limit of the Web Mercator projection in WGS-84 degrees — the latitude at
|
|
26
|
-
* vertical extent equals its horizontal one.
|
|
25
|
+
* Southern limit of the Web Mercator projection in WGS-84 degrees — the latitude at
|
|
26
|
+
* which the square projection's vertical extent equals its horizontal one.
|
|
27
27
|
*/
|
|
28
28
|
export const MERCATOR_LATITUDE_MIN = -85.05112878;
|
|
29
29
|
/**
|
|
@@ -42,4 +42,4 @@ export function isValidLatitude(value) {
|
|
|
42
42
|
export function isValidLongitude(value) {
|
|
43
43
|
return Number.isFinite(value) && value >= LONGITUDE_MIN && value <= LONGITUDE_MAX;
|
|
44
44
|
}
|
|
45
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../lib/coordinate/bounds.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,CAAA;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAA;AAE9B;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,CAAA;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEhC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,WAAW,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAA;AAEhD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,YAAY,IAAI,KAAK,IAAI,YAAY,CAAA;AAChF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,aAAa,IAAI,KAAK,IAAI,aAAa,CAAA;AAClF,CAAC"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Coordinate-format conversions — the pure-math annotators OpenCage exposes (DMS, geohash,
|
|
7
|
-
* Maidenhead, MGRS, Web Mercator, qibla bearing, sun times). No data, no I/O; each is a
|
|
8
|
-
* deterministic function of a `{lat, lon}`. {@link coordinateFormatAnnotator} packages them as an
|
|
9
|
-
* `@mailwoman/annotations` `Annotator`.
|
|
10
5
|
*/
|
|
11
6
|
import type { Annotator } from "@mailwoman/annotations";
|
|
12
7
|
/**
|
|
@@ -25,7 +20,7 @@ export declare function toDMS(lat: number, lon: number): {
|
|
|
25
20
|
lon: string;
|
|
26
21
|
};
|
|
27
22
|
/**
|
|
28
|
-
* Web Mercator (
|
|
23
|
+
* Web Mercator (epsg:3857) projection of a coordinate.
|
|
29
24
|
*/
|
|
30
25
|
export declare function toMercator(lat: number, lon: number): {
|
|
31
26
|
x: number;
|
|
@@ -44,9 +39,10 @@ export declare function toGeohash(lat: number, lon: number, precision?: number):
|
|
|
44
39
|
*/
|
|
45
40
|
export declare function toMaidenhead(lat: number, lon: number, pairs?: number): string;
|
|
46
41
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
42
|
+
* Computes sunrise, solar noon and sunset for a coordinate and date as UTC epoch
|
|
43
|
+
* seconds using the standard sunrise equation.
|
|
44
|
+
*
|
|
45
|
+
* `rise` and `set` are omitted during polar day or polar night, while `noon` is always present.
|
|
50
46
|
*/
|
|
51
47
|
export declare function sunTimes(lat: number, lon: number, date?: Date): {
|
|
52
48
|
rise?: number;
|
|
@@ -54,11 +50,12 @@ export declare function sunTimes(lat: number, lon: number, date?: Date): {
|
|
|
54
50
|
noon: number;
|
|
55
51
|
};
|
|
56
52
|
/**
|
|
57
|
-
* Military Grid Reference System
|
|
53
|
+
* Formats a coordinate as a Military Grid Reference System string such as `"18SUJ2340806479"`,
|
|
54
|
+
* or returns `""` outside latitudes −80° to 84°.
|
|
58
55
|
*/
|
|
59
56
|
export declare function toMGRS(lat: number, lon: number): string;
|
|
60
57
|
/**
|
|
61
|
-
* Fill the coordinate-format
|
|
58
|
+
* Fill the coordinate-format fields of an {@link AnnotationSet} from a `{lat, lon}`.
|
|
62
59
|
*/
|
|
63
60
|
export declare const coordinateFormatAnnotator: Annotator;
|
|
64
|
-
//# sourceMappingURL=
|
|
61
|
+
//# sourceMappingURL=formats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../lib/coordinate/formats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAUtE;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAaD;;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;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,IAAiB,GACrB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAsB/C;AAgDD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAiBvD;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,SAQtC,CAAA"}
|
|
@@ -2,24 +2,10 @@
|
|
|
2
2
|
* @copyright Sister Software
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Coordinate-format conversions — the pure-math annotators OpenCage exposes (DMS, geohash,
|
|
7
|
-
* Maidenhead, MGRS, Web Mercator, qibla bearing, sun times). No data, no I/O; each is a
|
|
8
|
-
* deterministic function of a `{lat, lon}`. {@link coordinateFormatAnnotator} packages them as an
|
|
9
|
-
* `@mailwoman/annotations` `Annotator`.
|
|
10
|
-
*/
|
|
11
|
-
import { MERCATOR_LATITUDE_MAX, MERCATOR_LATITUDE_MIN } from "#coordinate-bounds";
|
|
12
|
-
/**
|
|
13
|
-
* Bits packed into each base-32 geohash character.
|
|
14
5
|
*/
|
|
6
|
+
import { MERCATOR_LATITUDE_MAX, MERCATOR_LATITUDE_MIN } from "#coordinate/bounds";
|
|
15
7
|
const GEOHASH_BITS_PER_CHAR = 5;
|
|
16
|
-
/**
|
|
17
|
-
* Southern limit of the MGRS lettered bands. Below it MGRS is undefined and the UPS grid applies instead.
|
|
18
|
-
*/
|
|
19
8
|
const MGRS_LAT_MIN = -80;
|
|
20
|
-
/**
|
|
21
|
-
* Northern limit of the MGRS lettered bands. Band X is extended to 84°, so there is no 84–90° band.
|
|
22
|
-
*/
|
|
23
9
|
const MGRS_LAT_MAX = 84;
|
|
24
10
|
/**
|
|
25
11
|
* WGS-84 degrees → radians.
|
|
@@ -33,9 +19,6 @@ export function toRad(deg) {
|
|
|
33
19
|
export function toDeg(rad) {
|
|
34
20
|
return (rad * 180) / Math.PI;
|
|
35
21
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Render a single signed degree as `D° M′ S″ H` with the given hemisphere letters `[positive, negative]`.
|
|
38
|
-
*/
|
|
39
22
|
function dmsComponent(value, hemispheres, secondsDp = 2) {
|
|
40
23
|
const hemisphere = value >= 0 ? hemispheres[0] : hemispheres[1];
|
|
41
24
|
const abs = Math.abs(value);
|
|
@@ -53,7 +36,7 @@ export function toDMS(lat, lon) {
|
|
|
53
36
|
}
|
|
54
37
|
const WEB_MERCATOR_R = 6_378_137;
|
|
55
38
|
/**
|
|
56
|
-
* Web Mercator (
|
|
39
|
+
* Web Mercator (epsg:3857) projection of a coordinate.
|
|
57
40
|
*/
|
|
58
41
|
export function toMercator(lat, lon) {
|
|
59
42
|
const clampedLat = Math.max(MERCATOR_LATITUDE_MIN, Math.min(MERCATOR_LATITUDE_MAX, lat));
|
|
@@ -139,9 +122,10 @@ export function toMaidenhead(lat, lon, pairs = 3) {
|
|
|
139
122
|
const J2000 = 2_451_545;
|
|
140
123
|
const unixEpochJulian = 2_440_587.5;
|
|
141
124
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
125
|
+
* Computes sunrise, solar noon and sunset for a coordinate and date as UTC epoch
|
|
126
|
+
* seconds using the standard sunrise equation.
|
|
127
|
+
*
|
|
128
|
+
* `rise` and `set` are omitted during polar day or polar night, while `noon` is always present.
|
|
145
129
|
*/
|
|
146
130
|
export function sunTimes(lat, lon, date = new Date()) {
|
|
147
131
|
const julian = date.getTime() / 86_400_000 + unixEpochJulian;
|
|
@@ -162,9 +146,6 @@ export function sunTimes(lat, lon, date = new Date()) {
|
|
|
162
146
|
const hourAngle = toDeg(Math.acos(cosH));
|
|
163
147
|
return { rise: toEpoch(transit - hourAngle / 360), set: toEpoch(transit + hourAngle / 360), noon };
|
|
164
148
|
}
|
|
165
|
-
/**
|
|
166
|
-
* MGRS / UTM (WGS84). The forward Transverse Mercator series + the military grid lettering.
|
|
167
|
-
*/
|
|
168
149
|
const UTM_A = 6_378_137;
|
|
169
150
|
const UTM_F = 1 / 298.257223563;
|
|
170
151
|
const UTM_K0 = 0.9996;
|
|
@@ -201,12 +182,14 @@ const MGRS_LAT_BANDS = "CDEFGHJKLMNPQRSTUVWX";
|
|
|
201
182
|
const MGRS_COL_SETS = ["ABCDEFGH", "JKLMNPQR", "STUVWXYZ"];
|
|
202
183
|
const MGRS_ROW_LETTERS = "ABCDEFGHJKLMNPQRSTUV";
|
|
203
184
|
/**
|
|
204
|
-
* Military Grid Reference System
|
|
185
|
+
* Formats a coordinate as a Military Grid Reference System string such as `"18SUJ2340806479"`,
|
|
186
|
+
* or returns `""` outside latitudes −80° to 84°.
|
|
205
187
|
*/
|
|
206
188
|
export function toMGRS(lat, lon) {
|
|
207
189
|
if (lat < MGRS_LAT_MIN || lat > MGRS_LAT_MAX)
|
|
208
190
|
return "";
|
|
209
|
-
|
|
191
|
+
// Band X spans 72° to 84°, so 80° and above still maps to the last band.
|
|
192
|
+
const band = MGRS_LAT_BANDS[Math.min(Math.floor((lat + 80) / 8), MGRS_LAT_BANDS.length - 1)];
|
|
210
193
|
const { zone, easting, northing } = latLonToUtm(lat, lon);
|
|
211
194
|
const colLetter = MGRS_COL_SETS[(zone - 1) % 3][Math.floor(easting / 100_000) - 1];
|
|
212
195
|
let row = Math.floor(northing / 100_000) % 20;
|
|
@@ -219,7 +202,7 @@ export function toMGRS(lat, lon) {
|
|
|
219
202
|
return `${zone}${band}${colLetter}${rowLetter}${e}${n}`;
|
|
220
203
|
}
|
|
221
204
|
/**
|
|
222
|
-
* Fill the coordinate-format
|
|
205
|
+
* Fill the coordinate-format fields of an {@link AnnotationSet} from a `{lat, lon}`.
|
|
223
206
|
*/
|
|
224
207
|
export const coordinateFormatAnnotator = ({ lat, lon, date }) => ({
|
|
225
208
|
dms: toDMS(lat, lon),
|
|
@@ -230,4 +213,4 @@ export const coordinateFormatAnnotator = ({ lat, lon, date }) => ({
|
|
|
230
213
|
qiblaBearing: qiblaBearing(lat, lon),
|
|
231
214
|
sun: sunTimes(lat, lon, date),
|
|
232
215
|
});
|
|
233
|
-
//# sourceMappingURL=
|
|
216
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../lib/coordinate/formats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAEjF,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAE/B,MAAM,YAAY,GAAG,CAAC,EAAE,CAAA;AAExB,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW;IAChC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAA;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW;IAChC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAA;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,KAAa,EAAE,WAA6B,EAAE,SAAS,GAAG,CAAC;IAChF,MAAM,UAAU,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/B,MAAM,WAAW,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IACxC,MAAM,OA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|
23
23
|
export type EarthRadiusUnit = "km" | "miles" | "meters";
|
|
24
24
|
export type PlanetaryBodyID = "earth" | "moon" | "mars";
|
|
25
25
|
/**
|
|
26
|
-
* Mean radii in
|
|
27
|
-
*
|
|
26
|
+
* Mean radii in kilometers.
|
|
27
|
+
*
|
|
28
|
+
* Earth's is the value `radii` scales to its units.
|
|
29
|
+
* The Moon's and Mars's are the IAU mean radii the usgs planetary products reference
|
|
30
|
+
* (the Moon as a sphere. Mars's mean radius, its DEM being on the areoid).
|
|
31
|
+
*
|
|
28
32
|
* A distance on a body other than Earth is meaningless without one of these.
|
|
29
33
|
*/
|
|
30
34
|
export declare const BODY_RADII_KM: {
|
|
@@ -51,54 +55,73 @@ export interface GreatCircleOptions {
|
|
|
51
55
|
*/
|
|
52
56
|
export declare function haversine(point1: GeoPointInput, point2: GeoPointInput, unit?: EarthRadiusUnit): number;
|
|
53
57
|
/**
|
|
54
|
-
* Great-circle distance on the
|
|
55
|
-
*
|
|
58
|
+
* Great-circle distance on the selected body. {@link haversine} is this function on Earth.
|
|
59
|
+
* A caller with a body passes it here.
|
|
60
|
+
*
|
|
61
|
+
* The Null-Island sentinel of the object form applies: a `(0, 0)` input answers `NaN`.
|
|
56
62
|
*
|
|
57
63
|
* @category Position
|
|
58
64
|
*/
|
|
59
65
|
export declare function greatCircleDistance(point1: GeoPointInput, point2: GeoPointInput, options?: GreatCircleOptions): number;
|
|
60
66
|
/**
|
|
61
|
-
*
|
|
62
|
-
* every resolver + eval consumer of the `(aLat, aLon, bLat, bLon)` shape imports this instead of re-declaring it.
|
|
67
|
+
* Returns the great-circle distance in kilometers between two coordinates on Earth.
|
|
63
68
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
69
|
+
* The formula's one true home — every resolver + eval consumer of the
|
|
70
|
+
* `(aLat, aLon, bLat, bLon)` shape imports this instead of re-declaring it.
|
|
71
|
+
*
|
|
72
|
+
* Unlike {@link haversine}, this is pure math with no Null-Island sentinel:
|
|
73
|
+
* `(0, 0)` is the Gulf of Guinea — a real point rather than "missing coordinate".
|
|
74
|
+
* That sentinel convention belongs to the `GeoPointInput` object form
|
|
75
|
+
* (where a 0/0 input means "no coordinate"), not to a raw scalar distance.
|
|
67
76
|
*
|
|
68
77
|
* @category Position
|
|
69
78
|
*/
|
|
70
79
|
export declare function haversineKm(aLat: number, aLon: number, bLat: number, bLon: number): number;
|
|
71
80
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
81
|
+
* Meters per degree of latitude.
|
|
82
|
+
*
|
|
83
|
+
* The scale used by {@link segmentDistanceMetres}.
|
|
84
|
+
* It is also the constant the bounding-box estimates in `#h3/polygon-cells` are built on.
|
|
74
85
|
*/
|
|
75
86
|
export declare const METRES_PER_DEGREE = 111320;
|
|
76
87
|
/**
|
|
77
|
-
* Square
|
|
88
|
+
* Square meters in a square kilometer.
|
|
89
|
+
*
|
|
90
|
+
* The conversion every polygon layer's area receipt reports through.
|
|
78
91
|
*/
|
|
79
92
|
export declare const M2_PER_KM2 = 1000000;
|
|
80
93
|
/**
|
|
81
|
-
*
|
|
94
|
+
* Meters from a point to a line segment, with longitude scaled for the latitude
|
|
95
|
+
* so the two axes are comparable.
|
|
96
|
+
*
|
|
97
|
+
* Measure TO the edge rather than TO the nearest vertex.
|
|
98
|
+
* A point a centimeter from a long edge can be meters from every vertex of it,
|
|
99
|
+
* so a vertex distance overstates the gap without bound.
|
|
100
|
+
*
|
|
101
|
+
* Measured on the flood layer's verification, one near-miss read 1.58 m to vertices
|
|
102
|
+
* and 0.009 m to edges, a 9 mm difference overstated 175-fold.
|
|
82
103
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* near-miss read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. That is the difference
|
|
86
|
-
* between "two channels rendered the same edge slightly differently" and "the conversion is wrong".
|
|
104
|
+
* That is the difference between "two channels rendered the same edge slightly
|
|
105
|
+
* differently" and "the conversion is wrong".
|
|
87
106
|
*
|
|
88
|
-
* The longitude scaling matters at the same scale: comparing raw degrees treats
|
|
89
|
-
*
|
|
107
|
+
* The longitude scaling matters at the same scale: comparing raw degrees treats
|
|
108
|
+
* a degree of longitude as a degree of latitude.
|
|
109
|
+
* At 54°N, this overstates east-west distance by 70%.
|
|
90
110
|
*
|
|
91
111
|
* @category Position
|
|
92
112
|
*/
|
|
93
113
|
export declare function segmentDistanceMetres(lon: number, lat: number, from: readonly number[], to: readonly number[]): number;
|
|
94
114
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
115
|
+
* Meters from a point to the nearest ring edge of an areal geometry.
|
|
116
|
+
*
|
|
117
|
+
* `Infinity` when the geometry bounds no area or contains no segment.
|
|
118
|
+
*
|
|
119
|
+
* To the edge rather than to the nearest vertex: a point a centimeter from a long edge can
|
|
120
|
+
* be meters from every vertex of it, so a vertex distance overstates the gap without bound.
|
|
121
|
+
* Measured on the flood layer's verification, one near-miss read 1.58 m to vertices
|
|
122
|
+
* and 0.009 m to edges, a 9 mm difference overstated 175-fold.
|
|
97
123
|
*
|
|
98
|
-
*
|
|
99
|
-
* so a vertex distance overstates the gap without bound — measured on the flood layer's verification, one near-miss
|
|
100
|
-
* read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. Every polygon layer's two-path
|
|
101
|
-
* verification measures its boundary tolerance with this.
|
|
124
|
+
* Every polygon layer's two-path verification measures its boundary tolerance with this.
|
|
102
125
|
*
|
|
103
126
|
* @category Position
|
|
104
127
|
*/
|
package/out/distance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distance.d.ts","sourceRoot":"","sources":["../lib/distance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGhE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"distance.d.ts","sourceRoot":"","sources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AAM,EAAE,GACnB,MAAM,CAaR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,EAChD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACd,MAAM,CAoBR"}
|
package/out/distance.js
CHANGED
|
@@ -27,8 +27,12 @@ const RADII = {
|
|
|
27
27
|
meters: 6_371_000,
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* Mean radii in
|
|
31
|
-
*
|
|
30
|
+
* Mean radii in kilometers.
|
|
31
|
+
*
|
|
32
|
+
* Earth's is the value `radii` scales to its units.
|
|
33
|
+
* The Moon's and Mars's are the IAU mean radii the usgs planetary products reference
|
|
34
|
+
* (the Moon as a sphere. Mars's mean radius, its DEM being on the areoid).
|
|
35
|
+
*
|
|
32
36
|
* A distance on a body other than Earth is meaningless without one of these.
|
|
33
37
|
*/
|
|
34
38
|
export const BODY_RADII_KM = {
|
|
@@ -37,7 +41,9 @@ export const BODY_RADII_KM = {
|
|
|
37
41
|
mars: 3389.5,
|
|
38
42
|
};
|
|
39
43
|
/**
|
|
40
|
-
* Shared great-circle math with no sentinel handling.
|
|
44
|
+
* Shared great-circle math with no sentinel handling.
|
|
45
|
+
*
|
|
46
|
+
* `unit` selects the Earth radius.
|
|
41
47
|
*/
|
|
42
48
|
function greatCircle(lat1, lon1, lat2, lon2, unit) {
|
|
43
49
|
const dLat = (lat2 - lat1) * ConversionFactor.DegreesToRadians;
|
|
@@ -66,8 +72,10 @@ export function haversine(point1, point2, unit = "km") {
|
|
|
66
72
|
return greatCircle(p1.latitude, p1.longitude, p2.latitude, p2.longitude, unit);
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
|
-
* Great-circle distance on the
|
|
70
|
-
*
|
|
75
|
+
* Great-circle distance on the selected body. {@link haversine} is this function on Earth.
|
|
76
|
+
* A caller with a body passes it here.
|
|
77
|
+
*
|
|
78
|
+
* The Null-Island sentinel of the object form applies: a `(0, 0)` input answers `NaN`.
|
|
71
79
|
*
|
|
72
80
|
* @category Position
|
|
73
81
|
*/
|
|
@@ -78,12 +86,15 @@ export function greatCircleDistance(point1, point2, options = {}) {
|
|
|
78
86
|
return haversine(point1, point2, unit) * scale;
|
|
79
87
|
}
|
|
80
88
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
89
|
+
* Returns the great-circle distance in kilometers between two coordinates on Earth.
|
|
90
|
+
*
|
|
91
|
+
* The formula's one true home — every resolver + eval consumer of the
|
|
92
|
+
* `(aLat, aLon, bLat, bLon)` shape imports this instead of re-declaring it.
|
|
83
93
|
*
|
|
84
|
-
* Unlike {@link haversine}, this is pure math with
|
|
85
|
-
*
|
|
86
|
-
*
|
|
94
|
+
* Unlike {@link haversine}, this is pure math with no Null-Island sentinel:
|
|
95
|
+
* `(0, 0)` is the Gulf of Guinea — a real point rather than "missing coordinate".
|
|
96
|
+
* That sentinel convention belongs to the `GeoPointInput` object form
|
|
97
|
+
* (where a 0/0 input means "no coordinate"), not to a raw scalar distance.
|
|
87
98
|
*
|
|
88
99
|
* @category Position
|
|
89
100
|
*/
|
|
@@ -91,24 +102,35 @@ export function haversineKm(aLat, aLon, bLat, bLon) {
|
|
|
91
102
|
return greatCircle(aLat, aLon, bLat, bLon, "km");
|
|
92
103
|
}
|
|
93
104
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
105
|
+
* Meters per degree of latitude.
|
|
106
|
+
*
|
|
107
|
+
* The scale used by {@link segmentDistanceMetres}.
|
|
108
|
+
* It is also the constant the bounding-box estimates in `#h3/polygon-cells` are built on.
|
|
96
109
|
*/
|
|
97
110
|
export const METRES_PER_DEGREE = 111_320;
|
|
98
111
|
/**
|
|
99
|
-
* Square
|
|
112
|
+
* Square meters in a square kilometer.
|
|
113
|
+
*
|
|
114
|
+
* The conversion every polygon layer's area receipt reports through.
|
|
100
115
|
*/
|
|
101
116
|
export const M2_PER_KM2 = 1_000_000;
|
|
102
117
|
/**
|
|
103
|
-
*
|
|
118
|
+
* Meters from a point to a line segment, with longitude scaled for the latitude
|
|
119
|
+
* so the two axes are comparable.
|
|
120
|
+
*
|
|
121
|
+
* Measure TO the edge rather than TO the nearest vertex.
|
|
122
|
+
* A point a centimeter from a long edge can be meters from every vertex of it,
|
|
123
|
+
* so a vertex distance overstates the gap without bound.
|
|
124
|
+
*
|
|
125
|
+
* Measured on the flood layer's verification, one near-miss read 1.58 m to vertices
|
|
126
|
+
* and 0.009 m to edges, a 9 mm difference overstated 175-fold.
|
|
104
127
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* near-miss read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. That is the difference
|
|
108
|
-
* between "two channels rendered the same edge slightly differently" and "the conversion is wrong".
|
|
128
|
+
* That is the difference between "two channels rendered the same edge slightly
|
|
129
|
+
* differently" and "the conversion is wrong".
|
|
109
130
|
*
|
|
110
|
-
* The longitude scaling matters at the same scale: comparing raw degrees treats
|
|
111
|
-
*
|
|
131
|
+
* The longitude scaling matters at the same scale: comparing raw degrees treats
|
|
132
|
+
* a degree of longitude as a degree of latitude.
|
|
133
|
+
* At 54°N, this overstates east-west distance by 70%.
|
|
112
134
|
*
|
|
113
135
|
* @category Position
|
|
114
136
|
*/
|
|
@@ -119,18 +141,22 @@ export function segmentDistanceMetres(lon, lat, from, to) {
|
|
|
119
141
|
const vx = (to[0] - from[0]) * scale;
|
|
120
142
|
const vy = to[1] - from[1];
|
|
121
143
|
const lengthSquared = vx * vx + vy * vy;
|
|
122
|
-
// A zero-length segment is a repeated vertex
|
|
144
|
+
// A zero-length segment is a repeated vertex.
|
|
145
|
+
// The distance to it is the distance to the point.
|
|
123
146
|
const t = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, (px * vx + py * vy) / lengthSquared));
|
|
124
147
|
return Math.hypot(px - t * vx, py - t * vy) * METRES_PER_DEGREE;
|
|
125
148
|
}
|
|
126
149
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
150
|
+
* Meters from a point to the nearest ring edge of an areal geometry.
|
|
151
|
+
*
|
|
152
|
+
* `Infinity` when the geometry bounds no area or contains no segment.
|
|
153
|
+
*
|
|
154
|
+
* To the edge rather than to the nearest vertex: a point a centimeter from a long edge can
|
|
155
|
+
* be meters from every vertex of it, so a vertex distance overstates the gap without bound.
|
|
156
|
+
* Measured on the flood layer's verification, one near-miss read 1.58 m to vertices
|
|
157
|
+
* and 0.009 m to edges, a 9 mm difference overstated 175-fold.
|
|
129
158
|
*
|
|
130
|
-
*
|
|
131
|
-
* so a vertex distance overstates the gap without bound — measured on the flood layer's verification, one near-miss
|
|
132
|
-
* read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. Every polygon layer's two-path
|
|
133
|
-
* verification measures its boundary tolerance with this.
|
|
159
|
+
* Every polygon layer's two-path verification measures its boundary tolerance with this.
|
|
134
160
|
*
|
|
135
161
|
* @category Position
|
|
136
162
|
*/
|