@procedures/geo 0.2.3 → 0.4.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/CHANGELOG.md +70 -0
- package/README.md +21 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/distance.d.ts +14 -0
- package/dist/distance.d.ts.map +1 -0
- package/dist/distance.js +20 -0
- package/dist/distance.js.map +1 -0
- package/dist/geo.d.ts +15 -0
- package/dist/geo.d.ts.map +1 -1
- package/dist/geo.js +5 -4
- package/dist/geo.js.map +1 -1
- package/dist/geohash.d.ts +30 -0
- package/dist/geohash.d.ts.map +1 -0
- package/dist/geohash.js +87 -0
- package/dist/geohash.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/procedures/geo/distance.d.ts +12 -0
- package/dist/procedures/geo/distance.d.ts.map +1 -0
- package/dist/procedures/geo/distance.js +14 -0
- package/dist/procedures/geo/distance.js.map +1 -0
- package/dist/procedures/geo/geohash.d.ts +11 -0
- package/dist/procedures/geo/geohash.d.ts.map +1 -0
- package/dist/procedures/geo/geohash.js +14 -0
- package/dist/procedures/geo/geohash.js.map +1 -0
- package/dist/procedures/geo/index.d.ts +3 -0
- package/dist/procedures/geo/index.d.ts.map +1 -0
- package/dist/procedures/geo/index.js +3 -0
- package/dist/procedures/geo/index.js.map +1 -0
- package/dist/procedures.d.ts +3 -1
- package/dist/procedures.d.ts.map +1 -1
- package/dist/procedures.js +34 -2
- package/dist/procedures.js.map +1 -1
- package/dist/types.d.ts +33 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/package.json +5 -3
- package/src/distance.ts +23 -0
- package/src/geo.ts +23 -7
- package/src/geohash.ts +97 -0
- package/src/index.ts +3 -0
- package/src/procedures/geo/distance.ts +16 -0
- package/src/procedures/geo/geohash.ts +16 -0
- package/src/procedures/geo/index.ts +2 -0
- package/src/procedures.ts +47 -2
- package/src/types.ts +67 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The great-circle distance between two points: the haversine formula on a sphere with the mean
|
|
3
|
+
* radius of the Earth. It uses no network.
|
|
4
|
+
*/
|
|
5
|
+
import type { Point } from "./geo.js";
|
|
6
|
+
/** The mean radius of the Earth, in kilometres (IUGG). */
|
|
7
|
+
export declare const EARTH_RADIUS_KM = 6371;
|
|
8
|
+
/**
|
|
9
|
+
* This function gives the great-circle distance between two points, in kilometres, without
|
|
10
|
+
* rounding. The formula is the haversine formula on a sphere of `EARTH_RADIUS_KM`. The road
|
|
11
|
+
* distance is longer.
|
|
12
|
+
*/
|
|
13
|
+
export declare const greatCircleKm: (a: Point, b: Point) => number;
|
|
14
|
+
//# sourceMappingURL=distance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.d.ts","sourceRoot":"","sources":["../src/distance.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,0DAA0D;AAC1D,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,aAAa,MAAO,KAAK,KAAK,KAAK,KAAG,MAOlD,CAAC"}
|
package/dist/distance.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The great-circle distance between two points: the haversine formula on a sphere with the mean
|
|
3
|
+
* radius of the Earth. It uses no network.
|
|
4
|
+
*/
|
|
5
|
+
/** The mean radius of the Earth, in kilometres (IUGG). */
|
|
6
|
+
export const EARTH_RADIUS_KM = 6371;
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the great-circle distance between two points, in kilometres, without
|
|
9
|
+
* rounding. The formula is the haversine formula on a sphere of `EARTH_RADIUS_KM`. The road
|
|
10
|
+
* distance is longer.
|
|
11
|
+
*/
|
|
12
|
+
export const greatCircleKm = (a, b) => {
|
|
13
|
+
const toRad = (deg) => (deg * Math.PI) / 180;
|
|
14
|
+
const dLat = toRad(b.lat - a.lat);
|
|
15
|
+
const dLon = toRad(b.lon - a.lon);
|
|
16
|
+
const h = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(a.lat)) * Math.cos(toRad(b.lat)) * Math.sin(dLon / 2) ** 2;
|
|
17
|
+
// For two antipodal points, a rounding error can make h a little more than 1, and asin of that is NaN
|
|
18
|
+
return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h)));
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=distance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.js","sourceRoot":"","sources":["../src/distance.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAQ,EAAE,CAAQ,EAAU,EAAE;IAC1D,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9G,sGAAsG;IACtG,OAAO,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC"}
|
package/dist/geo.d.ts
CHANGED
|
@@ -18,11 +18,24 @@ export interface RouteResult {
|
|
|
18
18
|
export declare const NOMINATIM_URL = "https://nominatim.openstreetmap.org";
|
|
19
19
|
/** The public OSRM demonstration server. It has a fair-use limit. A self-hosted OSRM has the same API. */
|
|
20
20
|
export declare const OSRM_URL = "https://router.project-osrm.org";
|
|
21
|
+
/**
|
|
22
|
+
* The part of `fetch` that this package uses. A host or a test can give its own function, for
|
|
23
|
+
* example a fetch with a cache or a recorder. The default is the global `fetch`.
|
|
24
|
+
*/
|
|
25
|
+
export type FetchJson = (url: string, init: {
|
|
26
|
+
headers: Record<string, string>;
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
ok: boolean;
|
|
30
|
+
status: number;
|
|
31
|
+
json(): Promise<unknown>;
|
|
32
|
+
}>;
|
|
21
33
|
/** This function gets a JSON document, with a time limit and the signal of the call. */
|
|
22
34
|
export declare function getJson(url: string, options: {
|
|
23
35
|
timeoutMs: number;
|
|
24
36
|
signal?: AbortSignal | undefined;
|
|
25
37
|
headers?: Record<string, string>;
|
|
38
|
+
fetch?: FetchJson | undefined;
|
|
26
39
|
}, service: string): Promise<unknown>;
|
|
27
40
|
/**
|
|
28
41
|
* This function gives the coordinates of an address or a place name, or undefined when Nominatim
|
|
@@ -34,11 +47,13 @@ export declare function geocode(query: string, options: {
|
|
|
34
47
|
baseUrl?: string | undefined;
|
|
35
48
|
timeoutMs: number;
|
|
36
49
|
signal?: AbortSignal | undefined;
|
|
50
|
+
fetch?: FetchJson | undefined;
|
|
37
51
|
}): Promise<GeocodeResult | undefined>;
|
|
38
52
|
/** This function gives the time and the distance of a drive from one point to another. */
|
|
39
53
|
export declare function drivingRoute(from: Point, to: Point, options: {
|
|
40
54
|
baseUrl?: string | undefined;
|
|
41
55
|
timeoutMs: number;
|
|
42
56
|
signal?: AbortSignal | undefined;
|
|
57
|
+
fetch?: FetchJson | undefined;
|
|
43
58
|
}): Promise<RouteResult>;
|
|
44
59
|
//# sourceMappingURL=geo.d.ts.map
|
package/dist/geo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sCAAsC;AACtC,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,6HAA6H;AAC7H,eAAO,MAAM,aAAa,wCAAwC,CAAC;AAEnE,0GAA0G;AAC1G,eAAO,MAAM,QAAQ,oCAAoC,CAAC;AAE1D,wFAAwF;AACxF,wBAAsB,OAAO,CAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sCAAsC;AACtC,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,C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/B,GACA,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAapC;AAED,0FAA0F;AAC1F,wBAAsB,YAAY,CAChC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,KAAK,EACT,OAAO,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,GAC5H,OAAO,CAAC,WAAW,CAAC,CActB"}
|
package/dist/geo.js
CHANGED
|
@@ -9,13 +9,14 @@ export const OSRM_URL = "https://router.project-osrm.org";
|
|
|
9
9
|
/** This function gets a JSON document, with a time limit and the signal of the call. */
|
|
10
10
|
export async function getJson(url, options, service) {
|
|
11
11
|
const signals = [AbortSignal.timeout(options.timeoutMs), ...(options.signal ? [options.signal] : [])];
|
|
12
|
+
const fetchJson = options.fetch ?? fetch;
|
|
12
13
|
let response;
|
|
13
14
|
try {
|
|
14
|
-
response = await
|
|
15
|
+
response = await fetchJson(url, { signal: AbortSignal.any(signals), headers: { accept: "application/json", ...options.headers } });
|
|
15
16
|
}
|
|
16
17
|
catch (error) {
|
|
17
18
|
const reason = error.name === "TimeoutError" ? `no answer in ${options.timeoutMs} ms` : "the request failed";
|
|
18
|
-
throw new Error(`${service} did not answer: ${reason}
|
|
19
|
+
throw new Error(`${service} did not answer: ${reason}`, { cause: error });
|
|
19
20
|
}
|
|
20
21
|
if (!response.ok)
|
|
21
22
|
throw new Error(`${service} gave HTTP ${response.status}`);
|
|
@@ -29,7 +30,7 @@ export async function geocode(query, options) {
|
|
|
29
30
|
const params = new URLSearchParams({ format: "jsonv2", limit: "1", q: query });
|
|
30
31
|
if (options.countryCodes !== undefined)
|
|
31
32
|
params.set("countrycodes", options.countryCodes);
|
|
32
|
-
const rows = (await getJson(`${options.baseUrl ?? NOMINATIM_URL}/search?${params.toString()}`, { timeoutMs: options.timeoutMs, signal: options.signal, headers: { "user-agent": options.userAgent } }, "Nominatim"));
|
|
33
|
+
const rows = (await getJson(`${options.baseUrl ?? NOMINATIM_URL}/search?${params.toString()}`, { timeoutMs: options.timeoutMs, signal: options.signal, headers: { "user-agent": options.userAgent }, fetch: options.fetch }, "Nominatim"));
|
|
33
34
|
const first = Array.isArray(rows) ? rows[0] : undefined;
|
|
34
35
|
const lat = Number(first?.lat);
|
|
35
36
|
const lon = Number(first?.lon);
|
|
@@ -39,7 +40,7 @@ export async function geocode(query, options) {
|
|
|
39
40
|
}
|
|
40
41
|
/** This function gives the time and the distance of a drive from one point to another. */
|
|
41
42
|
export async function drivingRoute(from, to, options) {
|
|
42
|
-
const body = (await getJson(`${options.baseUrl ?? OSRM_URL}/route/v1/driving/${from.lon},${from.lat};${to.lon},${to.lat}?overview=false`, { timeoutMs: options.timeoutMs, signal: options.signal }, "OSRM"));
|
|
43
|
+
const body = (await getJson(`${options.baseUrl ?? OSRM_URL}/route/v1/driving/${from.lon},${from.lat};${to.lon},${to.lat}?overview=false`, { timeoutMs: options.timeoutMs, signal: options.signal, fetch: options.fetch }, "OSRM"));
|
|
43
44
|
const route = body.routes?.[0];
|
|
44
45
|
if (body.code !== "Ok" || route?.duration === undefined || route.distance === undefined) {
|
|
45
46
|
throw new Error(`OSRM found no route (${body.code ?? "no code"})`);
|
package/dist/geo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,6HAA6H;AAC7H,MAAM,CAAC,MAAM,aAAa,GAAG,qCAAqC,CAAC;AAEnE,0GAA0G;AAC1G,MAAM,CAAC,MAAM,QAAQ,GAAG,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,6HAA6H;AAC7H,MAAM,CAA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IAAI,GAAG,CAAC,MAAM,OAAO,CACzB,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,qBAAqB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,iBAAiB,EAC5G,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAC9E,MAAM,CACP,CAAgF,CAAC;IAClF,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,EAAE,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,IAAI,IAAI,SAAS,GAAG,CAAC,CAAC;IACrE,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;QACjD,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;KACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geohash of a point, and the cell of a geohash. A geohash interleaves the bits of the
|
|
3
|
+
* longitude and the latitude, and writes five bits as one character of a base-32 alphabet.
|
|
4
|
+
*/
|
|
5
|
+
import type { Point } from "./geo.js";
|
|
6
|
+
/** The base-32 alphabet of the geohash. It has no `a`, `i`, `l` or `o`. */
|
|
7
|
+
export declare const GEOHASH_ALPHABET = "0123456789bcdefghjkmnpqrstuvwxyz";
|
|
8
|
+
/** The precision (number of characters) when the caller gives none. At the equator, a cell of 7 characters is approximately 153 m by 153 m. */
|
|
9
|
+
export declare const DEFAULT_GEOHASH_PRECISION = 7;
|
|
10
|
+
/** The maximum precision. A cell of 12 characters is smaller than 4 cm by 4 cm. */
|
|
11
|
+
export declare const MAX_GEOHASH_PRECISION = 12;
|
|
12
|
+
/** The cell of a geohash: its edges, in degrees, and its center. */
|
|
13
|
+
export interface GeohashCell {
|
|
14
|
+
readonly south: number;
|
|
15
|
+
readonly west: number;
|
|
16
|
+
readonly north: number;
|
|
17
|
+
readonly east: number;
|
|
18
|
+
readonly center: Point;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* This function gives the geohash of a point. The first bit is the longitude. A coordinate on
|
|
22
|
+
* the middle of a range goes to the upper half.
|
|
23
|
+
*/
|
|
24
|
+
export declare const geohash: (point: Point, precision?: number) => string;
|
|
25
|
+
/**
|
|
26
|
+
* This function gives the cell of a geohash: its edges and its center. Upper case letters are
|
|
27
|
+
* correct. It throws a `RangeError` for a character that is not in the alphabet.
|
|
28
|
+
*/
|
|
29
|
+
export declare const decodeGeohash: (hash: string) => GeohashCell;
|
|
30
|
+
//# sourceMappingURL=geohash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash.d.ts","sourceRoot":"","sources":["../src/geohash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,qCAAqC,CAAC;AAEnE,+IAA+I;AAC/I,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;CACxB;AAOD;;;GAGG;AACH,eAAO,MAAM,OAAO,UAAW,KAAK,cAAa,MAAM,KAA+B,MA+BrF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,KAAG,WAyB5C,CAAC"}
|
package/dist/geohash.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geohash of a point, and the cell of a geohash. A geohash interleaves the bits of the
|
|
3
|
+
* longitude and the latitude, and writes five bits as one character of a base-32 alphabet.
|
|
4
|
+
*/
|
|
5
|
+
/** The base-32 alphabet of the geohash. It has no `a`, `i`, `l` or `o`. */
|
|
6
|
+
export const GEOHASH_ALPHABET = "0123456789bcdefghjkmnpqrstuvwxyz";
|
|
7
|
+
/** The precision (number of characters) when the caller gives none. At the equator, a cell of 7 characters is approximately 153 m by 153 m. */
|
|
8
|
+
export const DEFAULT_GEOHASH_PRECISION = 7;
|
|
9
|
+
/** The maximum precision. A cell of 12 characters is smaller than 4 cm by 4 cm. */
|
|
10
|
+
export const MAX_GEOHASH_PRECISION = 12;
|
|
11
|
+
const checkPoint = (point) => {
|
|
12
|
+
if (!Number.isFinite(point.lat) || point.lat < -90 || point.lat > 90)
|
|
13
|
+
throw new RangeError(`The latitude ${point.lat} is not from -90 to 90`);
|
|
14
|
+
if (!Number.isFinite(point.lon) || point.lon < -180 || point.lon > 180)
|
|
15
|
+
throw new RangeError(`The longitude ${point.lon} is not from -180 to 180`);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This function gives the geohash of a point. The first bit is the longitude. A coordinate on
|
|
19
|
+
* the middle of a range goes to the upper half.
|
|
20
|
+
*/
|
|
21
|
+
export const geohash = (point, precision = DEFAULT_GEOHASH_PRECISION) => {
|
|
22
|
+
checkPoint(point);
|
|
23
|
+
if (!Number.isInteger(precision) || precision < 1 || precision > MAX_GEOHASH_PRECISION) {
|
|
24
|
+
throw new RangeError(`The precision ${precision} is not an integer from 1 to ${MAX_GEOHASH_PRECISION}`);
|
|
25
|
+
}
|
|
26
|
+
const latRange = [-90, 90];
|
|
27
|
+
const lonRange = [-180, 180];
|
|
28
|
+
let hash = "";
|
|
29
|
+
let bits = 0;
|
|
30
|
+
let value = 0;
|
|
31
|
+
let evenBit = true;
|
|
32
|
+
while (hash.length < precision) {
|
|
33
|
+
const range = evenBit ? lonRange : latRange;
|
|
34
|
+
const coordinate = evenBit ? point.lon : point.lat;
|
|
35
|
+
const mid = (range[0] + range[1]) / 2;
|
|
36
|
+
if (coordinate >= mid) {
|
|
37
|
+
value = (value << 1) | 1;
|
|
38
|
+
range[0] = mid;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
value <<= 1;
|
|
42
|
+
range[1] = mid;
|
|
43
|
+
}
|
|
44
|
+
evenBit = !evenBit;
|
|
45
|
+
bits += 1;
|
|
46
|
+
if (bits === 5) {
|
|
47
|
+
hash += GEOHASH_ALPHABET[value];
|
|
48
|
+
bits = 0;
|
|
49
|
+
value = 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return hash;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* This function gives the cell of a geohash: its edges and its center. Upper case letters are
|
|
56
|
+
* correct. It throws a `RangeError` for a character that is not in the alphabet.
|
|
57
|
+
*/
|
|
58
|
+
export const decodeGeohash = (hash) => {
|
|
59
|
+
if (hash.length === 0 || hash.length > MAX_GEOHASH_PRECISION) {
|
|
60
|
+
throw new RangeError(`A geohash has 1 to ${MAX_GEOHASH_PRECISION} characters`);
|
|
61
|
+
}
|
|
62
|
+
const lat = [-90, 90];
|
|
63
|
+
const lon = [-180, 180];
|
|
64
|
+
let evenBit = true;
|
|
65
|
+
for (const char of hash.toLowerCase()) {
|
|
66
|
+
const value = GEOHASH_ALPHABET.indexOf(char);
|
|
67
|
+
if (value === -1)
|
|
68
|
+
throw new RangeError(`"${char}" is not a character of a geohash`);
|
|
69
|
+
for (let bit = 4; bit >= 0; bit -= 1) {
|
|
70
|
+
const range = evenBit ? lon : lat;
|
|
71
|
+
const mid = (range[0] + range[1]) / 2;
|
|
72
|
+
if ((value >> bit) & 1)
|
|
73
|
+
range[0] = mid;
|
|
74
|
+
else
|
|
75
|
+
range[1] = mid;
|
|
76
|
+
evenBit = !evenBit;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
south: lat[0],
|
|
81
|
+
west: lon[0],
|
|
82
|
+
north: lat[1],
|
|
83
|
+
east: lon[1],
|
|
84
|
+
center: { lat: (lat[0] + lat[1]) / 2, lon: (lon[0] + lon[1]) / 2 },
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=geohash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash.js","sourceRoot":"","sources":["../src/geohash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,kCAAkC,CAAC;AAEnE,+IAA+I;AAC/I,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,mFAAmF;AACnF,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAWxC,MAAM,UAAU,GAAG,CAAC,KAAY,EAAQ,EAAE;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,KAAK,CAAC,GAAG,GAAG,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,KAAK,CAAC,GAAG,wBAAwB,CAAC,CAAC;IAC9I,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAA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C,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YAClC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACtC,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC;gBAAE,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;;gBAClC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACpB,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QACb,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QACZ,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QACb,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QACZ,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;KACnE,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* geo.distance procedure
|
|
3
|
+
*
|
|
4
|
+
* Give the great-circle distance between two points
|
|
5
|
+
*/
|
|
6
|
+
import type { GeoDistanceInput, GeoDistanceOutput } from "../../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the great-circle distance between two points, in kilometres. It changes
|
|
9
|
+
* nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function geoDistance(input: GeoDistanceInput): Promise<GeoDistanceOutput>;
|
|
12
|
+
//# sourceMappingURL=distance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.d.ts","sourceRoot":"","sources":["../../../src/procedures/geo/distance.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE1E;;;GAGG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAErF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* geo.distance procedure
|
|
3
|
+
*
|
|
4
|
+
* Give the great-circle distance between two points
|
|
5
|
+
*/
|
|
6
|
+
import { greatCircleKm } from "../../distance.js";
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the great-circle distance between two points, in kilometres. It changes
|
|
9
|
+
* nothing.
|
|
10
|
+
*/
|
|
11
|
+
export async function geoDistance(input) {
|
|
12
|
+
return { km: greatCircleKm(input.from, input.to) };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=distance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distance.js","sourceRoot":"","sources":["../../../src/procedures/geo/distance.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAuB;IACvD,OAAO,EAAE,EAAE,EAAE,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* geo.geohash procedure
|
|
3
|
+
*
|
|
4
|
+
* Give the geohash of a point
|
|
5
|
+
*/
|
|
6
|
+
import type { GeoGeohashInput, GeoGeohashOutput } from "../../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the geohash of a point and the cell of that geohash. It changes nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function geoGeohash(input: GeoGeohashInput): Promise<GeoGeohashOutput>;
|
|
11
|
+
//# sourceMappingURL=geohash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash.d.ts","sourceRoot":"","sources":["../../../src/procedures/geo/geohash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE;;GAEG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGlF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* geo.geohash procedure
|
|
3
|
+
*
|
|
4
|
+
* Give the geohash of a point
|
|
5
|
+
*/
|
|
6
|
+
import { decodeGeohash, geohash } from "../../geohash.js";
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the geohash of a point and the cell of that geohash. It changes nothing.
|
|
9
|
+
*/
|
|
10
|
+
export async function geoGeohash(input) {
|
|
11
|
+
const hash = geohash(input.point, input.precision);
|
|
12
|
+
return { hash, cell: decodeGeohash(hash) };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=geohash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geohash.js","sourceRoot":"","sources":["../../../src/procedures/geo/geohash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAsB;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACnD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/procedures/geo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/procedures/geo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/procedures.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The procedures of `@procedures/geo`: `geo.geocode` and `geo.
|
|
2
|
+
* The procedures of `@procedures/geo`: `geo.geocode`, `geo.route`, `geo.distance` and `geo.geohash`.
|
|
3
3
|
*/
|
|
4
4
|
import { type AnyProcedure } from "@procedures/client";
|
|
5
5
|
export declare const geoGeocodeProcedure: AnyProcedure;
|
|
6
6
|
export declare const geoRouteProcedure: AnyProcedure;
|
|
7
|
+
export declare const geoDistanceProcedure: AnyProcedure;
|
|
8
|
+
export declare const geoGeohashProcedure: AnyProcedure;
|
|
7
9
|
export declare const geoProcedures: AnyProcedure[];
|
|
8
10
|
//# sourceMappingURL=procedures.d.ts.map
|
package/dist/procedures.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAA+B,KAAK,YAAY,EAAyB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAA+B,KAAK,YAAY,EAAyB,MAAM,oBAAoB,CAAC;AA8C3G,eAAO,MAAM,mBAAmB,EAAE,YAcR,CAAC;AAe3B,eAAO,MAAM,iBAAiB,EAAE,YAaN,CAAC;AAM3B,eAAO,MAAM,oBAAoB,EAAE,YAUT,CAAC;AAM3B,eAAO,MAAM,mBAAmB,EAAE,YAUR,CAAC;AAE3B,eAAO,MAAM,aAAa,EAAE,YAAY,EAAwF,CAAC"}
|
package/dist/procedures.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The procedures of `@procedures/geo`: `geo.geocode` and `geo.
|
|
2
|
+
* The procedures of `@procedures/geo`: `geo.geocode`, `geo.route`, `geo.distance` and `geo.geohash`.
|
|
3
3
|
*/
|
|
4
4
|
import { createProcedure, zodAdapter } from "@procedures/client";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { drivingRoute, geocode } from "./geo.js";
|
|
7
|
+
import { geoDistance } from "./procedures/geo/distance.js";
|
|
8
|
+
import { geoGeohash } from "./procedures/geo/geohash.js";
|
|
9
|
+
import { GeoDistanceInputSchema, GeoDistanceOutputSchema, GeoGeohashInputSchema, GeoGeohashOutputSchema, } from "./types.js";
|
|
7
10
|
const NETWORK_READ = { reads: ["network"], writes: [] };
|
|
11
|
+
const PURE = { reads: [], writes: [] };
|
|
8
12
|
const point = z.object({ lat: z.number().min(-90).max(90), lon: z.number().min(-180).max(180) });
|
|
9
13
|
const timeoutMs = z.number().int().positive().max(120_000).default(20_000).describe("The time limit, in milliseconds (default: 20000)");
|
|
10
14
|
// =============================================================================
|
|
@@ -60,5 +64,33 @@ export const geoRouteProcedure = createProcedure()
|
|
|
60
64
|
})
|
|
61
65
|
.handler(async (input, ctx) => drivingRoute(input.from, input.to, { baseUrl: input.baseUrl, timeoutMs: input.timeoutMs, signal: ctx?.signal }))
|
|
62
66
|
.build();
|
|
63
|
-
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// geo.distance
|
|
69
|
+
// =============================================================================
|
|
70
|
+
export const geoDistanceProcedure = createProcedure()
|
|
71
|
+
.path(["geo", "distance"])
|
|
72
|
+
.input(zodAdapter(GeoDistanceInputSchema))
|
|
73
|
+
.output(zodAdapter(GeoDistanceOutputSchema))
|
|
74
|
+
.meta({
|
|
75
|
+
description: "Give the great-circle distance between two points in kilometres (haversine), without the network",
|
|
76
|
+
output: "json",
|
|
77
|
+
effects: PURE,
|
|
78
|
+
})
|
|
79
|
+
.handler(async (input) => geoDistance(input))
|
|
80
|
+
.build();
|
|
81
|
+
// =============================================================================
|
|
82
|
+
// geo.geohash
|
|
83
|
+
// =============================================================================
|
|
84
|
+
export const geoGeohashProcedure = createProcedure()
|
|
85
|
+
.path(["geo", "geohash"])
|
|
86
|
+
.input(zodAdapter(GeoGeohashInputSchema))
|
|
87
|
+
.output(zodAdapter(GeoGeohashOutputSchema))
|
|
88
|
+
.meta({
|
|
89
|
+
description: "Give the geohash of a point and the cell of that geohash, without the network",
|
|
90
|
+
output: "json",
|
|
91
|
+
effects: PURE,
|
|
92
|
+
})
|
|
93
|
+
.handler(async (input) => geoGeohash(input))
|
|
94
|
+
.build();
|
|
95
|
+
export const geoProcedures = [geoGeocodeProcedure, geoRouteProcedure, geoDistanceProcedure, geoGeohashProcedure];
|
|
64
96
|
//# sourceMappingURL=procedures.js.map
|
package/dist/procedures.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedures.js","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAA4C,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAwC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"procedures.js","sourceRoot":"","sources":["../src/procedures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAA4C,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAwC,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,GAKvB,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG,EAAE,KAAK,EAAE,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AC,WAAW,CAAC,KAAK,CAAC,CAAC;KAC1F,KAAK,EAAkB,CAAC;AAE3B,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF,MAAM,CAAC,MAAM,mBAAmB,GAAiB,eAAe,EAAE;KAC/D,IAAI,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;KACxB,KAAK,CAAC,UAAU,CAAkB,qBAAqB,CAAC,CAAC;KACzD,MAAM,CAAC,UAAU,CAAmB,sBAAsB,CAAC,CAAC;KAC5D,IAAI,CAAC;IACJ,WAAW,EAAE,+EAA+E;IAC5F,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,IAAI;CACd,CAAC;KACD,OAAO,CAAC,KAAK,EAAE,KAAsB,EAA6B,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;KACvF,KAAK,EAAkB,CAAC;AAE3B,MAAM,CAAC,MAAM,aAAa,GAAmB,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions of the procedures of this package
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { Point } from "./geo.js";
|
|
6
|
+
import type { GeohashCell } from "./geohash.js";
|
|
7
|
+
/** The input of `geo.distance`: two points. */
|
|
8
|
+
export interface GeoDistanceInput {
|
|
9
|
+
from: Point;
|
|
10
|
+
to: Point;
|
|
11
|
+
}
|
|
12
|
+
/** The output of `geo.distance`: the great-circle distance in kilometres, without rounding. */
|
|
13
|
+
export interface GeoDistanceOutput {
|
|
14
|
+
km: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const GeoDistanceInputSchema: z.ZodType<GeoDistanceInput>;
|
|
17
|
+
export declare const GeoDistanceOutputSchema: z.ZodType<GeoDistanceOutput>;
|
|
18
|
+
/** The input of `geo.geohash`: a point and the number of characters. */
|
|
19
|
+
export interface GeoGeohashInput {
|
|
20
|
+
point: Point;
|
|
21
|
+
precision: number;
|
|
22
|
+
}
|
|
23
|
+
/** The output of `geo.geohash`: the geohash and its cell. */
|
|
24
|
+
export interface GeoGeohashOutput {
|
|
25
|
+
hash: string;
|
|
26
|
+
cell: GeohashCell;
|
|
27
|
+
}
|
|
28
|
+
export declare const GeoGeohashInputSchema: z.ZodType<GeoGeohashInput, {
|
|
29
|
+
point: Point;
|
|
30
|
+
precision?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const GeoGeohashOutputSchema: z.ZodType<GeoGeohashOutput>;
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQhD,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,EAAE,KAAK,CAAC;CACX;AAED,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAG7D,CAAC;AAEH,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAE/D,CAAC;AAMH,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAG7G,CAAC;AAEH,eAAO,MAAM,sBAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAW7D,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions of the procedures of this package
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const point = z.object({ lat: z.number().min(-90).max(90), lon: z.number().min(-180).max(180) });
|
|
6
|
+
export const GeoDistanceInputSchema = z.object({
|
|
7
|
+
from: point.describe("The first point (degrees)"),
|
|
8
|
+
to: point.describe("The second point (degrees)"),
|
|
9
|
+
});
|
|
10
|
+
export const GeoDistanceOutputSchema = z.object({
|
|
11
|
+
km: z.number().describe("The great-circle distance in kilometres (haversine, Earth radius 6371 km), without rounding"),
|
|
12
|
+
});
|
|
13
|
+
export const GeoGeohashInputSchema = z.object({
|
|
14
|
+
point: point.describe("The point (degrees)"),
|
|
15
|
+
precision: z.number().int().min(1).max(12).default(7).describe("The number of characters, from 1 to 12 (default: 7)"),
|
|
16
|
+
});
|
|
17
|
+
export const GeoGeohashOutputSchema = z.object({
|
|
18
|
+
hash: z.string().describe("The geohash"),
|
|
19
|
+
cell: z
|
|
20
|
+
.object({
|
|
21
|
+
south: z.number(),
|
|
22
|
+
west: z.number(),
|
|
23
|
+
north: z.number(),
|
|
24
|
+
east: z.number(),
|
|
25
|
+
center: z.object({ lat: z.number(), lon: z.number() }),
|
|
26
|
+
})
|
|
27
|
+
.describe("The cell of the geohash: its edges and its center (degrees)"),
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["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AAC;QACN,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;KACvD,CAAC;SACD,QAAQ,CAAC,6DAA6D,CAAC;CAC3E,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/geo",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Map procedures: the coordinates of an address (OpenStreetMap Nominatim)
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"description": "Map procedures: the coordinates of an address (OpenStreetMap Nominatim), the time and distance of a drive (OSRM), the great-circle distance and the geohash.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"geocode",
|
|
8
8
|
"nominatim",
|
|
9
9
|
"openstreetmap",
|
|
10
10
|
"osrm",
|
|
11
11
|
"routing",
|
|
12
|
+
"haversine",
|
|
13
|
+
"geohash",
|
|
12
14
|
"procedures"
|
|
13
15
|
],
|
|
14
16
|
"homepage": "https://mark1russell7.github.io/client/",
|
|
@@ -58,7 +60,7 @@
|
|
|
58
60
|
"provenance": true
|
|
59
61
|
},
|
|
60
62
|
"dependencies": {
|
|
61
|
-
"@procedures/client": "0.
|
|
63
|
+
"@procedures/client": "0.4.0",
|
|
62
64
|
"zod": "^4.6.5"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
package/src/distance.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The great-circle distance between two points: the haversine formula on a sphere with the mean
|
|
3
|
+
* radius of the Earth. It uses no network.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Point } from "./geo.js";
|
|
7
|
+
|
|
8
|
+
/** The mean radius of the Earth, in kilometres (IUGG). */
|
|
9
|
+
export const EARTH_RADIUS_KM = 6371;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This function gives the great-circle distance between two points, in kilometres, without
|
|
13
|
+
* rounding. The formula is the haversine formula on a sphere of `EARTH_RADIUS_KM`. The road
|
|
14
|
+
* distance is longer.
|
|
15
|
+
*/
|
|
16
|
+
export const greatCircleKm = (a: Point, b: Point): number => {
|
|
17
|
+
const toRad = (deg: number): number => (deg * Math.PI) / 180;
|
|
18
|
+
const dLat = toRad(b.lat - a.lat);
|
|
19
|
+
const dLon = toRad(b.lon - a.lon);
|
|
20
|
+
const h = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(a.lat)) * Math.cos(toRad(b.lat)) * Math.sin(dLon / 2) ** 2;
|
|
21
|
+
// For two antipodal points, a rounding error can make h a little more than 1, and asin of that is NaN
|
|
22
|
+
return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h)));
|
|
23
|
+
};
|