@mailwoman/spatial 9.1.0 → 9.2.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 +51 -0
- package/coordinate-bounds.ts +41 -0
- package/coordinate-formats.ts +13 -2
- package/distance.ts +84 -0
- package/geometries/polygon.ts +87 -7
- package/index.ts +3 -0
- package/open-location-code.ts +168 -0
- package/out/bbox.d.ts +21 -0
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +31 -0
- package/out/bbox.js.map +1 -1
- package/out/coordinate-bounds.d.ts +32 -0
- package/out/coordinate-bounds.d.ts.map +1 -0
- package/out/coordinate-bounds.js +36 -0
- package/out/coordinate-bounds.js.map +1 -0
- package/out/coordinate-formats.d.ts +8 -0
- package/out/coordinate-formats.d.ts.map +1 -1
- package/out/coordinate-formats.js +12 -2
- package/out/coordinate-formats.js.map +1 -1
- package/out/distance.d.ts +46 -0
- package/out/distance.d.ts.map +1 -0
- package/out/distance.js +70 -0
- package/out/distance.js.map +1 -0
- package/out/geometries/polygon.d.ts +53 -0
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +40 -7
- package/out/geometries/polygon.js.map +1 -1
- package/out/index.d.ts +3 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -0
- package/out/index.js.map +1 -1
- package/out/open-location-code.d.ts +48 -0
- package/out/open-location-code.d.ts.map +1 -0
- package/out/open-location-code.js +137 -0
- package/out/open-location-code.js.map +1 -0
- package/out/polyline.js +1 -1
- package/out/position.d.ts +4 -61
- package/out/position.d.ts.map +1 -1
- package/out/position.js +14 -126
- package/out/position.js.map +1 -1
- package/out/sdk/well-known-text.d.ts +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 -1
- package/out/tsconfig.tsbuildinfo +1 -1
- package/package.json +66 -6
- package/polyline.ts +1 -1
- package/position.ts +15 -144
- package/sdk/well-known-text.ts +2 -1
package/bbox.ts
CHANGED
|
@@ -6,10 +6,21 @@
|
|
|
6
6
|
* GeoJSON Bounding Boxes
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { toRad } from "./coordinate-formats.ts"
|
|
9
10
|
import type { PolygonLiteral, SolidPolygonPath } from "./geometries/polygon.ts"
|
|
10
11
|
import { clampLatitude, wrapLongitude } from "./position.ts"
|
|
11
12
|
import { CoordinateProjection } from "./projection.ts"
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Kilometres per degree of latitude, which is very nearly constant on a sphere.
|
|
16
|
+
*/
|
|
17
|
+
const KM_PER_DEGREE_LATITUDE = 111
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Floor for cos(latitude) so a polar bbox stays finite. See {@linkcode bboxAround}.
|
|
21
|
+
*/
|
|
22
|
+
const MIN_COS_LATITUDE = 1e-6
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* Arity of a 2D bounding box: `[west, south, east, north]`.
|
|
15
26
|
*/
|
|
@@ -452,3 +463,43 @@ export class GeoBoundingBox {
|
|
|
452
463
|
|
|
453
464
|
//#endregion
|
|
454
465
|
}
|
|
466
|
+
|
|
467
|
+
//#region Equirectangular bbox around a point
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* A flat latitude/longitude range, as a query filter rather than a model.
|
|
471
|
+
*
|
|
472
|
+
* Distinct from {@linkcode GeoBoundingBox} on purpose: that is a class carrying a projection and private state, which an
|
|
473
|
+
* SQL row cannot be. This is the plain shape a spatial-index query is built from — four numbers, no behaviour.
|
|
474
|
+
*/
|
|
475
|
+
export interface LatLonBounds {
|
|
476
|
+
minLat: number
|
|
477
|
+
maxLat: number
|
|
478
|
+
minLon: number
|
|
479
|
+
maxLon: number
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Approximate bounds `radiusKM` in each direction around a point.
|
|
484
|
+
*
|
|
485
|
+
* The spherical-Earth equirectangular approximation: 1° latitude ≈ 111 km globally, 1° longitude ≈ 111 km × cos(lat).
|
|
486
|
+
* It is a FILTER, not an answer — it over-selects near the poles and along a long east-west span, and a caller is
|
|
487
|
+
* expected to re-check survivors with an exact haversine distance. That is what makes the approximation safe: it may
|
|
488
|
+
* admit a point it should not, and never excludes one it should keep.
|
|
489
|
+
*/
|
|
490
|
+
export function bboxAround(lat: number, lon: number, radiusKM: number): LatLonBounds {
|
|
491
|
+
const latDelta = radiusKM / KM_PER_DEGREE_LATITUDE
|
|
492
|
+
// cos(±90°) is 0, which would divide the longitude delta to Infinity and select the whole globe. Clamp so a polar
|
|
493
|
+
// query stays a wide band rather than becoming unbounded.
|
|
494
|
+
const cosLat = Math.max(Math.cos(toRad(lat)), MIN_COS_LATITUDE)
|
|
495
|
+
const lonDelta = radiusKM / (KM_PER_DEGREE_LATITUDE * cosLat)
|
|
496
|
+
|
|
497
|
+
return {
|
|
498
|
+
minLat: lat - latDelta,
|
|
499
|
+
maxLat: lat + latDelta,
|
|
500
|
+
minLon: lon - lonDelta,
|
|
501
|
+
maxLon: lon + lonDelta,
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
//#endregion
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Dependency-free WGS-84 coordinate bounds shared by parsers and geometry objects.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Southern limit of latitude in WGS-84 degrees.
|
|
11
|
+
*/
|
|
12
|
+
export const LATITUDE_MIN = -90
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Northern limit of latitude in WGS-84 degrees.
|
|
16
|
+
*/
|
|
17
|
+
export const LATITUDE_MAX = 90
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Western limit of longitude in WGS-84 degrees.
|
|
21
|
+
*/
|
|
22
|
+
export const LONGITUDE_MIN = -180
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Eastern limit of longitude in WGS-84 degrees.
|
|
26
|
+
*/
|
|
27
|
+
export const LONGITUDE_MAX = 180
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether a finite number is a latitude on the globe, including both poles.
|
|
31
|
+
*/
|
|
32
|
+
export function isValidLatitude(value: number): boolean {
|
|
33
|
+
return Number.isFinite(value) && value >= LATITUDE_MIN && value <= LATITUDE_MAX
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Whether a finite number is a longitude on the globe, including the antimeridian.
|
|
38
|
+
*/
|
|
39
|
+
export function isValidLongitude(value: number): boolean {
|
|
40
|
+
return Number.isFinite(value) && value >= LONGITUDE_MIN && value <= LONGITUDE_MAX
|
|
41
|
+
}
|
package/coordinate-formats.ts
CHANGED
|
@@ -26,8 +26,19 @@ const MGRS_LAT_MIN = -80
|
|
|
26
26
|
*/
|
|
27
27
|
const MGRS_LAT_MAX = 84
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* WGS-84 degrees → radians.
|
|
31
|
+
*/
|
|
32
|
+
export function toRad(deg: number): number {
|
|
33
|
+
return (deg * Math.PI) / 180
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* WGS-84 radians → degrees.
|
|
38
|
+
*/
|
|
39
|
+
export function toDeg(rad: number): number {
|
|
40
|
+
return (rad * 180) / Math.PI
|
|
41
|
+
}
|
|
31
42
|
|
|
32
43
|
/**
|
|
33
44
|
* Render a single signed degree as `D° M′ S″ H` with the given hemisphere letters `[positive, negative]`.
|
package/distance.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
* @file Great-circle distance utilities. This module imports geometry directly so spatial's
|
|
6
|
+
* lowest-level math never reaches back through its public barrel.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { GeoPoint, type GeoPointInput } from "./geometries/point.ts"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Conversion factors for converting between degrees and radians.
|
|
13
|
+
*
|
|
14
|
+
* @category Position
|
|
15
|
+
* @see {@link https://en.wikipedia.org/wiki/Radian Wikipedia: Radian}
|
|
16
|
+
* @see {@link https://en.wikipedia.org/wiki/Degree_(angle) Wikipedia: Degree (angle)}
|
|
17
|
+
*/
|
|
18
|
+
export const ConversionFactor = {
|
|
19
|
+
DegreesToRadians: Math.PI / 180,
|
|
20
|
+
RadiansToDegrees: 180 / Math.PI,
|
|
21
|
+
} as const
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Available conversion units for the radius of the Earth.
|
|
25
|
+
*/
|
|
26
|
+
export type EarthRadiusUnit = "km" | "miles" | "meters"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Radius of the Earth in various units.
|
|
30
|
+
*/
|
|
31
|
+
const RADII = {
|
|
32
|
+
km: 6371,
|
|
33
|
+
miles: 3958.8,
|
|
34
|
+
meters: 6_371_000,
|
|
35
|
+
} as const satisfies Record<EarthRadiusUnit, number>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shared great-circle math with no sentinel handling. `unit` selects the Earth radius.
|
|
39
|
+
*/
|
|
40
|
+
function greatCircle(lat1: number, lon1: number, lat2: number, lon2: number, unit: EarthRadiusUnit): number {
|
|
41
|
+
const dLat = (lat2 - lat1) * ConversionFactor.DegreesToRadians
|
|
42
|
+
const dLon = (lon2 - lon1) * ConversionFactor.DegreesToRadians
|
|
43
|
+
|
|
44
|
+
const a =
|
|
45
|
+
Math.pow(Math.sin(dLat / 2), 2) +
|
|
46
|
+
Math.cos(lat1 * ConversionFactor.DegreesToRadians) *
|
|
47
|
+
Math.cos(lat2 * ConversionFactor.DegreesToRadians) *
|
|
48
|
+
Math.pow(Math.sin(dLon / 2), 2)
|
|
49
|
+
|
|
50
|
+
return RADII[unit] * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Calculate the distance between two points on the Earth's surface.
|
|
55
|
+
*
|
|
56
|
+
* @category Position
|
|
57
|
+
* @param point1 The first point to calculate the distance from.
|
|
58
|
+
* @param point2 The second point to calculate the distance to.
|
|
59
|
+
* @param unit The unit of measurement to return the distance in.
|
|
60
|
+
*
|
|
61
|
+
* @returns The distance between the two points in the specified unit.
|
|
62
|
+
*/
|
|
63
|
+
export function haversine(point1: GeoPointInput, point2: GeoPointInput, unit: EarthRadiusUnit = "km"): number {
|
|
64
|
+
const p1 = GeoPoint.from(point1)
|
|
65
|
+
const p2 = GeoPoint.from(point2)
|
|
66
|
+
|
|
67
|
+
if (!p1 || !p2) return Number.NaN
|
|
68
|
+
|
|
69
|
+
return greatCircle(p1.latitude, p1.longitude, p2.latitude, p2.longitude, unit)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Great-circle distance in kilometres between two lat/lon pairs given as raw scalars. The formula's one true home —
|
|
74
|
+
* every resolver + eval consumer of the `(aLat, aLon, bLat, bLon)` shape imports this instead of re-declaring it.
|
|
75
|
+
*
|
|
76
|
+
* Unlike {@link haversine}, this is pure math with NO Null-Island sentinel: `(0, 0)` is the Gulf of Guinea — a real
|
|
77
|
+
* point, not "missing coordinate". That sentinel convention belongs to the `GeoPointInput` object form (where a 0/0
|
|
78
|
+
* input means "no coordinate"), not to a raw scalar distance.
|
|
79
|
+
*
|
|
80
|
+
* @category Position
|
|
81
|
+
*/
|
|
82
|
+
export function haversineKm(aLat: number, aLon: number, bLat: number, bLon: number): number {
|
|
83
|
+
return greatCircle(aLat, aLon, bLat, bLon, "km")
|
|
84
|
+
}
|
package/geometries/polygon.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { APIClient, pluckResponseData } from "@mailwoman/core/api"
|
|
7
8
|
import { ResourceError } from "@mailwoman/core/errors"
|
|
8
9
|
|
|
9
10
|
import type { GeoObjectLiteral } from "../objects.ts"
|
|
@@ -290,21 +291,100 @@ export function isResidentialElement(element: OSMOverpassElement): boolean {
|
|
|
290
291
|
return true
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
const overpassClient = new APIClient({ displayName: "overpass", retry: true })
|
|
295
|
+
|
|
293
296
|
export function fetchOSMElementViaOverpassAPI(input: PolygonLiteral): Promise<OSMOverpassElement[]> {
|
|
294
297
|
const filter = polygonToOSMFilter(input)
|
|
295
298
|
|
|
296
299
|
const url = new URL("http://overpass-api.de/api/interpreter")
|
|
297
300
|
url.searchParams.set("data", `[out:json];(node['addr:housenumber'](${filter}););out body;>;out skel qt;`)
|
|
298
301
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
.then((response) => response.json() as Promise<OSMOverpassResponseBody>)
|
|
302
|
+
// Overpass is a free shared endpoint that answers a throttle with 429 + `Retry-After`. `retry: true` is what
|
|
303
|
+
// reads that header, which is the server stating its own limit rather than this file guessing one. `ResourceError`
|
|
304
|
+
// now arrives from the client instead of being assembled here.
|
|
305
|
+
return overpassClient
|
|
306
|
+
.fetch<OSMOverpassResponseBody>({ url: url.toString() })
|
|
307
|
+
.then(pluckResponseData)
|
|
306
308
|
.then((body) => body.elements)
|
|
307
309
|
.catch((error) => {
|
|
308
310
|
throw ResourceError.wrap(error, "osm", "overpass-api", "fetch")
|
|
309
311
|
})
|
|
310
312
|
}
|
|
313
|
+
|
|
314
|
+
//#region Ring-list geometry — the parsed-GeoJSON shape
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* A GeoJSON position — `[lon, lat]`, possibly carrying extra dimensions this module ignores.
|
|
318
|
+
*
|
|
319
|
+
* Deliberately looser than {@linkcode Coordinates2D}: a gazetteer geometry arrives from `JSON.parse`, where nothing has
|
|
320
|
+
* checked the arity, and a tuple type there would be a claim about data rather than a description of it.
|
|
321
|
+
*/
|
|
322
|
+
export type GeojsonPosition = [number, number, ...number[]]
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* A GeoJSON `Polygon` as a RING LIST — `[outerRing, hole1, hole2, …]`.
|
|
326
|
+
*
|
|
327
|
+
* This coexists with {@linkcode PolygonLiteral} on purpose, and the difference is load-bearing. `PolygonLiteral`
|
|
328
|
+
* defaults to {@linkcode SolidPolygonPath}, a one-element tuple that cannot express a hole; a real administrative
|
|
329
|
+
* boundary routinely has them (a country with a lake, a locality with an enclave). Use this type for geometry read off
|
|
330
|
+
* a gazetteer, and `PolygonLiteral` where the solid/nested distinction is one you are asserting rather than
|
|
331
|
+
* discovering.
|
|
332
|
+
*/
|
|
333
|
+
export interface GeojsonPolygon {
|
|
334
|
+
type: "Polygon"
|
|
335
|
+
coordinates: GeojsonPosition[][]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* A GeoJSON `MultiPolygon` — one ring list per polygon.
|
|
340
|
+
*/
|
|
341
|
+
export interface GeojsonMultiPolygon {
|
|
342
|
+
type: "MultiPolygon"
|
|
343
|
+
coordinates: GeojsonPosition[][][]
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Either areal geometry, or an open fallback for the types containment cannot answer (Point, LineString, …).
|
|
348
|
+
*/
|
|
349
|
+
export type GeojsonGeometry = GeojsonPolygon | GeojsonMultiPolygon | { type: string; coordinates?: unknown }
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Even-odd containment over a polygon's ring list (`[outer, hole1, …]`).
|
|
353
|
+
*
|
|
354
|
+
* A named alias for {@linkcode pointInPolygon}: the "rings" spelling is what makes the ring-list argument obvious at a
|
|
355
|
+
* call site that has just pulled `coordinates` off a parsed geometry.
|
|
356
|
+
*
|
|
357
|
+
* `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
|
|
358
|
+
* HAND if this one changes — it is the one copy no import can reach.
|
|
359
|
+
*/
|
|
360
|
+
export function pointInPolygonRings(lon: number, lat: number, rings: readonly GeojsonPosition[][]): boolean {
|
|
361
|
+
return pointInPolygon(lon, lat, rings)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Does an areal GeoJSON geometry contain the point?
|
|
366
|
+
*
|
|
367
|
+
* The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
|
|
368
|
+
* LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
|
|
369
|
+
* geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
|
|
370
|
+
* containment pass instead of falling through to the approximate path.
|
|
371
|
+
*/
|
|
372
|
+
export function geometryContains(
|
|
373
|
+
geometry: GeojsonGeometry | null | undefined,
|
|
374
|
+
lon: number,
|
|
375
|
+
lat: number
|
|
376
|
+
): boolean | null {
|
|
377
|
+
if (!geometry) return null
|
|
378
|
+
|
|
379
|
+
if (geometry.type === "Polygon") {
|
|
380
|
+
return pointInPolygonRings(lon, lat, (geometry as GeojsonPolygon).coordinates)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (geometry.type === "MultiPolygon") {
|
|
384
|
+
return (geometry as GeojsonMultiPolygon).coordinates.some((rings) => pointInPolygonRings(lon, lat, rings))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return null
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
//#endregion
|
package/index.ts
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
export * from "./bbox.ts"
|
|
8
8
|
export * from "./coordinate-formats.ts"
|
|
9
|
+
export * from "./coordinate-bounds.ts"
|
|
10
|
+
export * from "./distance.ts"
|
|
9
11
|
export * from "./feature.ts"
|
|
12
|
+
export * from "./open-location-code.ts"
|
|
10
13
|
export * from "./geometries/index.ts"
|
|
11
14
|
export * from "./google/index.ts"
|
|
12
15
|
export * from "./h3/index.ts"
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Open Location Code (plus code) decode + nearest-recovery — the coordinate system Google Maps
|
|
7
|
+
* prints on every place card, which makes it a first-class user register in countries with sparse
|
|
8
|
+
* street addressing (the Nicaraguan board rows arrived exactly this way). Pure arithmetic over the
|
|
9
|
+
* published spec (https://github.com/google/open-location-code/blob/main/docs/specification.md);
|
|
10
|
+
* no dependency, no I/O.
|
|
11
|
+
*
|
|
12
|
+
* A FULL code (8 digits, a `+`, then 2–3 more) decodes directly. A SHORT code (2–6 leading digits
|
|
13
|
+
* removed, e.g. `VFQ6+92P`) is only meaningful near a reference point — the removed prefix is
|
|
14
|
+
* recovered from the reference, then the candidate cell is shifted by whole prefix-resolutions if
|
|
15
|
+
* a neighboring cell sits closer (the spec's `recoverNearest`). The reference in an address is the
|
|
16
|
+
* RESOLVED LOCALITY, which is why the geocode wiring recovers after the admin walk.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The 20-character OLC digit set. Deliberately excludes letters that read as words or digits (no A/E/I/L/N/O/S/T…), so
|
|
21
|
+
* a matched token is very unlikely to be ordinary text.
|
|
22
|
+
*/
|
|
23
|
+
const OLC_ALPHABET = "23456789CFGHJMPQRVWX"
|
|
24
|
+
|
|
25
|
+
const OLC_DIGIT_VALUE = new Map<string, number>([...OLC_ALPHABET].map((c, i) => [c, i]))
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Degree width of each pair-position, most significant first: the pair at index i spans `20^(2-i)` degrees. Ten pair
|
|
29
|
+
* digits (five lat/lon pairs) take a cell to 1/400° ≈ 275 m; grid digits refine further.
|
|
30
|
+
*/
|
|
31
|
+
const PAIR_RESOLUTIONS = [20, 1, 1 / 20, 1 / 400, 1 / 8000] as const
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Grid refinement past ten digits: each digit subdivides the cell into 4 columns × 5 rows.
|
|
35
|
+
*/
|
|
36
|
+
const GRID_COLUMNS = 4
|
|
37
|
+
const GRID_ROWS = 5
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A decoded plus-code cell: the center (the coordinate consumers want) plus the cell's span, from which callers price
|
|
41
|
+
* the claim (`uncertaintyM` ≈ the half-diagonal).
|
|
42
|
+
*/
|
|
43
|
+
export interface DecodedPlusCode {
|
|
44
|
+
lat: number
|
|
45
|
+
lon: number
|
|
46
|
+
latSpanDeg: number
|
|
47
|
+
lonSpanDeg: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A syntactically-valid FULL plus code: exactly 8 digits, `+`, then 2 or 3 digits. (The spec allows padded and longer
|
|
52
|
+
* forms; addresses carry the 10–11 digit register, which is all this reader accepts.)
|
|
53
|
+
*/
|
|
54
|
+
export function isFullPlusCode(token: string): boolean {
|
|
55
|
+
return /^[23456789CFGHJMPQRVWX]{8}\+[23456789CFGHJMPQRVWX]{2,3}$/i.test(token)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A syntactically-valid SHORT plus code: 2, 4, or 6 leading digits removed — so 6, 4, or 2 digits before the `+`. The
|
|
60
|
+
* 4-before-`+` form (`VFQ6+92P`) is the one Google prints on place cards.
|
|
61
|
+
*/
|
|
62
|
+
export function isShortPlusCode(token: string): boolean {
|
|
63
|
+
return /^[23456789CFGHJMPQRVWX]{2,6}\+[23456789CFGHJMPQRVWX]{2,3}$/i.test(token) && token.indexOf("+") % 2 === 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Decode a FULL plus code to its cell. Returns null on anything `isFullPlusCode` rejects.
|
|
68
|
+
*/
|
|
69
|
+
export function decodePlusCode(code: string): DecodedPlusCode | null {
|
|
70
|
+
if (!isFullPlusCode(code)) return null
|
|
71
|
+
const digits = code.toUpperCase().replace("+", "")
|
|
72
|
+
|
|
73
|
+
let latLo = -90
|
|
74
|
+
let lonLo = -180
|
|
75
|
+
let latSpan = 400
|
|
76
|
+
let lonSpan = 400
|
|
77
|
+
|
|
78
|
+
// The first ten digits arrive in (lat, lon) pairs.
|
|
79
|
+
const pairCount = Math.min(digits.length, 10)
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i < pairCount; i += 2) {
|
|
82
|
+
const resolution = PAIR_RESOLUTIONS[i / 2]!
|
|
83
|
+
|
|
84
|
+
latLo += OLC_DIGIT_VALUE.get(digits[i]!)! * resolution
|
|
85
|
+
lonLo += OLC_DIGIT_VALUE.get(digits[i + 1]!)! * resolution
|
|
86
|
+
latSpan = resolution
|
|
87
|
+
lonSpan = resolution
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Grid refinement: each further digit indexes a 4×5 (columns × rows) subdivision.
|
|
91
|
+
for (let i = 10; i < digits.length; i++) {
|
|
92
|
+
const value = OLC_DIGIT_VALUE.get(digits[i]!)!
|
|
93
|
+
|
|
94
|
+
latSpan /= GRID_ROWS
|
|
95
|
+
lonSpan /= GRID_COLUMNS
|
|
96
|
+
latLo += Math.floor(value / GRID_COLUMNS) * latSpan
|
|
97
|
+
lonLo += (value % GRID_COLUMNS) * lonSpan
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
lat: latLo + latSpan / 2,
|
|
102
|
+
lon: lonLo + lonSpan / 2,
|
|
103
|
+
latSpanDeg: latSpan,
|
|
104
|
+
lonSpanDeg: lonSpan,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Encode the pair digits of a coordinate to `length` digits (length ≤ 10, even) — the prefix machinery
|
|
110
|
+
* {@link recoverNearestPlusCode} needs; not a general encoder.
|
|
111
|
+
*/
|
|
112
|
+
function encodePairDigits(lat: number, lon: number, length: number): string {
|
|
113
|
+
let latVal = Math.min(Math.max(lat + 90, 0), 180 - 1e-12)
|
|
114
|
+
let lonVal = lon + 180
|
|
115
|
+
|
|
116
|
+
lonVal -= Math.floor(lonVal / 360) * 360
|
|
117
|
+
|
|
118
|
+
let out = ""
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < length / 2; i++) {
|
|
121
|
+
const resolution = PAIR_RESOLUTIONS[i]!
|
|
122
|
+
const latDigit = Math.min(Math.floor(latVal / resolution), 19)
|
|
123
|
+
const lonDigit = Math.min(Math.floor(lonVal / resolution), 19)
|
|
124
|
+
|
|
125
|
+
out += OLC_ALPHABET[latDigit]! + OLC_ALPHABET[lonDigit]!
|
|
126
|
+
latVal -= latDigit * resolution
|
|
127
|
+
lonVal -= lonDigit * resolution
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return out
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Recover a SHORT plus code against a reference coordinate, per the spec's `recoverNearest`: prepend the reference's
|
|
135
|
+
* prefix at the missing precision, then shift the candidate cell by whole prefix-resolutions when a neighboring cell
|
|
136
|
+
* center sits closer to the reference. Returns the decoded nearest cell, or null for an invalid short code.
|
|
137
|
+
*/
|
|
138
|
+
export function recoverNearestPlusCode(shortCode: string, refLat: number, refLon: number): DecodedPlusCode | null {
|
|
139
|
+
if (!isShortPlusCode(shortCode)) return null
|
|
140
|
+
const upper = shortCode.toUpperCase()
|
|
141
|
+
const missing = 8 - upper.indexOf("+")
|
|
142
|
+
const prefix = encodePairDigits(refLat, refLon, missing)
|
|
143
|
+
const candidate = decodePlusCode(prefix + upper)
|
|
144
|
+
|
|
145
|
+
if (!candidate) return null
|
|
146
|
+
|
|
147
|
+
// The prefix pins the cell modulo its own resolution; the nearest bearer of the short code may sit
|
|
148
|
+
// one prefix-cell away (the reference near a cell edge). Shift by whole prefix-resolutions, never
|
|
149
|
+
// past the poles.
|
|
150
|
+
const LAT_MIN = -90
|
|
151
|
+
const LAT_MAX = 90
|
|
152
|
+
const prefixResolution = PAIR_RESOLUTIONS[missing / 2 - 1]!
|
|
153
|
+
const result = { ...candidate }
|
|
154
|
+
|
|
155
|
+
if (refLat + prefixResolution / 2 < result.lat && result.lat - prefixResolution >= LAT_MIN) {
|
|
156
|
+
result.lat -= prefixResolution
|
|
157
|
+
} else if (refLat - prefixResolution / 2 > result.lat && result.lat + prefixResolution <= LAT_MAX) {
|
|
158
|
+
result.lat += prefixResolution
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (refLon + prefixResolution / 2 < result.lon) {
|
|
162
|
+
result.lon -= prefixResolution
|
|
163
|
+
} else if (refLon - prefixResolution / 2 > result.lon) {
|
|
164
|
+
result.lon += prefixResolution
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return result
|
|
168
|
+
}
|
package/out/bbox.d.ts
CHANGED
|
@@ -201,4 +201,25 @@ export declare class GeoBoundingBox {
|
|
|
201
201
|
*/
|
|
202
202
|
to2DEWKT(): string;
|
|
203
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* A flat latitude/longitude range, as a query filter rather than a model.
|
|
206
|
+
*
|
|
207
|
+
* Distinct from {@linkcode GeoBoundingBox} on purpose: that is a class carrying a projection and private state, which an
|
|
208
|
+
* SQL row cannot be. This is the plain shape a spatial-index query is built from — four numbers, no behaviour.
|
|
209
|
+
*/
|
|
210
|
+
export interface LatLonBounds {
|
|
211
|
+
minLat: number;
|
|
212
|
+
maxLat: number;
|
|
213
|
+
minLon: number;
|
|
214
|
+
maxLon: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Approximate bounds `radiusKM` in each direction around a point.
|
|
218
|
+
*
|
|
219
|
+
* The spherical-Earth equirectangular approximation: 1° latitude ≈ 111 km globally, 1° longitude ≈ 111 km × cos(lat).
|
|
220
|
+
* It is a FILTER, not an answer — it over-selects near the poles and along a long east-west span, and a caller is
|
|
221
|
+
* expected to re-check survivors with an exact haversine distance. That is what makes the approximation safe: it may
|
|
222
|
+
* admit a point it should not, and never excludes one it should keep.
|
|
223
|
+
*/
|
|
224
|
+
export declare function bboxAround(lat: number, lon: number, radiusKM: number): LatLonBounds;
|
|
204
225
|
//# sourceMappingURL=bbox.d.ts.map
|
package/out/bbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAwBtD;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM;IACnB;;;;;OAKG;IACH,YAAY,EAAE,MAAM;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM;CACnB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM;IAEnB;;OAEG;IACH,WAAW,EAAE,MAAM;IACnB;;;;;OAKG;IACH,YAAY,EAAE,MAAM;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM;IAEnB;;OAEG;IACH,WAAW,EAAE,MAAM;CACnB,CAAA;AAMD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO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B;IAED,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAE5B;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAEjC;IAED,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAE7B;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;IAQxB;;OAEG;;IAEH;;OAEG;gBACS,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,oBAAoB;IAElE;;OAEG;gBACS,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,oBAAoB;gBAEtD,KAAK,CAAC,EAAE,mBAAmB,EAAE,UAAU,CAAC,EAAE,oBAAoB;IAmCnE,IAAI;IAIJ,IAAI;IAQX;;OAEG;IACI,QAAQ,IAAI,aAAa;IAUhC;;OAEG;IACI,QAAQ,IAAI,aAAa;IAYzB,MAAM,IAAI,aAAa,GAAG,aAAa;IAM9C;;OAEG;IACI,WAAW,IAAI,cAAc;IAgBpC;;;;OAIG;IACI,QAAQ,IAAI,MAAM;CAOzB;AAID;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAanF"}
|
package/out/bbox.js
CHANGED
|
@@ -5,8 +5,17 @@
|
|
|
5
5
|
*
|
|
6
6
|
* GeoJSON Bounding Boxes
|
|
7
7
|
*/
|
|
8
|
+
import { toRad } from "./coordinate-formats.js";
|
|
8
9
|
import { clampLatitude, wrapLongitude } from "./position.js";
|
|
9
10
|
import { CoordinateProjection } from "./projection.js";
|
|
11
|
+
/**
|
|
12
|
+
* Kilometres per degree of latitude, which is very nearly constant on a sphere.
|
|
13
|
+
*/
|
|
14
|
+
const KM_PER_DEGREE_LATITUDE = 111;
|
|
15
|
+
/**
|
|
16
|
+
* Floor for cos(latitude) so a polar bbox stays finite. See {@linkcode bboxAround}.
|
|
17
|
+
*/
|
|
18
|
+
const MIN_COS_LATITUDE = 1e-6;
|
|
10
19
|
/**
|
|
11
20
|
* Arity of a 2D bounding box: `[west, south, east, north]`.
|
|
12
21
|
*/
|
|
@@ -271,4 +280,26 @@ export class GeoBoundingBox {
|
|
|
271
280
|
return `SRID=${this.projection};POLYGON((${minLongitude} ${minLatitude}, ${maxLongitude} ${minLatitude}, ${maxLongitude} ${maxLatitude}, ${minLongitude} ${maxLatitude}, ${minLongitude} ${minLatitude}))`;
|
|
272
281
|
}
|
|
273
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Approximate bounds `radiusKM` in each direction around a point.
|
|
285
|
+
*
|
|
286
|
+
* The spherical-Earth equirectangular approximation: 1° latitude ≈ 111 km globally, 1° longitude ≈ 111 km × cos(lat).
|
|
287
|
+
* It is a FILTER, not an answer — it over-selects near the poles and along a long east-west span, and a caller is
|
|
288
|
+
* expected to re-check survivors with an exact haversine distance. That is what makes the approximation safe: it may
|
|
289
|
+
* admit a point it should not, and never excludes one it should keep.
|
|
290
|
+
*/
|
|
291
|
+
export function bboxAround(lat, lon, radiusKM) {
|
|
292
|
+
const latDelta = radiusKM / KM_PER_DEGREE_LATITUDE;
|
|
293
|
+
// cos(±90°) is 0, which would divide the longitude delta to Infinity and select the whole globe. Clamp so a polar
|
|
294
|
+
// query stays a wide band rather than becoming unbounded.
|
|
295
|
+
const cosLat = Math.max(Math.cos(toRad(lat)), MIN_COS_LATITUDE);
|
|
296
|
+
const lonDelta = radiusKM / (KM_PER_DEGREE_LATITUDE * cosLat);
|
|
297
|
+
return {
|
|
298
|
+
minLat: lat - latDelta,
|
|
299
|
+
maxLat: lat + latDelta,
|
|
300
|
+
minLon: lon - lonDelta,
|
|
301
|
+
maxLon: lon + lonDelta,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
274
305
|
//# sourceMappingURL=bbox.js.map
|
package/out/bbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;GAEG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAElC;;GAEG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAE7B;;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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GD;AAiBD;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW,EAAE,QAAgB;IACpE,MAAM,QAAQ,GAAG,QAAQ,GAAG,sBAAsB,CAAA;IAClD,kHAAkH;IAClH,0DAA0D;IAC1D,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,YAAY"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Dependency-free WGS-84 coordinate bounds shared by parsers and geometry objects.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Southern limit of latitude in WGS-84 degrees.
|
|
10
|
+
*/
|
|
11
|
+
export declare const LATITUDE_MIN = -90;
|
|
12
|
+
/**
|
|
13
|
+
* Northern limit of latitude in WGS-84 degrees.
|
|
14
|
+
*/
|
|
15
|
+
export declare const LATITUDE_MAX = 90;
|
|
16
|
+
/**
|
|
17
|
+
* Western limit of longitude in WGS-84 degrees.
|
|
18
|
+
*/
|
|
19
|
+
export declare const LONGITUDE_MIN = -180;
|
|
20
|
+
/**
|
|
21
|
+
* Eastern limit of longitude in WGS-84 degrees.
|
|
22
|
+
*/
|
|
23
|
+
export declare const LONGITUDE_MAX = 180;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a finite number is a latitude on the globe, including both poles.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isValidLatitude(value: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a finite number is a longitude on the globe, including the antimeridian.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isValidLongitude(value: number): boolean;
|
|
32
|
+
//# sourceMappingURL=coordinate-bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinate-bounds.d.ts","sourceRoot":"","sources":["../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;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|