@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
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mailwoman/spatial
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Spatial analysis, geocoding, and geo-related utilities for the Mailwoman
|
|
4
|
+
ecosystem. Provides coordinate math, H3 hexagonal grid indexing, WKB geometry
|
|
5
|
+
parsing, and coordinate-string parsing.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { haversineKm, latLngToCell, parseCoordinateString } from "@mailwoman/spatial"
|
|
9
|
+
|
|
10
|
+
// Great-circle distance
|
|
11
|
+
const km = haversineKm(37.7749, -122.4194, 34.0522, -118.2437) // SF → LA
|
|
12
|
+
|
|
13
|
+
// H3 grid cell
|
|
14
|
+
const cell = latLngToCell(37.7749, -122.4194, 9) // resolution-9 H3 index
|
|
15
|
+
|
|
16
|
+
// Parse coordinate strings
|
|
17
|
+
const loc = parseCoordinateString("37.7749° N, 122.4194° W")
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What's inside
|
|
21
|
+
|
|
22
|
+
| Capability | Implementation |
|
|
23
|
+
| ---------------------- | --------------------------------------------------------------------------- |
|
|
24
|
+
| **Coordinate math** | Haversine distance, bearing, bounding-box containment |
|
|
25
|
+
| **H3 indexing** | Hexagonal grid indexing via `h3-js` — spatial blocking for the matcher |
|
|
26
|
+
| **WKB/WKT geometry** | Parse/format Well-Known Binary geometry via `wkx` |
|
|
27
|
+
| **Coordinate parsing** | Parse decimal, DMS, and UTM coordinate strings via `geo-coordinates-parser` |
|
|
28
|
+
| **GeoJSON** | GeoJSON Feature/FeatureCollection types and utilities |
|
|
29
|
+
|
|
30
|
+
## Dependencies
|
|
31
|
+
|
|
32
|
+
- [`h3-js`](https://github.com/uber/h3-js) — Uber's hexagonal hierarchical geospatial indexing system
|
|
33
|
+
- [`wkx`](https://github.com/cschwarz/wkx) — Well-Known Binary geometry parser
|
|
34
|
+
- [`geo-coordinates-parser`](https://github.com/geops/geo-coordinates-parser) — coordinate string parsing
|
|
35
|
+
|
|
36
|
+
Optional: `@googlemaps/google-maps-services-js` for Google Maps API integration.
|
|
37
|
+
|
|
38
|
+
## Related
|
|
39
|
+
|
|
40
|
+
- [`@mailwoman/match`](../match) — uses H3 cells for geo-first record blocking
|
|
41
|
+
- [`@mailwoman/address-id`](../address-id) — uses H3 for stable address primary keys
|
|
42
|
+
- [`@mailwoman/core`](../core) — consumes spatial types
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
[AGPL-3.0-only](https://www.gnu.org/licenses/agpl-3.0.html)
|
package/out/bbox.d.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software.
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* GeoJSON Bounding Boxes
|
|
7
|
+
*/
|
|
8
|
+
import type { PolygonLiteral } from "./geometries/polygon.js";
|
|
9
|
+
import { CoordinateProjection } from "./projection.js";
|
|
10
|
+
/**
|
|
11
|
+
* A 2-dimensional rectangular area that can be determined by two longitudes and two latitudes.
|
|
12
|
+
*
|
|
13
|
+
* @category GeoJSON
|
|
14
|
+
* @category Bounding Box
|
|
15
|
+
* @see {@linkcode BBox} for additional information.
|
|
16
|
+
* @see {@linkcode BBox3DLiteral} for 3-dimensional bounding boxes.
|
|
17
|
+
* @see {@linkcode isBBox} for type-predicates.
|
|
18
|
+
* @see {@link https://tools.ietf.org/html/rfc7946#section-5 GeoJSON Bounding Boxes}
|
|
19
|
+
*/
|
|
20
|
+
export type BBox2DLiteral = [
|
|
21
|
+
/**
|
|
22
|
+
* The most western longitude (in decimal degrees) of the coordinate range.
|
|
23
|
+
*
|
|
24
|
+
* @minimum -180.0
|
|
25
|
+
* @maximum 180.0
|
|
26
|
+
*/
|
|
27
|
+
minLongitude: number,
|
|
28
|
+
/**
|
|
29
|
+
* The most southern latitude (in decimal degrees) of the coordinate range.
|
|
30
|
+
*
|
|
31
|
+
* @minimum -90.0
|
|
32
|
+
* @maximum 90.0
|
|
33
|
+
*/
|
|
34
|
+
minLatitude: number,
|
|
35
|
+
/**
|
|
36
|
+
* The most eastern longitude (in decimal degrees) of the coordinate range.
|
|
37
|
+
*
|
|
38
|
+
* @minimum -180.0
|
|
39
|
+
* @maximum 180.0
|
|
40
|
+
*/
|
|
41
|
+
maxLongitude: number,
|
|
42
|
+
/**
|
|
43
|
+
* The most northern latitude (in decimal degrees) of the coordinate range.
|
|
44
|
+
*
|
|
45
|
+
* @minimum -90.0
|
|
46
|
+
* @maximum 90.0
|
|
47
|
+
*/
|
|
48
|
+
maxLatitude: number
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* A 3-dimensional rectangular area that can be determined by two longitudes, two latitudes, and two
|
|
52
|
+
* altitudes.
|
|
53
|
+
*
|
|
54
|
+
* @category GeoJSON
|
|
55
|
+
* @category Bounding Box
|
|
56
|
+
* @see {@linkcode BBox} for additional information.
|
|
57
|
+
* @see {@linkcode BBox2DLiteral} for a 2-dimensional bounding box.
|
|
58
|
+
* @see {@link https://tools.ietf.org/html/rfc7946#section-5 GeoJSON Bounding Boxes}
|
|
59
|
+
*/
|
|
60
|
+
export type BBox3DLiteral = [
|
|
61
|
+
/**
|
|
62
|
+
* The most western longitude (in decimal degrees) of the coordinate range.
|
|
63
|
+
*
|
|
64
|
+
* @minimum -180.0
|
|
65
|
+
* @maximum 180.0
|
|
66
|
+
*/
|
|
67
|
+
minLongitude: number,
|
|
68
|
+
/**
|
|
69
|
+
* The most southern latitude (in decimal degrees) of the coordinate range.
|
|
70
|
+
*
|
|
71
|
+
* @minimum -90.0
|
|
72
|
+
* @maximum 90.0
|
|
73
|
+
*/
|
|
74
|
+
minLatitude: number,
|
|
75
|
+
/**
|
|
76
|
+
* Altitude of the most western longitude (in decimal degrees) of the coordinate range.
|
|
77
|
+
*/
|
|
78
|
+
minAltitude: number,
|
|
79
|
+
/**
|
|
80
|
+
* The most eastern longitude (in decimal degrees) of the coordinate range.
|
|
81
|
+
*
|
|
82
|
+
* @minimum -180.0
|
|
83
|
+
* @maximum 180.0
|
|
84
|
+
*/
|
|
85
|
+
maxLongitude: number,
|
|
86
|
+
/**
|
|
87
|
+
* The most northern latitude (in decimal degrees) of the coordinate range.
|
|
88
|
+
*
|
|
89
|
+
* @minimum -90.0
|
|
90
|
+
* @maximum 90.0
|
|
91
|
+
*/
|
|
92
|
+
maxLatitude: number,
|
|
93
|
+
/**
|
|
94
|
+
* Altitude of the most eastern longitude (in decimal degrees) of the coordinate range.
|
|
95
|
+
*/
|
|
96
|
+
maxAltitude: number
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* Type-predicate for 3-dimensional bounding boxes.
|
|
100
|
+
*
|
|
101
|
+
* This is useful when determining the type of bounding box in a GeoJSON object.
|
|
102
|
+
*
|
|
103
|
+
* @category GeoJSON
|
|
104
|
+
* @category Bounding Box
|
|
105
|
+
*/
|
|
106
|
+
export declare function is2DBBox(input: unknown): input is BBox3DLiteral;
|
|
107
|
+
/**
|
|
108
|
+
* Type-predicate for 3-dimensional bounding boxes.
|
|
109
|
+
*
|
|
110
|
+
* This is useful when determining the type of bounding box in a GeoJSON object.
|
|
111
|
+
*
|
|
112
|
+
* @category GeoJSON
|
|
113
|
+
* @category Bounding Box
|
|
114
|
+
*/
|
|
115
|
+
export declare function is3DBBox(input: unknown): input is BBox3DLiteral;
|
|
116
|
+
/**
|
|
117
|
+
* Type-predicate to determine if the given input is a bounding box.
|
|
118
|
+
*
|
|
119
|
+
* @category GeoJSON
|
|
120
|
+
* @category Bounding Box
|
|
121
|
+
*/
|
|
122
|
+
export declare function isBBox(input: unknown): input is BBox2DLiteral | BBox3DLiteral;
|
|
123
|
+
/**
|
|
124
|
+
* Type-predicate to determine if the given input is a GeoBoundingBox instance.
|
|
125
|
+
*
|
|
126
|
+
* Note that this function only checks if the input is an instance of the GeoBoundingBox class.
|
|
127
|
+
* `instanceof` checks are not reliable in JavaScript, so this function should be used with
|
|
128
|
+
* caution.
|
|
129
|
+
*
|
|
130
|
+
* @category GeoJSON
|
|
131
|
+
*/
|
|
132
|
+
export declare function isGeoBoundingBox(input: unknown): input is GeoBoundingBox;
|
|
133
|
+
/**
|
|
134
|
+
* Input for creating a GeoBoundingBox instance.
|
|
135
|
+
*/
|
|
136
|
+
export type GeoBoundingBoxInput = BBox2DLiteral | BBox3DLiteral | GeoBoundingBox;
|
|
137
|
+
/**
|
|
138
|
+
* A bounding box to represent the coordinate range of a GeoJSON object.
|
|
139
|
+
*
|
|
140
|
+
* This is useful when defining the extent of a GeoJSON object, such as the minimum and maximum
|
|
141
|
+
* coordinates of the object's Geometries, Features, or Feature Collections.
|
|
142
|
+
*/
|
|
143
|
+
export declare class GeoBoundingBox {
|
|
144
|
+
#private;
|
|
145
|
+
projection: CoordinateProjection;
|
|
146
|
+
get minLongitude(): number;
|
|
147
|
+
set minLongitude(value: number);
|
|
148
|
+
get minLatitude(): number;
|
|
149
|
+
set minLatitude(value: number);
|
|
150
|
+
get maxLongitude(): number;
|
|
151
|
+
set maxLongitude(value: number);
|
|
152
|
+
get maxLatitude(): number;
|
|
153
|
+
set maxLatitude(value: number);
|
|
154
|
+
get minAltitude(): number;
|
|
155
|
+
set minAltitude(value: number);
|
|
156
|
+
get maxAltitude(): number;
|
|
157
|
+
set maxAltitude(value: number);
|
|
158
|
+
get east(): number;
|
|
159
|
+
set east(value: number);
|
|
160
|
+
get north(): number;
|
|
161
|
+
set north(value: number);
|
|
162
|
+
get south(): number;
|
|
163
|
+
set south(value: number);
|
|
164
|
+
get west(): number;
|
|
165
|
+
set west(value: number);
|
|
166
|
+
get elevation(): number;
|
|
167
|
+
set elevation(value: number);
|
|
168
|
+
get depth(): number;
|
|
169
|
+
set depth(value: number);
|
|
170
|
+
[Symbol.iterator](): ArrayIterator<number>;
|
|
171
|
+
/**
|
|
172
|
+
* Creates a blank GeoBoundingBox instance.
|
|
173
|
+
*/
|
|
174
|
+
constructor();
|
|
175
|
+
/**
|
|
176
|
+
* Creates a new GeoBoundingBox instance from the given 2D bounding box.
|
|
177
|
+
*/
|
|
178
|
+
constructor(bbox: BBox2DLiteral, projection?: CoordinateProjection);
|
|
179
|
+
/**
|
|
180
|
+
* Creates a new GeoBoundingBox instance from the given 3D bounding box.
|
|
181
|
+
*/
|
|
182
|
+
constructor(bbox: BBox3DLiteral, projection?: CoordinateProjection);
|
|
183
|
+
constructor(input?: GeoBoundingBoxInput, projection?: CoordinateProjection);
|
|
184
|
+
is3D(): boolean;
|
|
185
|
+
is2D(): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Converts the 2D GeoBoundingBox to an array literal.
|
|
188
|
+
*/
|
|
189
|
+
toJSON2D(): BBox2DLiteral;
|
|
190
|
+
/**
|
|
191
|
+
* Converts the 3D GeoBoundingBox to an array literal.
|
|
192
|
+
*/
|
|
193
|
+
toJSON3D(): BBox3DLiteral;
|
|
194
|
+
toJSON(): BBox2DLiteral | BBox3DLiteral;
|
|
195
|
+
/**
|
|
196
|
+
* Converts the GeoBoundingBox to a GeoJSON Polygon, omitting the altitude.
|
|
197
|
+
*/
|
|
198
|
+
to2DPolygon(): PolygonLiteral;
|
|
199
|
+
/**
|
|
200
|
+
* Converts the GeoBoundingBox to a Well-Known-Text (WKT) string.
|
|
201
|
+
*
|
|
202
|
+
* This is useful when building Spatialite query parameters.
|
|
203
|
+
*/
|
|
204
|
+
to2DEWKT(): string;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=bbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAItD;;;;;;;;;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;;;;;;;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|
|
5
|
+
*
|
|
6
|
+
* GeoJSON Bounding Boxes
|
|
7
|
+
*/
|
|
8
|
+
import { clampLatitude, wrapLongitude } from "./position.js";
|
|
9
|
+
import { CoordinateProjection } from "./projection.js";
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region Type Predicates
|
|
12
|
+
/**
|
|
13
|
+
* Type-predicate for 3-dimensional bounding boxes.
|
|
14
|
+
*
|
|
15
|
+
* This is useful when determining the type of bounding box in a GeoJSON object.
|
|
16
|
+
*
|
|
17
|
+
* @category GeoJSON
|
|
18
|
+
* @category Bounding Box
|
|
19
|
+
*/
|
|
20
|
+
export function is2DBBox(input) {
|
|
21
|
+
return Array.isArray(input) && input.length === 6;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Type-predicate for 3-dimensional bounding boxes.
|
|
25
|
+
*
|
|
26
|
+
* This is useful when determining the type of bounding box in a GeoJSON object.
|
|
27
|
+
*
|
|
28
|
+
* @category GeoJSON
|
|
29
|
+
* @category Bounding Box
|
|
30
|
+
*/
|
|
31
|
+
export function is3DBBox(input) {
|
|
32
|
+
return Array.isArray(input) && input.length === 6;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Type-predicate to determine if the given input is a bounding box.
|
|
36
|
+
*
|
|
37
|
+
* @category GeoJSON
|
|
38
|
+
* @category Bounding Box
|
|
39
|
+
*/
|
|
40
|
+
export function isBBox(input) {
|
|
41
|
+
return Array.isArray(input) && (input.length === 4 || input.length === 6);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Type-predicate to determine if the given input is a GeoBoundingBox instance.
|
|
45
|
+
*
|
|
46
|
+
* Note that this function only checks if the input is an instance of the GeoBoundingBox class.
|
|
47
|
+
* `instanceof` checks are not reliable in JavaScript, so this function should be used with
|
|
48
|
+
* caution.
|
|
49
|
+
*
|
|
50
|
+
* @category GeoJSON
|
|
51
|
+
*/
|
|
52
|
+
export function isGeoBoundingBox(input) {
|
|
53
|
+
return input instanceof GeoBoundingBox;
|
|
54
|
+
}
|
|
55
|
+
// MARK: - GeoBoundingBox
|
|
56
|
+
/**
|
|
57
|
+
* A bounding box to represent the coordinate range of a GeoJSON object.
|
|
58
|
+
*
|
|
59
|
+
* This is useful when defining the extent of a GeoJSON object, such as the minimum and maximum
|
|
60
|
+
* coordinates of the object's Geometries, Features, or Feature Collections.
|
|
61
|
+
*/
|
|
62
|
+
export class GeoBoundingBox {
|
|
63
|
+
//#region Properties
|
|
64
|
+
projection;
|
|
65
|
+
/**
|
|
66
|
+
* The most western longitude (in decimal degrees) of the coordinate range.
|
|
67
|
+
*
|
|
68
|
+
* @minimum -180.0
|
|
69
|
+
* @maximum 180.0
|
|
70
|
+
*/
|
|
71
|
+
#minLongitude;
|
|
72
|
+
/**
|
|
73
|
+
* The most southern latitude (in decimal degrees) of the coordinate range.
|
|
74
|
+
*
|
|
75
|
+
* @minimum -90.0
|
|
76
|
+
* @maximum 90.0
|
|
77
|
+
*/
|
|
78
|
+
#minLatitude;
|
|
79
|
+
/**
|
|
80
|
+
* Altitude of the most western longitude (in decimal degrees) of the coordinate range.
|
|
81
|
+
*/
|
|
82
|
+
#minAltitude;
|
|
83
|
+
/**
|
|
84
|
+
* The most eastern longitude (in decimal degrees) of the coordinate range.
|
|
85
|
+
*
|
|
86
|
+
* @minimum -180.0
|
|
87
|
+
* @maximum 180.0
|
|
88
|
+
*/
|
|
89
|
+
#maxLongitude;
|
|
90
|
+
/**
|
|
91
|
+
* The most northern latitude (in decimal degrees) of the coordinate range.
|
|
92
|
+
*
|
|
93
|
+
* @minimum -90.0
|
|
94
|
+
* @maximum 90.0
|
|
95
|
+
*/
|
|
96
|
+
#maxLatitude;
|
|
97
|
+
/**
|
|
98
|
+
* Altitude of the most eastern longitude (in decimal degrees) of the coordinate range.
|
|
99
|
+
*/
|
|
100
|
+
#maxAltitude;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region Accessors
|
|
103
|
+
get minLongitude() {
|
|
104
|
+
return this.#minLongitude;
|
|
105
|
+
}
|
|
106
|
+
set minLongitude(value) {
|
|
107
|
+
this.#minLongitude = wrapLongitude(value);
|
|
108
|
+
}
|
|
109
|
+
get minLatitude() {
|
|
110
|
+
return this.#minLatitude;
|
|
111
|
+
}
|
|
112
|
+
set minLatitude(value) {
|
|
113
|
+
this.#minLatitude = clampLatitude(value);
|
|
114
|
+
}
|
|
115
|
+
get maxLongitude() {
|
|
116
|
+
return this.#maxLongitude;
|
|
117
|
+
}
|
|
118
|
+
set maxLongitude(value) {
|
|
119
|
+
this.#maxLongitude = wrapLongitude(value);
|
|
120
|
+
}
|
|
121
|
+
get maxLatitude() {
|
|
122
|
+
return this.#maxLatitude;
|
|
123
|
+
}
|
|
124
|
+
set maxLatitude(value) {
|
|
125
|
+
this.#maxLatitude = clampLatitude(value);
|
|
126
|
+
}
|
|
127
|
+
get minAltitude() {
|
|
128
|
+
return this.#minAltitude;
|
|
129
|
+
}
|
|
130
|
+
set minAltitude(value) {
|
|
131
|
+
this.#minAltitude = value;
|
|
132
|
+
}
|
|
133
|
+
get maxAltitude() {
|
|
134
|
+
return this.#maxAltitude;
|
|
135
|
+
}
|
|
136
|
+
set maxAltitude(value) {
|
|
137
|
+
this.#maxAltitude = value;
|
|
138
|
+
}
|
|
139
|
+
get east() {
|
|
140
|
+
return this.#maxLongitude;
|
|
141
|
+
}
|
|
142
|
+
set east(value) {
|
|
143
|
+
this.#maxLongitude = wrapLongitude(value);
|
|
144
|
+
}
|
|
145
|
+
get north() {
|
|
146
|
+
return this.#maxLatitude;
|
|
147
|
+
}
|
|
148
|
+
set north(value) {
|
|
149
|
+
this.#maxLatitude = clampLatitude(value);
|
|
150
|
+
}
|
|
151
|
+
get south() {
|
|
152
|
+
return this.#minLatitude;
|
|
153
|
+
}
|
|
154
|
+
set south(value) {
|
|
155
|
+
this.#minLatitude = clampLatitude(value);
|
|
156
|
+
}
|
|
157
|
+
get west() {
|
|
158
|
+
return this.#minLongitude;
|
|
159
|
+
}
|
|
160
|
+
set west(value) {
|
|
161
|
+
this.#minLongitude = wrapLongitude(value);
|
|
162
|
+
}
|
|
163
|
+
get elevation() {
|
|
164
|
+
return this.#maxAltitude;
|
|
165
|
+
}
|
|
166
|
+
set elevation(value) {
|
|
167
|
+
this.#maxAltitude = value;
|
|
168
|
+
}
|
|
169
|
+
get depth() {
|
|
170
|
+
return this.#minAltitude;
|
|
171
|
+
}
|
|
172
|
+
set depth(value) {
|
|
173
|
+
this.#minAltitude = value;
|
|
174
|
+
}
|
|
175
|
+
[Symbol.iterator]() {
|
|
176
|
+
return this.toJSON()[Symbol.iterator]();
|
|
177
|
+
}
|
|
178
|
+
constructor(input, projection) {
|
|
179
|
+
let bbox;
|
|
180
|
+
if (input instanceof GeoBoundingBox) {
|
|
181
|
+
bbox = input.toJSON();
|
|
182
|
+
}
|
|
183
|
+
else if (isBBox(input)) {
|
|
184
|
+
bbox = input;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
bbox = [0, 0, 0, 0];
|
|
188
|
+
}
|
|
189
|
+
const [
|
|
190
|
+
// ---
|
|
191
|
+
minLongitude = 0, minLatitude = 0, maxLongitude = 0, maxLatitude = 0, minAltitude = 0, maxAltitude = 0,] = bbox;
|
|
192
|
+
this.#minLongitude = minLongitude;
|
|
193
|
+
this.#minLatitude = minLatitude;
|
|
194
|
+
this.#maxLongitude = maxLongitude;
|
|
195
|
+
this.#maxLatitude = maxLatitude;
|
|
196
|
+
this.#minAltitude = minAltitude;
|
|
197
|
+
this.#maxAltitude = maxAltitude;
|
|
198
|
+
this.projection = projection ?? CoordinateProjection.WGS84;
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region Predicates
|
|
202
|
+
is3D() {
|
|
203
|
+
return this.#minAltitude !== 0 || this.#maxAltitude !== 0;
|
|
204
|
+
}
|
|
205
|
+
is2D() {
|
|
206
|
+
return !this.is3D();
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region Conversion
|
|
210
|
+
/**
|
|
211
|
+
* Converts the 2D GeoBoundingBox to an array literal.
|
|
212
|
+
*/
|
|
213
|
+
toJSON2D() {
|
|
214
|
+
return [
|
|
215
|
+
// ---
|
|
216
|
+
this.#minLongitude,
|
|
217
|
+
this.#minLatitude,
|
|
218
|
+
this.#maxLongitude,
|
|
219
|
+
this.#maxLatitude,
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Converts the 3D GeoBoundingBox to an array literal.
|
|
224
|
+
*/
|
|
225
|
+
toJSON3D() {
|
|
226
|
+
return [
|
|
227
|
+
// ---
|
|
228
|
+
this.#minLongitude,
|
|
229
|
+
this.#minLatitude,
|
|
230
|
+
this.#minAltitude,
|
|
231
|
+
this.#maxLongitude,
|
|
232
|
+
this.#maxLatitude,
|
|
233
|
+
this.#maxAltitude,
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
toJSON() {
|
|
237
|
+
if (this.is3D())
|
|
238
|
+
return this.toJSON3D();
|
|
239
|
+
return this.toJSON2D();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Converts the GeoBoundingBox to a GeoJSON Polygon, omitting the altitude.
|
|
243
|
+
*/
|
|
244
|
+
to2DPolygon() {
|
|
245
|
+
const { minLatitude, maxLatitude, minLongitude, maxLongitude } = this;
|
|
246
|
+
const path = [
|
|
247
|
+
[
|
|
248
|
+
[minLongitude, minLatitude],
|
|
249
|
+
[maxLongitude, minLatitude],
|
|
250
|
+
[maxLongitude, maxLatitude],
|
|
251
|
+
[minLongitude, maxLatitude],
|
|
252
|
+
[minLongitude, minLatitude],
|
|
253
|
+
],
|
|
254
|
+
];
|
|
255
|
+
return { type: "Polygon", coordinates: path };
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Converts the GeoBoundingBox to a Well-Known-Text (WKT) string.
|
|
259
|
+
*
|
|
260
|
+
* This is useful when building Spatialite query parameters.
|
|
261
|
+
*/
|
|
262
|
+
to2DEWKT() {
|
|
263
|
+
const { minLatitude, maxLatitude, minLongitude, maxLongitude } = this;
|
|
264
|
+
return `SRID=${this.projection};POLYGON((${minLongitude} ${minLatitude}, ${maxLongitude} ${minLatitude}, ${maxLongitude} ${maxLatitude}, ${minLongitude} ${maxLatitude}, ${minLongitude} ${minLatitude}))`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=bbox.js.map
|
package/out/bbox.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../bbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAgGtD,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;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,KAAK,YAAY,cAAc,CAAA;AACvC,CAAC;AASD,yBAAyB;AAEzB;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAC1B,o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