@mailwoman/spatial 4.9.0 → 4.11.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 +45 -2
- package/out/bbox.d.ts +206 -0
- package/out/bbox.d.ts.map +1 -0
- package/out/bbox.js +267 -0
- package/out/bbox.js.map +1 -0
- package/out/countries/codes.d.ts +528 -0
- package/out/countries/codes.d.ts.map +1 -0
- package/out/countries/codes.js +520 -0
- package/out/countries/codes.js.map +1 -0
- package/out/countries/index.d.ts +8 -0
- package/out/countries/index.d.ts.map +1 -0
- package/out/countries/index.js +8 -0
- package/out/countries/index.js.map +1 -0
- package/out/countries/names.d.ts +23 -0
- package/out/countries/names.d.ts.map +1 -0
- package/out/countries/names.js +264 -0
- package/out/countries/names.js.map +1 -0
- package/out/feature.d.ts +70 -0
- package/out/feature.d.ts.map +1 -0
- package/out/feature.js +8 -0
- package/out/feature.js.map +1 -0
- package/out/geometries/collection.d.ts +29 -0
- package/out/geometries/collection.d.ts.map +1 -0
- package/out/geometries/collection.js +9 -0
- package/out/geometries/collection.js.map +1 -0
- package/out/geometries/index.d.ts +12 -0
- package/out/geometries/index.d.ts.map +1 -0
- package/out/geometries/index.js +12 -0
- package/out/geometries/index.js.map +1 -0
- package/out/geometries/line-string.d.ts +44 -0
- package/out/geometries/line-string.d.ts.map +1 -0
- package/out/geometries/line-string.js +9 -0
- package/out/geometries/line-string.js.map +1 -0
- package/out/geometries/point.d.ts +208 -0
- package/out/geometries/point.d.ts.map +1 -0
- package/out/geometries/point.js +258 -0
- package/out/geometries/point.js.map +1 -0
- package/out/geometries/polygon.d.ts +175 -0
- package/out/geometries/polygon.d.ts.map +1 -0
- package/out/geometries/polygon.js +94 -0
- package/out/geometries/polygon.js.map +1 -0
- package/out/google/index.d.ts +7 -0
- package/out/google/index.d.ts.map +1 -0
- package/out/google/index.js +7 -0
- package/out/google/index.js.map +1 -0
- package/out/google/place-id.d.ts +39 -0
- package/out/google/place-id.d.ts.map +1 -0
- package/out/google/place-id.js +22 -0
- package/out/google/place-id.js.map +1 -0
- package/out/h3/index.d.ts +38 -0
- package/out/h3/index.d.ts.map +1 -0
- package/out/h3/index.js +57 -0
- package/out/h3/index.js.map +1 -0
- package/out/index.d.ts +16 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +16 -0
- package/out/index.js.map +1 -0
- package/out/objects.d.ts +93 -0
- package/out/objects.d.ts.map +1 -0
- package/out/objects.js +42 -0
- package/out/objects.js.map +1 -0
- package/out/position.d.ts +176 -0
- package/out/position.d.ts.map +1 -0
- package/out/position.js +169 -0
- package/out/position.js.map +1 -0
- package/out/projection.d.ts +23 -0
- package/out/projection.d.ts.map +1 -0
- package/out/projection.js +24 -0
- package/out/projection.js.map +1 -0
- package/out/regions/codes.d.ts +30 -0
- package/out/regions/codes.d.ts.map +1 -0
- package/out/regions/codes.js +33 -0
- package/out/regions/codes.js.map +1 -0
- package/out/regions/index.d.ts +8 -0
- package/out/regions/index.d.ts.map +1 -0
- package/out/regions/index.js +8 -0
- package/out/regions/index.js.map +1 -0
- package/out/regions/names.d.ts +20 -0
- package/out/regions/names.d.ts.map +1 -0
- package/out/regions/names.js +20 -0
- package/out/regions/names.js.map +1 -0
- package/out/sdk/index.d.ts +7 -0
- package/out/sdk/index.d.ts.map +1 -0
- package/out/sdk/index.js +7 -0
- package/out/sdk/index.js.map +1 -0
- package/out/sdk/well-known-text.d.ts +62 -0
- package/out/sdk/well-known-text.d.ts.map +1 -0
- package/out/sdk/well-known-text.js +61 -0
- package/out/sdk/well-known-text.js.map +1 -0
- package/out/tsconfig.tsbuildinfo +1 -0
- package/package.json +48 -43
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import type google from "@googlemaps/google-maps-services-js";
|
|
7
|
+
import type { LatLng, LatLngLiteral } from "@googlemaps/google-maps-services-js";
|
|
8
|
+
import { type BBox2DLiteral, type BBox3DLiteral, GeoBoundingBox } from "../bbox.js";
|
|
9
|
+
import { type H3Cell } from "../h3/index.js";
|
|
10
|
+
import { type GeoObjectLiteral } from "../objects.js";
|
|
11
|
+
import { type InternalPointCoordinates, type Coordinates2D as Point2DCoordinates, type Coordinates3D as Point3DCoordinates } from "../position.js";
|
|
12
|
+
/**
|
|
13
|
+
* A JSON-serializeable single point geometry, such as a specific location, address, or longitude,
|
|
14
|
+
* latitude pair.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* {
|
|
18
|
+
* "type": "Point",
|
|
19
|
+
* "coordinates": [100, 0]
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @title Point Geometry
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface PointLiteral extends GeoObjectLiteral {
|
|
27
|
+
/**
|
|
28
|
+
* Declares the type of GeoJSON object as a `Point` geometry.
|
|
29
|
+
*/
|
|
30
|
+
type: "Point";
|
|
31
|
+
/**
|
|
32
|
+
* A pair of coordinates in the form of [longitude, latitude].
|
|
33
|
+
*
|
|
34
|
+
* @see {@linkcode Point2DCoordinates} for more information.
|
|
35
|
+
*/
|
|
36
|
+
coordinates: Point2DCoordinates | Point3DCoordinates;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Type-predicate to determine if the given input is a GeoJSON Point geometry.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isPointLiteral(input: PointLiteral | null | undefined | unknown): input is PointLiteral;
|
|
42
|
+
/**
|
|
43
|
+
* Common interface for Browser Geolocation API coordinates.
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates MDN Web Docs}
|
|
46
|
+
*/
|
|
47
|
+
export interface GeolocationCoordinatesLike {
|
|
48
|
+
latitude: number;
|
|
49
|
+
longitude: number;
|
|
50
|
+
altitude: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type-predicate to determine if the given input appears to be a {@linkcode GeolocationCoordinates}
|
|
54
|
+
* object.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isGeolocationCoordinatesLike(input: unknown): input is GeolocationCoordinatesLike;
|
|
57
|
+
export type GeoPointInput = PointLiteral | Point2DCoordinates | Point3DCoordinates | GeolocationCoordinatesLike | InternalPointCoordinates | LatLngLiteral | LatLng;
|
|
58
|
+
/**
|
|
59
|
+
* A single point geometry, such as a specific location, address, or longitude, latitude pair.
|
|
60
|
+
*/
|
|
61
|
+
export declare class GeoPoint implements PointLiteral {
|
|
62
|
+
#private;
|
|
63
|
+
/**
|
|
64
|
+
* Declares the type of GeoJSON object as a `Point` geometry.
|
|
65
|
+
*/
|
|
66
|
+
readonly type: "Point";
|
|
67
|
+
/**
|
|
68
|
+
* The bounding box literal of the GeoPoint.
|
|
69
|
+
*
|
|
70
|
+
* @see {@linkcode GeoPoint.bbox} for the actual bounding box object.
|
|
71
|
+
* @see {@linkcode GeoBoundingBox} for creating a bounding box.
|
|
72
|
+
*/
|
|
73
|
+
boundingBox: GeoBoundingBox | null;
|
|
74
|
+
/**
|
|
75
|
+
* The bounding box literal of the GeoPoint.
|
|
76
|
+
*
|
|
77
|
+
* @see {@linkcode BBox2DLiteral} for 2D bounding boxes.
|
|
78
|
+
* @see {@linkcode BBox3DLiteral} for 3D bounding boxes.
|
|
79
|
+
* @see {@linkcode GeoBoundingBox} for creating a bounding box.
|
|
80
|
+
*/
|
|
81
|
+
get bbox(): BBox2DLiteral | BBox3DLiteral | undefined;
|
|
82
|
+
set bbox(bbox: BBox2DLiteral | BBox3DLiteral | undefined);
|
|
83
|
+
get coordinates(): Point2DCoordinates | Point3DCoordinates;
|
|
84
|
+
set coordinates(coords: Point2DCoordinates | Point3DCoordinates);
|
|
85
|
+
/**
|
|
86
|
+
* The longitude of the point in degrees, i.e. the x-coordinate.
|
|
87
|
+
*
|
|
88
|
+
* Values outside the range will be wrapped around to the opposite side of the globe.
|
|
89
|
+
*
|
|
90
|
+
* @minimum -180
|
|
91
|
+
* @maximum 180
|
|
92
|
+
*/
|
|
93
|
+
get longitude(): number;
|
|
94
|
+
set longitude(value: number);
|
|
95
|
+
/**
|
|
96
|
+
* The latitude of the point in degrees, i.e. the y-coordinate.
|
|
97
|
+
*
|
|
98
|
+
* Values outside the range will be clamped to the poles.
|
|
99
|
+
*
|
|
100
|
+
* @minimum -90
|
|
101
|
+
* @maximum 90
|
|
102
|
+
*/
|
|
103
|
+
get latitude(): number;
|
|
104
|
+
set latitude(value: number);
|
|
105
|
+
/**
|
|
106
|
+
* The altitude of the point, i.e. the z-coordinate.
|
|
107
|
+
*
|
|
108
|
+
* This is optional and is typically measured in meters.
|
|
109
|
+
*/
|
|
110
|
+
get altitude(): number;
|
|
111
|
+
set altitude(value: number);
|
|
112
|
+
/**
|
|
113
|
+
* Create a new GeoPoint object with default coordinates.
|
|
114
|
+
*/
|
|
115
|
+
constructor();
|
|
116
|
+
/**
|
|
117
|
+
* Create a new GeoPoint instance from another {@linkcode GeoJSONPosition} coordinates.
|
|
118
|
+
*/
|
|
119
|
+
constructor(geoJSONPosition: Point2DCoordinates | Point3DCoordinates, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
120
|
+
/**
|
|
121
|
+
* Create a new GeoPoint instance from the browser's Geolocation API coordinates.
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates MDN Web Docs}
|
|
124
|
+
*/
|
|
125
|
+
constructor(geoLocationCoordinates: GeolocationCoordinatesLike, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new GeoPoint instance from a Google Maps API
|
|
128
|
+
* {@linkcode google.LatLngLiteral | LatLngLiteral} object.
|
|
129
|
+
*/
|
|
130
|
+
constructor(latLngLiteral: google.LatLngLiteral, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
131
|
+
/**
|
|
132
|
+
* Creates a new GeoPoint instance from internal coordinates.
|
|
133
|
+
*/
|
|
134
|
+
constructor(interpolatedCoords: InternalPointCoordinates, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new GeoPoint instance from a Google Maps API {@linkcode google.LatLng | LatLng}
|
|
137
|
+
* object.
|
|
138
|
+
*/
|
|
139
|
+
constructor(latLng: LatLngLiteral, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
140
|
+
/**
|
|
141
|
+
* Create a new GeoPoint instance from another {@linkcode PointLiteral}.
|
|
142
|
+
*/
|
|
143
|
+
constructor(geoPointJSON: PointLiteral, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
144
|
+
/**
|
|
145
|
+
* Create a new GeoPoint instance.
|
|
146
|
+
*/
|
|
147
|
+
constructor(input: GeoPointInput, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox);
|
|
148
|
+
/**
|
|
149
|
+
* Attempts to create a new GeoPoint instance from the given input.
|
|
150
|
+
*/
|
|
151
|
+
static from(input: unknown): GeoPoint | null;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the GeoPoint is 2-dimensional.
|
|
154
|
+
*/
|
|
155
|
+
is2D(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Whether the GeoPoint is 3-dimensional.
|
|
158
|
+
*/
|
|
159
|
+
is3D(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Whether the GeoPoint is the null island at 0, 0.
|
|
162
|
+
*/
|
|
163
|
+
isNullIsland(): boolean;
|
|
164
|
+
toJSON(): PointLiteral;
|
|
165
|
+
to2DCoordinates(): Point2DCoordinates;
|
|
166
|
+
to3DCoordinates(): Point3DCoordinates;
|
|
167
|
+
/**
|
|
168
|
+
* Converts the GeoPoint to a Google Maps API {@linkcode google.LatLngLiteral | LatLngLiteral}
|
|
169
|
+
* object.
|
|
170
|
+
*/
|
|
171
|
+
toGoogleLatLngLiteral(): google.LatLngLiteral;
|
|
172
|
+
/**
|
|
173
|
+
* Converts the GeoPoint to DMS (Degrees, Minutes, Seconds) format.
|
|
174
|
+
*/
|
|
175
|
+
toDMS(): string;
|
|
176
|
+
/**
|
|
177
|
+
* Converts the GeoPoint to a H3 short cell address.
|
|
178
|
+
*/
|
|
179
|
+
toH3Cell(resolution?: number): H3Cell;
|
|
180
|
+
/**
|
|
181
|
+
* Converts the GeoPoint to a H3 short cell address.
|
|
182
|
+
*/
|
|
183
|
+
toH3ShortCell(resolution?: number): import("../h3/index.js").H3CellShort;
|
|
184
|
+
toString(): string;
|
|
185
|
+
[Symbol.iterator](): Iterator<number>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* An array of positions for each point in the geometry.
|
|
189
|
+
*
|
|
190
|
+
* @see {@linkcode GeoJSONPosition} for more information.
|
|
191
|
+
*/
|
|
192
|
+
export type MultiPointPath = [...points: Array<Point2DCoordinates | Point3DCoordinates>];
|
|
193
|
+
/**
|
|
194
|
+
* A collection of points, such as a constellation or a set of locations.
|
|
195
|
+
*/
|
|
196
|
+
export interface MultiPointLiteral extends GeoObjectLiteral {
|
|
197
|
+
/**
|
|
198
|
+
* Declares the type of GeoJSON object as a `MultiPoint` geometry.
|
|
199
|
+
*/
|
|
200
|
+
type: "MultiPoint";
|
|
201
|
+
/**
|
|
202
|
+
* An array of positions for each point in the geometry.
|
|
203
|
+
*
|
|
204
|
+
* @see {@linkcode GeoJSONPosition} for more information.
|
|
205
|
+
*/
|
|
206
|
+
coordinates: MultiPointPath;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../geometries/point.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAA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AE,IAAI,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,cAAc;IAiCvF;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA0B5C;;OAEG;IACI,IAAI;IAIX;;OAEG;IACI,IAAI;IAIX;;OAEG;IACI,YAAY,IAAI,OAAO;IAQvB,MAAM,IAAI,YAAY;IAOtB,eAAe,IAAI,kBAAkB;IAIrC,eAAe,IAAI,kBAAkB;IAI5C;;;OAGG;IACI,qBAAqB,IAAI,MAAM,CAAC,aAAa;IAOpD;;OAEG;IACI,KAAK,IAAI,MAAM;IAMtB;;OAEG;IACI,QAAQ,CAAC,UAAU,SAAK;IAM/B;;OAEG;IACI,aAAa,CAAC,UAAU,SAAK;IAM7B,QAAQ,IAAI,MAAM;IAKlB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC;CAG5C;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,CAAC,CAAA;AAExF;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IAC1D;;OAEG;IACH,IAAI,EAAE,YAAY,CAAA;IAClB;;;;OAIG;IACH,WAAW,EAAE,cAAc,CAAA;CAC3B"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { tryParsingJSON } from "@mailwoman/core/objects";
|
|
7
|
+
import { convert as convertCoords } from "geo-coordinates-parser";
|
|
8
|
+
import { latLngToCell } from "h3-js";
|
|
9
|
+
import { GeoBoundingBox, isBBox } from "../bbox.js";
|
|
10
|
+
import { shortenH3Cell } from "../h3/index.js";
|
|
11
|
+
import { GeometryType } from "../objects.js";
|
|
12
|
+
import { clampLatitude, inferGeoJSONCoordOrder, isCoordPairLiteral, isGoogleMapsLatLngLiteral, isInterpolatedCoordinates, wrapLongitude, } from "../position.js";
|
|
13
|
+
/**
|
|
14
|
+
* Type-predicate to determine if the given input is a GeoJSON Point geometry.
|
|
15
|
+
*/
|
|
16
|
+
export function isPointLiteral(input) {
|
|
17
|
+
if (!input || typeof input !== "object")
|
|
18
|
+
return false;
|
|
19
|
+
if (!("type" in input))
|
|
20
|
+
return false;
|
|
21
|
+
if (!("coordinates" in input))
|
|
22
|
+
return false;
|
|
23
|
+
if (input.type !== GeometryType.Point)
|
|
24
|
+
return false;
|
|
25
|
+
return isCoordPairLiteral(input.coordinates);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Type-predicate to determine if the given input appears to be a {@linkcode GeolocationCoordinates}
|
|
29
|
+
* object.
|
|
30
|
+
*/
|
|
31
|
+
export function isGeolocationCoordinatesLike(input) {
|
|
32
|
+
if (!input || typeof input !== "object")
|
|
33
|
+
return false;
|
|
34
|
+
if (!("latitude" in input))
|
|
35
|
+
return false;
|
|
36
|
+
if (!("longitude" in input))
|
|
37
|
+
return false;
|
|
38
|
+
if (!("altitude" in input))
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
//#region GeoPoint
|
|
43
|
+
/**
|
|
44
|
+
* A single point geometry, such as a specific location, address, or longitude, latitude pair.
|
|
45
|
+
*/
|
|
46
|
+
export class GeoPoint {
|
|
47
|
+
//#region Properties
|
|
48
|
+
/**
|
|
49
|
+
* Declares the type of GeoJSON object as a `Point` geometry.
|
|
50
|
+
*/
|
|
51
|
+
type = GeometryType.Point;
|
|
52
|
+
/**
|
|
53
|
+
* The bounding box literal of the GeoPoint.
|
|
54
|
+
*
|
|
55
|
+
* @see {@linkcode GeoPoint.bbox} for the actual bounding box object.
|
|
56
|
+
* @see {@linkcode GeoBoundingBox} for creating a bounding box.
|
|
57
|
+
*/
|
|
58
|
+
boundingBox = null;
|
|
59
|
+
/**
|
|
60
|
+
* The bounding box literal of the GeoPoint.
|
|
61
|
+
*
|
|
62
|
+
* @see {@linkcode BBox2DLiteral} for 2D bounding boxes.
|
|
63
|
+
* @see {@linkcode BBox3DLiteral} for 3D bounding boxes.
|
|
64
|
+
* @see {@linkcode GeoBoundingBox} for creating a bounding box.
|
|
65
|
+
*/
|
|
66
|
+
get bbox() {
|
|
67
|
+
return this.boundingBox?.toJSON();
|
|
68
|
+
}
|
|
69
|
+
set bbox(bbox) {
|
|
70
|
+
this.boundingBox = bbox ? new GeoBoundingBox(bbox) : null;
|
|
71
|
+
}
|
|
72
|
+
get coordinates() {
|
|
73
|
+
if (this.is3D()) {
|
|
74
|
+
return [this.#longitude, this.#latitude, this.#altitude];
|
|
75
|
+
}
|
|
76
|
+
return [this.#longitude, this.#latitude];
|
|
77
|
+
}
|
|
78
|
+
set coordinates(coords) {
|
|
79
|
+
const [longitude, latitude, altitude] = coords;
|
|
80
|
+
this.#longitude = longitude;
|
|
81
|
+
this.#latitude = latitude;
|
|
82
|
+
this.#altitude = typeof altitude === "number" ? altitude : 0;
|
|
83
|
+
}
|
|
84
|
+
#latitude = 0;
|
|
85
|
+
#longitude = 0;
|
|
86
|
+
#altitude = 0;
|
|
87
|
+
/**
|
|
88
|
+
* The longitude of the point in degrees, i.e. the x-coordinate.
|
|
89
|
+
*
|
|
90
|
+
* Values outside the range will be wrapped around to the opposite side of the globe.
|
|
91
|
+
*
|
|
92
|
+
* @minimum -180
|
|
93
|
+
* @maximum 180
|
|
94
|
+
*/
|
|
95
|
+
get longitude() {
|
|
96
|
+
return this.#longitude;
|
|
97
|
+
}
|
|
98
|
+
set longitude(value) {
|
|
99
|
+
this.#longitude = wrapLongitude(value);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The latitude of the point in degrees, i.e. the y-coordinate.
|
|
103
|
+
*
|
|
104
|
+
* Values outside the range will be clamped to the poles.
|
|
105
|
+
*
|
|
106
|
+
* @minimum -90
|
|
107
|
+
* @maximum 90
|
|
108
|
+
*/
|
|
109
|
+
get latitude() {
|
|
110
|
+
return this.#latitude;
|
|
111
|
+
}
|
|
112
|
+
set latitude(value) {
|
|
113
|
+
this.#latitude = clampLatitude(value);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The altitude of the point, i.e. the z-coordinate.
|
|
117
|
+
*
|
|
118
|
+
* This is optional and is typically measured in meters.
|
|
119
|
+
*/
|
|
120
|
+
get altitude() {
|
|
121
|
+
return this.#altitude;
|
|
122
|
+
}
|
|
123
|
+
set altitude(value) {
|
|
124
|
+
this.#altitude = value;
|
|
125
|
+
}
|
|
126
|
+
constructor(input, bbox) {
|
|
127
|
+
if (isCoordPairLiteral(input)) {
|
|
128
|
+
if (input.length === 2) {
|
|
129
|
+
this.coordinates = inferGeoJSONCoordOrder(input);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.coordinates = input;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (isPointLiteral(input)) {
|
|
136
|
+
this.coordinates = [...input.coordinates];
|
|
137
|
+
if (isBBox(input.bbox)) {
|
|
138
|
+
this.bbox = [...input.bbox];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (isGoogleMapsLatLngLiteral(input)) {
|
|
142
|
+
this.coordinates = [input.lng, input.lat];
|
|
143
|
+
}
|
|
144
|
+
else if (isGeolocationCoordinatesLike(input)) {
|
|
145
|
+
this.#longitude = input.longitude;
|
|
146
|
+
this.#latitude = input.latitude;
|
|
147
|
+
this.#altitude = input.altitude || 0;
|
|
148
|
+
}
|
|
149
|
+
else if (isInterpolatedCoordinates(input)) {
|
|
150
|
+
this.#longitude = input.x;
|
|
151
|
+
this.#latitude = input.y;
|
|
152
|
+
this.#altitude = 0;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.coordinates = [0, 0];
|
|
156
|
+
}
|
|
157
|
+
if (isBBox(bbox)) {
|
|
158
|
+
this.bbox = bbox;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Attempts to create a new GeoPoint instance from the given input.
|
|
163
|
+
*/
|
|
164
|
+
static from(input) {
|
|
165
|
+
if (!input)
|
|
166
|
+
return null;
|
|
167
|
+
if (input instanceof GeoPoint)
|
|
168
|
+
return input;
|
|
169
|
+
if (typeof input === "string") {
|
|
170
|
+
const coordinates = tryParsingJSON(input) || tryParsingJSON(`[${input}]`);
|
|
171
|
+
if (coordinates) {
|
|
172
|
+
input = coordinates;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const point = new GeoPoint(input);
|
|
177
|
+
if (point.isNullIsland())
|
|
178
|
+
return null;
|
|
179
|
+
return point;
|
|
180
|
+
}
|
|
181
|
+
catch (_error) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region Predicates
|
|
187
|
+
/**
|
|
188
|
+
* Whether the GeoPoint is 2-dimensional.
|
|
189
|
+
*/
|
|
190
|
+
is2D() {
|
|
191
|
+
return !this.is3D();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Whether the GeoPoint is 3-dimensional.
|
|
195
|
+
*/
|
|
196
|
+
is3D() {
|
|
197
|
+
return this.#altitude !== 0;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Whether the GeoPoint is the null island at 0, 0.
|
|
201
|
+
*/
|
|
202
|
+
isNullIsland() {
|
|
203
|
+
return this.#latitude === 0 && this.#longitude === 0;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region Conversion
|
|
207
|
+
toJSON() {
|
|
208
|
+
return {
|
|
209
|
+
type: this.type,
|
|
210
|
+
coordinates: this.coordinates,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
to2DCoordinates() {
|
|
214
|
+
return [this.#longitude, this.#latitude];
|
|
215
|
+
}
|
|
216
|
+
to3DCoordinates() {
|
|
217
|
+
return [this.#longitude, this.#latitude, this.#altitude];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Converts the GeoPoint to a Google Maps API {@linkcode google.LatLngLiteral | LatLngLiteral}
|
|
221
|
+
* object.
|
|
222
|
+
*/
|
|
223
|
+
toGoogleLatLngLiteral() {
|
|
224
|
+
return {
|
|
225
|
+
lat: this.#latitude,
|
|
226
|
+
lng: this.#longitude,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Converts the GeoPoint to DMS (Degrees, Minutes, Seconds) format.
|
|
231
|
+
*/
|
|
232
|
+
toDMS() {
|
|
233
|
+
const converter = convertCoords(`${this.#latitude},${this.#longitude}`);
|
|
234
|
+
return converter.toCoordinateFormat("DMS");
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Converts the GeoPoint to a H3 short cell address.
|
|
238
|
+
*/
|
|
239
|
+
toH3Cell(resolution = 15) {
|
|
240
|
+
const cell = latLngToCell(this.#latitude, this.#longitude, resolution);
|
|
241
|
+
return cell;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Converts the GeoPoint to a H3 short cell address.
|
|
245
|
+
*/
|
|
246
|
+
toH3ShortCell(resolution = 15) {
|
|
247
|
+
const cell = this.toH3Cell(resolution);
|
|
248
|
+
return shortenH3Cell(cell);
|
|
249
|
+
}
|
|
250
|
+
toString() {
|
|
251
|
+
return JSON.stringify(this.toJSON());
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
[Symbol.iterator]() {
|
|
255
|
+
return this.coordinates[Symbol.iterator]();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"point.js","sourceRoot":"","sources":["../../geometries/point.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,E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,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;QAEtC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,YAAY;IAEL,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC3C,CAAC;CACD"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import type { GeoObjectLiteral } from "../objects.js";
|
|
7
|
+
import type { LineStringPath } from "./line-string.js";
|
|
8
|
+
/**
|
|
9
|
+
* An array of positions forming a closed shape, such as a country or a lake.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* A polygon without holes:
|
|
14
|
+
*
|
|
15
|
+
* ```json
|
|
16
|
+
* {
|
|
17
|
+
* "type": "Polygon",
|
|
18
|
+
* "coordinates": [
|
|
19
|
+
* [
|
|
20
|
+
* [100, 0],
|
|
21
|
+
* [101, 0],
|
|
22
|
+
* [101, 1],
|
|
23
|
+
* [100, 1],
|
|
24
|
+
* [100, 0]
|
|
25
|
+
* ]
|
|
26
|
+
* ]
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type SolidPolygonPath = [
|
|
31
|
+
/**
|
|
32
|
+
* - A linear ring is a closed LineString with four or more positions.
|
|
33
|
+
* - The first and last positions are equivalent (they represent equivalent points).
|
|
34
|
+
*/
|
|
35
|
+
exteriorRing: LineStringPath
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* An array of positions forming a closed shape with holes, such as a country with islands or a lake
|
|
39
|
+
* with islands.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* A polygon with holes:
|
|
44
|
+
*
|
|
45
|
+
* ```json
|
|
46
|
+
* {
|
|
47
|
+
* "type": "Polygon",
|
|
48
|
+
* "coordinates": [
|
|
49
|
+
* [
|
|
50
|
+
* [100.0, 0.0],
|
|
51
|
+
* [101.0, 0.0],
|
|
52
|
+
* [101.0, 1.0],
|
|
53
|
+
* [100.0, 1.0],
|
|
54
|
+
* [100.0, 0.0]
|
|
55
|
+
* ],
|
|
56
|
+
* [
|
|
57
|
+
* [100.8, 0.8],
|
|
58
|
+
* [100.8, 0.2],
|
|
59
|
+
* [100.2, 0.2],
|
|
60
|
+
* [100.2, 0.8],
|
|
61
|
+
* [100.8, 0.8]
|
|
62
|
+
* ]
|
|
63
|
+
* ]
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export type NestedPolygonPath = [
|
|
68
|
+
/**
|
|
69
|
+
* - A linear ring is a closed LineString with four or more positions.
|
|
70
|
+
* - The first and last positions are equivalent (they represent equivalent points).
|
|
71
|
+
*/
|
|
72
|
+
exteriorRing: LineStringPath,
|
|
73
|
+
/**
|
|
74
|
+
* - The interior rings are arrays of positions forming holes in the polygon.
|
|
75
|
+
*/
|
|
76
|
+
...interiorRings: LineStringPath[]
|
|
77
|
+
];
|
|
78
|
+
/**
|
|
79
|
+
* A polygon geometry.
|
|
80
|
+
*
|
|
81
|
+
* @see {@linkcode PolygonLiteral} for applicable JSON schema.
|
|
82
|
+
* @see {@linkcode SolidPolygonPath} for more information.
|
|
83
|
+
* @see {@linkcode NestedPolygonPath} for more information.
|
|
84
|
+
*/
|
|
85
|
+
export type PolygonPath = SolidPolygonPath | NestedPolygonPath;
|
|
86
|
+
/**
|
|
87
|
+
* An array of positions forming a closed shape, such as a country or a lake.
|
|
88
|
+
*/
|
|
89
|
+
export interface PolygonLiteral<P extends PolygonPath = SolidPolygonPath> extends GeoObjectLiteral {
|
|
90
|
+
/**
|
|
91
|
+
* Declares the type of GeoJSON object as a `Polygon` geometry.
|
|
92
|
+
*/
|
|
93
|
+
type: "Polygon";
|
|
94
|
+
/**
|
|
95
|
+
* An array of positions for each point in the geometry.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6 | RFC 7946 Section 3.1.6}
|
|
98
|
+
* @see {@linkcode SolidPolygonPath}
|
|
99
|
+
* @see {@linkcode NestedPolygonPath}
|
|
100
|
+
*/
|
|
101
|
+
coordinates: P;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Predicate for checking if a GeoJSON object is a `Polygon` geometry.
|
|
105
|
+
*/
|
|
106
|
+
export declare function isPolygonLiteral<P extends PolygonPath = PolygonPath>(input: unknown): input is PolygonLiteral<P>;
|
|
107
|
+
/**
|
|
108
|
+
* Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isSolidPolygonPath(input: PolygonLiteral): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* A collection of polygons, such as a country with islands or a lake with islands.
|
|
113
|
+
*/
|
|
114
|
+
export interface MultiPolygonLiteral<P extends PolygonPath = SolidPolygonPath> extends GeoObjectLiteral {
|
|
115
|
+
type: "MultiPolygon";
|
|
116
|
+
/**
|
|
117
|
+
* An array of polygons.
|
|
118
|
+
*/
|
|
119
|
+
coordinates: P[][];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Given a polygon geometry, return an OSM filter string.
|
|
126
|
+
*
|
|
127
|
+
* This is useful when working with the Overpass API.
|
|
128
|
+
*/
|
|
129
|
+
export declare function polygonToOSMFilter(input: PolygonLiteral): string;
|
|
130
|
+
/**
|
|
131
|
+
* Tags returned by the Overpass API for a node.
|
|
132
|
+
*
|
|
133
|
+
* @category OSM
|
|
134
|
+
*/
|
|
135
|
+
export declare enum OSMNodeTag {
|
|
136
|
+
HouseNumber = "addr:housenumber",
|
|
137
|
+
PostCode = "addr:postcode",
|
|
138
|
+
Street = "addr:street",
|
|
139
|
+
State = "addr:state",
|
|
140
|
+
City = "addr:city",
|
|
141
|
+
Website = "website",
|
|
142
|
+
Email = "email",
|
|
143
|
+
Phone = "phone",
|
|
144
|
+
Shop = "shop",
|
|
145
|
+
Brand = "brand",
|
|
146
|
+
Cuisine = "cuisine",
|
|
147
|
+
Name = "name",
|
|
148
|
+
Healthcare = "healthcare",
|
|
149
|
+
Office = "office",
|
|
150
|
+
Amenity = "amenity"
|
|
151
|
+
}
|
|
152
|
+
export declare const ForbiddenResidentialOSMNodeTags: ReadonlySet<OSMNodeTag>;
|
|
153
|
+
export type OSMNodeTagRecord = Record<OSMNodeTag, string | undefined>;
|
|
154
|
+
export interface OSMOverpassElement {
|
|
155
|
+
type: "node";
|
|
156
|
+
id: number;
|
|
157
|
+
lat: number;
|
|
158
|
+
lon: number;
|
|
159
|
+
tags: OSMNodeTagRecord;
|
|
160
|
+
}
|
|
161
|
+
export interface OSMOverpassResponseBody {
|
|
162
|
+
version: string;
|
|
163
|
+
generator: string;
|
|
164
|
+
osm3s: {
|
|
165
|
+
timestamp_osm_base: string;
|
|
166
|
+
copyright: string;
|
|
167
|
+
};
|
|
168
|
+
elements: OSMOverpassElement[];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Given an OSM element, attempts to infer if the result is a residential address.
|
|
172
|
+
*/
|
|
173
|
+
export declare function isResidentialElement(element: OSMOverpassElement): boolean;
|
|
174
|
+
export declare function fetchOSMElementViaOverpassAPI(input: PolygonLiteral): Promise<OSMOverpassElement[]>;
|
|
175
|
+
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../geometries/polygon.ts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