@math.gl/geospatial 5.0.0 → 5.0.2
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/dist/coverage-simplification.d.ts +9 -0
- package/dist/coverage-simplification.d.ts.map +1 -0
- package/dist/coverage-simplification.js +167 -0
- package/dist/coverage-simplification.js.map +1 -0
- package/dist/line-network/build-line-network.d.ts +100 -0
- package/dist/line-network/build-line-network.d.ts.map +1 -0
- package/dist/line-network/build-line-network.js +766 -0
- package/dist/line-network/build-line-network.js.map +1 -0
- package/dist/line-network/line-network-routes.d.ts +53 -0
- package/dist/line-network/line-network-routes.d.ts.map +1 -0
- package/dist/line-network/line-network-routes.js +146 -0
- package/dist/line-network/line-network-routes.js.map +1 -0
- package/dist/line-network/line-network-weights.d.ts +11 -0
- package/dist/line-network/line-network-weights.d.ts.map +1 -0
- package/dist/line-network/line-network-weights.js +25 -0
- package/dist/line-network/line-network-weights.js.map +1 -0
- package/dist/line-network.cjs +850 -0
- package/dist/line-network.cjs.map +6 -0
- package/dist/line-network.d.ts +7 -0
- package/dist/line-network.d.ts.map +1 -0
- package/dist/line-network.js +7 -0
- package/dist/line-network.js.map +1 -0
- package/dist/line-simplification.d.ts +7 -0
- package/dist/line-simplification.d.ts.map +1 -1
- package/dist/line-simplification.js +4 -13
- package/dist/line-simplification.js.map +1 -1
- package/dist/linear-referencing.d.ts +3 -1
- package/dist/linear-referencing.d.ts.map +1 -1
- package/dist/linear-referencing.js +21 -33
- package/dist/linear-referencing.js.map +1 -1
- package/dist/measure-referencing.d.ts +16 -0
- package/dist/measure-referencing.d.ts.map +1 -0
- package/dist/measure-referencing.js +143 -0
- package/dist/measure-referencing.js.map +1 -0
- package/dist/polygon-simplification.d.ts +6 -0
- package/dist/polygon-simplification.d.ts.map +1 -0
- package/dist/polygon-simplification.js +111 -0
- package/dist/polygon-simplification.js.map +1 -0
- package/dist/route-editing.d.ts +10 -0
- package/dist/route-editing.d.ts.map +1 -0
- package/dist/route-editing.js +58 -0
- package/dist/route-editing.js.map +1 -0
- package/dist/spatial-box-clipping.d.ts +9 -0
- package/dist/spatial-box-clipping.d.ts.map +1 -0
- package/dist/spatial-box-clipping.js +123 -0
- package/dist/spatial-box-clipping.js.map +1 -0
- package/dist/spatial-dwithin.d.ts +19 -0
- package/dist/spatial-dwithin.d.ts.map +1 -0
- package/dist/spatial-dwithin.js +107 -0
- package/dist/spatial-dwithin.js.map +1 -0
- package/dist/spatial-hulls.d.ts +6 -0
- package/dist/spatial-hulls.d.ts.map +1 -0
- package/dist/spatial-hulls.js +176 -0
- package/dist/spatial-hulls.js.map +1 -0
- package/dist/spatial-line-intersection-result.d.ts +4 -0
- package/dist/spatial-line-intersection-result.d.ts.map +1 -0
- package/dist/spatial-line-intersection-result.js +79 -0
- package/dist/spatial-line-intersection-result.js.map +1 -0
- package/dist/spatial-line-polygon-intersection.d.ts +4 -0
- package/dist/spatial-line-polygon-intersection.d.ts.map +1 -0
- package/dist/spatial-line-polygon-intersection.js +130 -0
- package/dist/spatial-line-polygon-intersection.js.map +1 -0
- package/dist/spatial-planar-intersects.d.ts +1 -0
- package/dist/spatial-planar-intersects.d.ts.map +1 -1
- package/dist/spatial-planar-intersects.js +5 -37
- package/dist/spatial-planar-intersects.js.map +1 -1
- package/dist/spatial-planar.d.ts +9 -0
- package/dist/spatial-planar.d.ts.map +1 -1
- package/dist/spatial-planar.js +13 -1
- package/dist/spatial-planar.js.map +1 -1
- package/dist/spatial-polygon-overlay.d.ts +5 -0
- package/dist/spatial-polygon-overlay.d.ts.map +1 -0
- package/dist/spatial-polygon-overlay.js +23 -0
- package/dist/spatial-polygon-overlay.js.map +1 -0
- package/dist/spatial-sql.d.ts +15 -2
- package/dist/spatial-sql.d.ts.map +1 -1
- package/dist/spatial-sql.js +65 -13
- package/dist/spatial-sql.js.map +1 -1
- package/dist/spatial-subdivision.d.ts +9 -0
- package/dist/spatial-subdivision.d.ts.map +1 -0
- package/dist/spatial-subdivision.js +61 -0
- package/dist/spatial-subdivision.js.map +1 -0
- package/dist/spatial-touches.d.ts +11 -0
- package/dist/spatial-touches.d.ts.map +1 -0
- package/dist/spatial-touches.js +178 -0
- package/dist/spatial-touches.js.map +1 -0
- package/dist/st-coverage-functions.d.ts +11 -0
- package/dist/st-coverage-functions.d.ts.map +1 -0
- package/dist/st-coverage-functions.js +57 -0
- package/dist/st-coverage-functions.js.map +1 -0
- package/dist/st-functions.cjs +3279 -554
- package/dist/st-functions.cjs.map +3 -3
- package/dist/st-functions.d.ts +100 -2
- package/dist/st-functions.d.ts.map +1 -1
- package/dist/st-functions.js +239 -22
- package/dist/st-functions.js.map +1 -1
- package/dist/st-geodesic-functions.d.ts +41 -0
- package/dist/st-geodesic-functions.d.ts.map +1 -0
- package/dist/st-geodesic-functions.js +238 -0
- package/dist/st-geodesic-functions.js.map +1 -0
- package/dist/st-hull-functions.cjs +386 -0
- package/dist/st-hull-functions.cjs.map +6 -0
- package/dist/st-hull-functions.d.ts +17 -0
- package/dist/st-hull-functions.d.ts.map +1 -0
- package/dist/st-hull-functions.js +14 -0
- package/dist/st-hull-functions.js.map +1 -0
- package/dist/st-overlay-functions.cjs +668 -0
- package/dist/st-overlay-functions.cjs.map +6 -0
- package/dist/st-overlay-functions.d.ts +46 -0
- package/dist/st-overlay-functions.d.ts.map +1 -0
- package/dist/st-overlay-functions.js +248 -0
- package/dist/st-overlay-functions.js.map +1 -0
- package/dist/st-viewport-functions.cjs +481 -0
- package/dist/st-viewport-functions.cjs.map +6 -0
- package/dist/st-viewport-functions.d.ts +13 -0
- package/dist/st-viewport-functions.d.ts.map +1 -0
- package/dist/st-viewport-functions.js +81 -0
- package/dist/st-viewport-functions.js.map +1 -0
- package/dist/terrain/index.cjs +93 -20
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +1 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +1 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/regional-watersheds.d.ts +44 -0
- package/dist/terrain/regional-watersheds.d.ts.map +1 -0
- package/dist/terrain/regional-watersheds.js +108 -0
- package/dist/terrain/regional-watersheds.js.map +1 -0
- package/dist/terrain/tile-cutout-update.d.ts.map +1 -1
- package/dist/terrain/tile-cutout-update.js +28 -22
- package/dist/terrain/tile-cutout-update.js.map +1 -1
- package/dist/turf-functions.cjs +16 -9
- package/dist/turf-functions.cjs.map +1 -1
- package/package.json +27 -6
- package/src/coverage-simplification.ts +215 -0
- package/src/line-network/build-line-network.ts +990 -0
- package/src/line-network/line-network-routes.ts +213 -0
- package/src/line-network/line-network-weights.ts +40 -0
- package/src/line-network.ts +29 -0
- package/src/line-simplification.ts +4 -16
- package/src/linear-referencing.ts +27 -40
- package/src/measure-referencing.ts +165 -0
- package/src/polygon-simplification.ts +146 -0
- package/src/route-editing.ts +107 -0
- package/src/spatial-box-clipping.ts +140 -0
- package/src/spatial-dwithin.ts +135 -0
- package/src/spatial-hulls.ts +203 -0
- package/src/spatial-line-intersection-result.ts +93 -0
- package/src/spatial-line-polygon-intersection.ts +152 -0
- package/src/spatial-planar-intersects.ts +10 -51
- package/src/spatial-planar.ts +20 -1
- package/src/spatial-polygon-overlay.ts +30 -0
- package/src/spatial-sql.ts +97 -13
- package/src/spatial-subdivision.ts +75 -0
- package/src/spatial-touches.ts +204 -0
- package/src/st-coverage-functions.ts +88 -0
- package/src/st-functions.ts +345 -26
- package/src/st-geodesic-functions.ts +313 -0
- package/src/st-hull-functions.ts +25 -0
- package/src/st-overlay-functions.ts +313 -0
- package/src/st-viewport-functions.ts +98 -0
- package/src/terrain/index.ts +7 -0
- package/src/terrain/regional-watersheds.ts +153 -0
- package/src/terrain/tile-cutout-update.ts +32 -26
package/dist/st-functions.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -8,21 +10,32 @@ var __export = (target, all) => {
|
|
|
8
10
|
};
|
|
9
11
|
var __copyProps = (to, from, except, desc) => {
|
|
10
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let
|
|
12
|
-
if (!__hasOwnProp.call(to,
|
|
13
|
-
__defProp(to,
|
|
13
|
+
for (let key2 of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
15
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// dist/st-functions.js
|
|
20
30
|
var st_functions_exports = {};
|
|
21
31
|
__export(st_functions_exports, {
|
|
32
|
+
GEODESIC_SPATIAL_FUNCTIONS: () => GEODESIC_SPATIAL_FUNCTIONS,
|
|
22
33
|
POSTGIS_SPATIAL_FUNCTIONS: () => POSTGIS_SPATIAL_FUNCTIONS,
|
|
34
|
+
ST_ADDMEASURE: () => ST_ADDMEASURE,
|
|
23
35
|
ST_AREA: () => ST_AREA,
|
|
24
36
|
ST_AZIMUTH: () => ST_AZIMUTH,
|
|
25
37
|
ST_CENTROID: () => ST_CENTROID,
|
|
38
|
+
ST_CLOSESTPOINT: () => ST_CLOSESTPOINT,
|
|
26
39
|
ST_COLLECT: () => ST_COLLECT,
|
|
27
40
|
ST_CONTAINS: () => ST_CONTAINS,
|
|
28
41
|
ST_COVEREDBY: () => ST_COVEREDBY,
|
|
@@ -33,14 +46,23 @@ __export(st_functions_exports, {
|
|
|
33
46
|
ST_ENVELOPE: () => ST_ENVELOPE,
|
|
34
47
|
ST_EXTENT: () => ST_EXTENT,
|
|
35
48
|
ST_FORCE2D: () => ST_FORCE2D,
|
|
49
|
+
ST_GEODESICDISTANCE: () => ST_GEODESICDISTANCE,
|
|
50
|
+
ST_GEODESICDWITHIN: () => ST_GEODESICDWITHIN,
|
|
51
|
+
ST_GEODESICLENGTH: () => ST_GEODESICLENGTH,
|
|
52
|
+
ST_GEODESICSEGMENTIZE: () => ST_GEODESICSEGMENTIZE,
|
|
36
53
|
ST_GEOMETRYN: () => ST_GEOMETRYN,
|
|
37
54
|
ST_GEOMETRYTYPE: () => ST_GEOMETRYTYPE,
|
|
38
55
|
ST_INTERSECTS: () => ST_INTERSECTS,
|
|
39
56
|
ST_ISEMPTY: () => ST_ISEMPTY,
|
|
57
|
+
ST_ISVALID: () => ST_ISVALID,
|
|
58
|
+
ST_ISVALIDREASON: () => ST_ISVALIDREASON,
|
|
40
59
|
ST_LENGTH: () => ST_LENGTH,
|
|
41
60
|
ST_LINEINTERPOLATEPOINT: () => ST_LINEINTERPOLATEPOINT,
|
|
42
61
|
ST_LINELOCATEPOINT: () => ST_LINELOCATEPOINT,
|
|
62
|
+
ST_LINEMERGE: () => ST_LINEMERGE,
|
|
43
63
|
ST_LINESUBSTRING: () => ST_LINESUBSTRING,
|
|
64
|
+
ST_LOCATEALONG: () => ST_LOCATEALONG,
|
|
65
|
+
ST_LOCATEBETWEEN: () => ST_LOCATEBETWEEN,
|
|
44
66
|
ST_M: () => ST_M,
|
|
45
67
|
ST_MAKEENVELOPE: () => ST_MAKEENVELOPE,
|
|
46
68
|
ST_MAKELINE: () => ST_MAKELINE,
|
|
@@ -50,25 +72,40 @@ __export(st_functions_exports, {
|
|
|
50
72
|
ST_POINTN: () => ST_POINTN,
|
|
51
73
|
ST_POINTONSURFACE: () => ST_POINTONSURFACE,
|
|
52
74
|
ST_REMOVEREPEATEDPOINTS: () => ST_REMOVEREPEATEDPOINTS,
|
|
75
|
+
ST_SEGMENTIZE: () => ST_SEGMENTIZE,
|
|
53
76
|
ST_SETSRID: () => ST_SETSRID,
|
|
77
|
+
ST_SHORTESTLINE: () => ST_SHORTESTLINE,
|
|
54
78
|
ST_SIMPLIFY: () => ST_SIMPLIFY,
|
|
79
|
+
ST_SIMPLIFYPRESERVETOPOLOGY: () => ST_SIMPLIFYPRESERVETOPOLOGY,
|
|
55
80
|
ST_SRID: () => ST_SRID,
|
|
56
81
|
ST_STARTPOINT: () => ST_STARTPOINT,
|
|
57
82
|
ST_TILEENVELOPE: () => ST_TILEENVELOPE,
|
|
83
|
+
ST_TOUCHES: () => ST_TOUCHES,
|
|
58
84
|
ST_TRANSFORM: () => ST_TRANSFORM,
|
|
59
85
|
ST_WITHIN: () => ST_WITHIN,
|
|
60
86
|
ST_X: () => ST_X,
|
|
61
87
|
ST_Y: () => ST_Y,
|
|
62
|
-
ST_Z: () => ST_Z
|
|
88
|
+
ST_Z: () => ST_Z,
|
|
89
|
+
createSTCoverageSimplify: () => createSTCoverageSimplify,
|
|
90
|
+
createSTTransform: () => createSTTransform
|
|
63
91
|
});
|
|
64
92
|
module.exports = __toCommonJS(st_functions_exports);
|
|
65
|
-
var
|
|
66
|
-
var
|
|
93
|
+
var import_apache_arrow4 = require("apache-arrow");
|
|
94
|
+
var import_arrow7 = require("@math.gl/core/arrow");
|
|
95
|
+
var import_polygon5 = require("@math.gl/geometry/polygon");
|
|
67
96
|
|
|
68
97
|
// dist/spatial-planar-intersects.js
|
|
69
|
-
var
|
|
98
|
+
var import_polygon = require("@math.gl/geometry/polygon");
|
|
99
|
+
var import_polygon2 = require("@math.gl/geometry/polygon");
|
|
70
100
|
|
|
71
101
|
// dist/spatial-planar.js
|
|
102
|
+
function distanceToPlanarSegment(p, a, b) {
|
|
103
|
+
const dx = b[0] - a[0], dy = b[1] - a[1];
|
|
104
|
+
const length = Math.hypot(dx, dy);
|
|
105
|
+
const px = p[0] - a[0], py = p[1] - a[1];
|
|
106
|
+
const t = length ? Math.max(0, Math.min(1, (px * (dx / length) + py * (dy / length)) / length)) : 0;
|
|
107
|
+
return Math.hypot(px - t * dx, py - t * dy);
|
|
108
|
+
}
|
|
72
109
|
function visitSegments(path, closed, visit) {
|
|
73
110
|
for (let i = 1; i < path.length; i++)
|
|
74
111
|
visit(path[i - 1], path[i]);
|
|
@@ -130,13 +167,15 @@ function polygonMoments(rings, origin) {
|
|
|
130
167
|
return total;
|
|
131
168
|
}
|
|
132
169
|
function planarArea(geometry) {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
170
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : [];
|
|
171
|
+
return polygons3.reduce((total, rings) => {
|
|
135
172
|
var _a;
|
|
136
173
|
return total + polygonMoments(rings, ((_a = rings[0]) == null ? void 0 : _a[0]) ?? [0, 0]).weight;
|
|
137
174
|
}, 0);
|
|
138
175
|
}
|
|
139
176
|
function planarLength(geometry) {
|
|
177
|
+
if (geometry.type === "GeometryCollection")
|
|
178
|
+
return geometry.geometries.reduce((sum, part) => sum + planarLength(part), 0);
|
|
140
179
|
if (geometry.type !== "LineString" && geometry.type !== "MultiLineString")
|
|
141
180
|
return 0;
|
|
142
181
|
let length = 0;
|
|
@@ -148,7 +187,7 @@ function planarLength(geometry) {
|
|
|
148
187
|
return length;
|
|
149
188
|
}
|
|
150
189
|
function planarCentroid(geometry) {
|
|
151
|
-
const
|
|
190
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : [];
|
|
152
191
|
const points2 = { x: 0, y: 0, weight: 0 };
|
|
153
192
|
const lines = { x: 0, y: 0, weight: 0 };
|
|
154
193
|
const areas = { x: 0, y: 0, weight: 0 };
|
|
@@ -160,7 +199,7 @@ function planarCentroid(geometry) {
|
|
|
160
199
|
const ox = origin[0];
|
|
161
200
|
const oy = origin[1];
|
|
162
201
|
if (geometry.type !== "MultiPoint") {
|
|
163
|
-
visitSegments(path,
|
|
202
|
+
visitSegments(path, polygons3.length > 0, (a, b) => {
|
|
164
203
|
const weight2 = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
165
204
|
lines.x += (a[0] - ox + (b[0] - ox)) / 2 * weight2;
|
|
166
205
|
lines.y += (a[1] - oy + (b[1] - oy)) / 2 * weight2;
|
|
@@ -175,7 +214,7 @@ function planarCentroid(geometry) {
|
|
|
175
214
|
});
|
|
176
215
|
if (!origin)
|
|
177
216
|
return { type: "Point", coordinates: [] };
|
|
178
|
-
for (const polygon of
|
|
217
|
+
for (const polygon of polygons3) {
|
|
179
218
|
const part = polygonMoments(polygon, origin);
|
|
180
219
|
areas.x += part.x;
|
|
181
220
|
areas.y += part.y;
|
|
@@ -203,13 +242,13 @@ function planarBounds(geometry) {
|
|
|
203
242
|
return minX <= maxX ? [minX, minY, maxX, maxY] : null;
|
|
204
243
|
}
|
|
205
244
|
function planarEnvelope(geometry) {
|
|
206
|
-
const
|
|
207
|
-
if (!
|
|
245
|
+
const bounds2 = planarBounds(geometry);
|
|
246
|
+
if (!bounds2)
|
|
208
247
|
return geometry;
|
|
209
|
-
return envelopeFromBounds(
|
|
248
|
+
return envelopeFromBounds(bounds2);
|
|
210
249
|
}
|
|
211
|
-
function envelopeFromBounds(
|
|
212
|
-
const [x0, y0, x1, y1] =
|
|
250
|
+
function envelopeFromBounds(bounds2) {
|
|
251
|
+
const [x0, y0, x1, y1] = bounds2;
|
|
213
252
|
if (x0 === x1 && y0 === y1)
|
|
214
253
|
return { type: "Point", coordinates: [x0, y0] };
|
|
215
254
|
if (x0 === x1 || y0 === y1) {
|
|
@@ -235,10 +274,10 @@ function envelopeFromBounds(bounds) {
|
|
|
235
274
|
};
|
|
236
275
|
}
|
|
237
276
|
function planarPolygonPointOnSurface(geometry) {
|
|
238
|
-
const
|
|
277
|
+
const polygons3 = geometry.type === "MultiPolygon" ? geometry.coordinates : geometry.type === "Polygon" ? [geometry.coordinates] : [];
|
|
239
278
|
let coordinates = [];
|
|
240
279
|
let widest = -1;
|
|
241
|
-
for (const rings of
|
|
280
|
+
for (const rings of polygons3) {
|
|
242
281
|
const shell = rings[0];
|
|
243
282
|
if (!(shell == null ? void 0 : shell.length))
|
|
244
283
|
continue;
|
|
@@ -306,17 +345,6 @@ function* primitives(geometry) {
|
|
|
306
345
|
yield geometry;
|
|
307
346
|
}
|
|
308
347
|
}
|
|
309
|
-
function side(a, b, c) {
|
|
310
|
-
return Math.sign((0, import_robust_predicates.orient2d)(a[0], a[1], b[0], b[1], c[0], c[1]));
|
|
311
|
-
}
|
|
312
|
-
function inBounds(p, a, b) {
|
|
313
|
-
return p[0] >= Math.min(a[0], b[0]) && p[0] <= Math.max(a[0], b[0]) && p[1] >= Math.min(a[1], b[1]) && p[1] <= Math.max(a[1], b[1]);
|
|
314
|
-
}
|
|
315
|
-
function segmentsMeet(a, b, c, d) {
|
|
316
|
-
const cSide = side(a, b, c), dSide = side(a, b, d);
|
|
317
|
-
const aSide = side(c, d, a), bSide = side(c, d, b);
|
|
318
|
-
return cSide * dSide < 0 && aSide * bSide < 0 || !cSide && inBounds(c, a, b) || !dSide && inBounds(d, a, b) || !aSide && inBounds(a, c, d) || !bSide && inBounds(b, c, d);
|
|
319
|
-
}
|
|
320
348
|
function anyEdge(path, closed, match) {
|
|
321
349
|
for (let i = closed ? 0 : 1; i < path.length; i++) {
|
|
322
350
|
if (match(path[i ? i - 1 : path.length - 1], path[i]))
|
|
@@ -330,20 +358,8 @@ function meetsPoint(point2, geometry) {
|
|
|
330
358
|
if (geometry.type === "Point")
|
|
331
359
|
return point2[0] === geometry.coordinates[0] && point2[1] === geometry.coordinates[1];
|
|
332
360
|
if (geometry.type === "LineString")
|
|
333
|
-
return anyEdge(geometry.coordinates, false, (a, b) =>
|
|
334
|
-
|
|
335
|
-
for (const ring of geometry.coordinates) {
|
|
336
|
-
if (anyEdge(ring, true, (a, b) => {
|
|
337
|
-
const orientation = side(a, b, point2);
|
|
338
|
-
if (!orientation && inBounds(point2, a, b))
|
|
339
|
-
return true;
|
|
340
|
-
if (a[1] > point2[1] !== b[1] > point2[1] && orientation < 0 === b[1] > a[1])
|
|
341
|
-
inside = !inside;
|
|
342
|
-
return false;
|
|
343
|
-
}))
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
return inside;
|
|
361
|
+
return anyEdge(geometry.coordinates, false, (a, b) => (0, import_polygon.pointOnSegment)(point2, a, b));
|
|
362
|
+
return (0, import_polygon.locatePointInPolygon)(point2, geometry.coordinates) >= 0;
|
|
347
363
|
}
|
|
348
364
|
function primitivesMeet(a, b) {
|
|
349
365
|
if (a.type === "Point")
|
|
@@ -355,7 +371,7 @@ function primitivesMeet(a, b) {
|
|
|
355
371
|
for (const path of pathsA) {
|
|
356
372
|
if (b.type === "Polygon" && path[0] && meetsPoint(path[0], b))
|
|
357
373
|
return true;
|
|
358
|
-
if (anyEdge(path, a.type === "Polygon", (p, q) => pathsB.some((other) => anyEdge(other, b.type === "Polygon", (r, s) => segmentsMeet(p, q, r, s)))))
|
|
374
|
+
if (anyEdge(path, a.type === "Polygon", (p, q) => pathsB.some((other) => anyEdge(other, b.type === "Polygon", (r, s) => (0, import_polygon.segmentsMeet)(p, q, r, s)))))
|
|
359
375
|
return true;
|
|
360
376
|
}
|
|
361
377
|
return a.type === "Polygon" && pathsB.some((path) => Boolean(path[0] && meetsPoint(path[0], a)));
|
|
@@ -372,319 +388,350 @@ function planarIntersects(a, b) {
|
|
|
372
388
|
return false;
|
|
373
389
|
}
|
|
374
390
|
|
|
375
|
-
// dist/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
391
|
+
// dist/spatial-touches.js
|
|
392
|
+
var import_polygon_clipping = __toESM(require("polygon-clipping"), 1);
|
|
393
|
+
|
|
394
|
+
// dist/spatial-polygon-overlay.js
|
|
395
|
+
function polygonSet(geometry) {
|
|
396
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : void 0;
|
|
397
|
+
if (!polygons3)
|
|
398
|
+
throw new Error("Polygon overlay requires Polygon or MultiPolygon input");
|
|
399
|
+
return polygons3.filter((polygon) => {
|
|
400
|
+
var _a;
|
|
401
|
+
return (_a = polygon[0]) == null ? void 0 : _a.length;
|
|
402
|
+
}).map((polygon) => polygon.filter((ring) => ring.length).map((ring) => ring.map(([x, y]) => {
|
|
403
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
404
|
+
throw new Error("Polygon overlay requires finite coordinates");
|
|
405
|
+
return [x, y];
|
|
406
|
+
})));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// dist/spatial-touches.js
|
|
410
|
+
function isPointLike(geometry) {
|
|
411
|
+
return geometry.type === "Point" || geometry.type === "MultiPoint";
|
|
412
|
+
}
|
|
413
|
+
function isLinear(geometry) {
|
|
414
|
+
return geometry.type === "LineString" || geometry.type === "MultiLineString";
|
|
415
|
+
}
|
|
416
|
+
function isAreal(geometry) {
|
|
417
|
+
return geometry.type === "Polygon" || geometry.type === "MultiPolygon";
|
|
418
|
+
}
|
|
419
|
+
function paths(geometry) {
|
|
420
|
+
return geometry.type === "LineString" ? [geometry.coordinates] : geometry.coordinates;
|
|
421
|
+
}
|
|
422
|
+
function polygons(geometry) {
|
|
423
|
+
return geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
424
|
+
}
|
|
425
|
+
function samePoint(a, b) {
|
|
426
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
427
|
+
}
|
|
428
|
+
function pointKey(point2) {
|
|
429
|
+
return `${point2[0]}/${point2[1]}`;
|
|
430
|
+
}
|
|
431
|
+
function* edges(components, closed = false) {
|
|
432
|
+
for (const path of components) {
|
|
433
|
+
for (let i = closed ? 0 : 1; i < path.length; i++) {
|
|
434
|
+
const a = path[i ? i - 1 : path.length - 1];
|
|
435
|
+
const b = path[i];
|
|
436
|
+
if (!samePoint(a, b))
|
|
437
|
+
yield [a, b];
|
|
438
|
+
}
|
|
381
439
|
}
|
|
382
|
-
return distances;
|
|
383
440
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
|
|
441
|
+
function lineBoundary(components) {
|
|
442
|
+
const boundary = /* @__PURE__ */ new Map();
|
|
443
|
+
for (const component of components) {
|
|
444
|
+
if (!component.length)
|
|
445
|
+
continue;
|
|
446
|
+
for (const point2 of [component[0], component[component.length - 1]]) {
|
|
447
|
+
const key2 = pointKey(point2);
|
|
448
|
+
if (!boundary.delete(key2))
|
|
449
|
+
boundary.set(key2, point2);
|
|
392
450
|
}
|
|
393
451
|
}
|
|
394
|
-
return
|
|
452
|
+
return boundary;
|
|
395
453
|
}
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return null;
|
|
401
|
-
const path = line.coordinates;
|
|
402
|
-
const distances = cumulativeDistances(path);
|
|
403
|
-
const total = distances[distances.length - 1];
|
|
404
|
-
const from = start * total, to = end * total;
|
|
405
|
-
const first = coordinateAt(path, distances, from);
|
|
406
|
-
if (from === to)
|
|
407
|
-
return { type: "Point", coordinates: first };
|
|
408
|
-
const coordinates = [first];
|
|
409
|
-
for (let i = 1; i < path.length - 1; i++) {
|
|
410
|
-
if (distances[i] > from && distances[i] < to && distances[i] !== distances[i - 1])
|
|
411
|
-
coordinates.push(path[i]);
|
|
454
|
+
function hasBoundaryCrossing(boundary, a, b) {
|
|
455
|
+
for (const point2 of boundary.values()) {
|
|
456
|
+
if ((0, import_polygon2.pointOnSegment)(point2, ...a) && (0, import_polygon2.pointOnSegment)(point2, ...b))
|
|
457
|
+
return true;
|
|
412
458
|
}
|
|
413
|
-
|
|
414
|
-
return { type: "LineString", coordinates };
|
|
459
|
+
return false;
|
|
415
460
|
}
|
|
416
|
-
function
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
461
|
+
function lineInteriorsMeet(a, b) {
|
|
462
|
+
const aPaths = paths(a);
|
|
463
|
+
const bPaths = paths(b);
|
|
464
|
+
const aBoundary = lineBoundary(aPaths);
|
|
465
|
+
const bBoundary = lineBoundary(bPaths);
|
|
466
|
+
const bEdges = [...edges(bPaths)];
|
|
467
|
+
for (const left of edges(aPaths)) {
|
|
468
|
+
for (const right of bEdges) {
|
|
469
|
+
if (!(0, import_polygon2.segmentsMeet)(...left, ...right))
|
|
470
|
+
continue;
|
|
471
|
+
const contacts = (0, import_polygon2.endpointContacts)(left, right);
|
|
472
|
+
if (contacts.length > 1)
|
|
473
|
+
return true;
|
|
474
|
+
if (contacts.length) {
|
|
475
|
+
const key2 = pointKey(contacts[0]);
|
|
476
|
+
if (!aBoundary.has(key2) && !bBoundary.has(key2))
|
|
477
|
+
return true;
|
|
478
|
+
} else if (!hasBoundaryCrossing(aBoundary, left, right) && !hasBoundaryCrossing(bBoundary, left, right)) {
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
433
481
|
}
|
|
434
|
-
total += length;
|
|
435
482
|
}
|
|
436
|
-
return
|
|
483
|
+
return false;
|
|
437
484
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
[
|
|
443
|
-
[
|
|
444
|
-
]);
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
[
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
[
|
|
451
|
-
]
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
return ogcCode ? `OGC:${ogcCode}` : identifier;
|
|
463
|
-
}
|
|
464
|
-
return formatIdentifier(authority, code);
|
|
485
|
+
function insideArea(point2, areas) {
|
|
486
|
+
return areas.some((rings) => (0, import_polygon2.locatePointInPolygon)(point2, rings) === 1);
|
|
487
|
+
}
|
|
488
|
+
function parameter(point2, [a, b]) {
|
|
489
|
+
const dx = b[0] - a[0];
|
|
490
|
+
const dy = b[1] - a[1];
|
|
491
|
+
return Math.abs(dx) >= Math.abs(dy) ? (point2[0] - a[0]) / dx : (point2[1] - a[1]) / dy;
|
|
492
|
+
}
|
|
493
|
+
function segmentEntersArea(edge, boundaries, areas) {
|
|
494
|
+
const [a, b] = edge;
|
|
495
|
+
if (insideArea(a, areas) || insideArea(b, areas))
|
|
496
|
+
return true;
|
|
497
|
+
const cuts = /* @__PURE__ */ new Set([0, 1]);
|
|
498
|
+
const coincident = [];
|
|
499
|
+
for (const boundary of boundaries) {
|
|
500
|
+
if (!(0, import_polygon2.segmentsMeet)(...edge, ...boundary))
|
|
501
|
+
continue;
|
|
502
|
+
const contacts = (0, import_polygon2.endpointContacts)(edge, boundary).map((point2) => parameter(point2, edge));
|
|
503
|
+
if (!contacts.length)
|
|
504
|
+
return true;
|
|
505
|
+
for (const contact of contacts)
|
|
506
|
+
cuts.add(contact);
|
|
507
|
+
if (contacts.length === 2)
|
|
508
|
+
coincident.push([Math.min(...contacts), Math.max(...contacts)]);
|
|
465
509
|
}
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
const [
|
|
469
|
-
|
|
510
|
+
const sorted = [...cuts].sort((left, right) => left - right);
|
|
511
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
512
|
+
const from = sorted[i - 1];
|
|
513
|
+
const to = sorted[i];
|
|
514
|
+
if (coincident.some(([start, end]) => start <= from && to <= end))
|
|
515
|
+
continue;
|
|
516
|
+
const t = (from + to) / 2;
|
|
517
|
+
if (insideArea([(1 - t) * a[0] + t * b[0], (1 - t) * a[1] + t * b[1]], areas))
|
|
518
|
+
return true;
|
|
470
519
|
}
|
|
471
|
-
return
|
|
520
|
+
return false;
|
|
472
521
|
}
|
|
473
|
-
function
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
522
|
+
function lineEntersArea(line, area) {
|
|
523
|
+
const areas = polygons(area);
|
|
524
|
+
const boundaries = [...edges(areas.flat(), true)];
|
|
525
|
+
for (const edge of edges(paths(line))) {
|
|
526
|
+
if (segmentEntersArea(edge, boundaries, areas))
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
return false;
|
|
478
530
|
}
|
|
479
|
-
function
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
531
|
+
function pointsMeetInterior(points2, other) {
|
|
532
|
+
const positions = points2.type === "Point" ? [points2.coordinates] : points2.coordinates;
|
|
533
|
+
if (isAreal(other)) {
|
|
534
|
+
const areas = polygons(other);
|
|
535
|
+
return positions.some((point2) => Number.isFinite(point2[0]) && Number.isFinite(point2[1]) && insideArea(point2, areas));
|
|
536
|
+
}
|
|
537
|
+
const linePaths = paths(other);
|
|
538
|
+
const boundary = lineBoundary(linePaths);
|
|
539
|
+
const segments = [...edges(linePaths)];
|
|
540
|
+
return positions.some((point2) => !boundary.has(pointKey(point2)) && segments.some((edge) => (0, import_polygon2.pointOnSegment)(point2, ...edge)));
|
|
541
|
+
}
|
|
542
|
+
function planarTouches(a, b) {
|
|
543
|
+
if (!isPointLike(a) && !isLinear(a) && !isAreal(a) || !isPointLike(b) && !isLinear(b) && !isAreal(b))
|
|
544
|
+
throw new Error("ST_Touches requires point, line or polygon geometry");
|
|
545
|
+
if (isPointLike(a) && isPointLike(b))
|
|
546
|
+
return false;
|
|
547
|
+
if (!planarIntersects(a, b))
|
|
548
|
+
return false;
|
|
549
|
+
if (isPointLike(a) && !isPointLike(b))
|
|
550
|
+
return !pointsMeetInterior(a, b);
|
|
551
|
+
if (isPointLike(b) && !isPointLike(a))
|
|
552
|
+
return !pointsMeetInterior(b, a);
|
|
553
|
+
if (isLinear(a) && isLinear(b))
|
|
554
|
+
return !lineInteriorsMeet(a, b);
|
|
555
|
+
if (isLinear(a) && isAreal(b))
|
|
556
|
+
return !lineEntersArea(a, b);
|
|
557
|
+
if (isAreal(a) && isLinear(b))
|
|
558
|
+
return !lineEntersArea(b, a);
|
|
559
|
+
return !import_polygon_clipping.default.intersection(polygonSet(a), polygonSet(b)).length;
|
|
484
560
|
}
|
|
485
561
|
|
|
486
|
-
// dist/
|
|
487
|
-
var
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
562
|
+
// dist/spatial-dwithin.js
|
|
563
|
+
var import_spatial_index = require("@math.gl/geometry/spatial-index");
|
|
564
|
+
var directPairLimit = 1024;
|
|
565
|
+
function pointWithinPolygonDistance(point2, polygon, radius) {
|
|
566
|
+
const [x, y] = point2.coordinates;
|
|
567
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
568
|
+
return false;
|
|
569
|
+
const bounds2 = planarBounds(polygon);
|
|
570
|
+
if (!bounds2 || !boxesWithin([x, y, x, y], bounds2, radius))
|
|
571
|
+
return false;
|
|
572
|
+
if (planarIntersects(point2, polygon))
|
|
573
|
+
return true;
|
|
574
|
+
if (radius === 0)
|
|
575
|
+
return false;
|
|
576
|
+
const areas = polygon.type === "Polygon" ? [polygon.coordinates] : polygon.coordinates;
|
|
577
|
+
for (const area of areas) {
|
|
578
|
+
for (const ring of area) {
|
|
579
|
+
for (let i = 0; i < ring.length; i++) {
|
|
580
|
+
const a = ring[i === 0 ? ring.length - 1 : i - 1];
|
|
581
|
+
const b = ring[i];
|
|
582
|
+
if (distanceToPlanarSegment(point2.coordinates, a, b) <= radius)
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
502
586
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
function lineSegments(geometry) {
|
|
590
|
+
const paths3 = geometry.type === "LineString" ? [geometry.coordinates] : geometry.coordinates;
|
|
591
|
+
const segments = [];
|
|
592
|
+
for (const path of paths3) {
|
|
593
|
+
if (path.some((point2) => !Number.isFinite(point2[0]) || !Number.isFinite(point2[1])))
|
|
594
|
+
throw new Error("ST_DWithin requires finite line coordinates");
|
|
595
|
+
if (!path.length)
|
|
596
|
+
continue;
|
|
597
|
+
for (let i = 0; i < Math.max(1, path.length - 1); i++) {
|
|
598
|
+
const a = path[i];
|
|
599
|
+
const b = path[i + 1] ?? a;
|
|
600
|
+
segments.push({
|
|
601
|
+
a,
|
|
602
|
+
b,
|
|
603
|
+
bounds: [
|
|
604
|
+
Math.min(a[0], b[0]),
|
|
605
|
+
Math.min(a[1], b[1]),
|
|
606
|
+
Math.max(a[0], b[0]),
|
|
607
|
+
Math.max(a[1], b[1])
|
|
608
|
+
]
|
|
609
|
+
});
|
|
610
|
+
}
|
|
506
611
|
}
|
|
507
|
-
|
|
508
|
-
const y = EPSG3857_EARTH_RADIUS * Math.log(Math.tan(PI / 4 + projectedLatitude * DEGREES_TO_RADIANS / 2));
|
|
509
|
-
return lngLatZ.length >= 3 ? [x, y, z] : [x, y];
|
|
612
|
+
return segments;
|
|
510
613
|
}
|
|
511
|
-
function
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
614
|
+
function boxesWithin(a, b, radius) {
|
|
615
|
+
return Math.max(a[0] - b[2], b[0] - a[2], a[1] - b[3], b[1] - a[3]) <= radius;
|
|
616
|
+
}
|
|
617
|
+
function segmentsWithin(left, right, radius) {
|
|
618
|
+
if (!boxesWithin(left.bounds, right.bounds, radius))
|
|
619
|
+
return false;
|
|
620
|
+
const { a, b } = left;
|
|
621
|
+
const { a: c, b: d } = right;
|
|
622
|
+
return (0, import_polygon2.segmentsMeet)(a, b, c, d) || radius > 0 && (distanceToPlanarSegment(a, c, d) <= radius || distanceToPlanarSegment(b, c, d) <= radius || distanceToPlanarSegment(c, a, b) <= radius || distanceToPlanarSegment(d, a, b) <= radius);
|
|
623
|
+
}
|
|
624
|
+
function expandBound(value, radius, direction) {
|
|
625
|
+
const padding = Math.max(Math.abs(value), radius) * Number.EPSILON;
|
|
626
|
+
return Math.max(-Number.MAX_VALUE, Math.min(Number.MAX_VALUE, value + direction * (radius + padding)));
|
|
627
|
+
}
|
|
628
|
+
function linesWithinDistance(left, right, radius) {
|
|
629
|
+
const leftBounds = planarBounds(left);
|
|
630
|
+
const rightBounds = planarBounds(right);
|
|
631
|
+
if (!leftBounds || !rightBounds || !boxesWithin(leftBounds, rightBounds, radius))
|
|
632
|
+
return false;
|
|
633
|
+
const a = lineSegments(left);
|
|
634
|
+
const b = lineSegments(right);
|
|
635
|
+
if (!a.length || !b.length)
|
|
636
|
+
return false;
|
|
637
|
+
if (radius === Infinity)
|
|
638
|
+
return true;
|
|
639
|
+
if (a.length * b.length <= directPairLimit || Math.min(a.length, b.length) < 8) {
|
|
640
|
+
return a.some((segment) => b.some((candidate2) => segmentsWithin(segment, candidate2, radius)));
|
|
515
641
|
}
|
|
516
|
-
|
|
517
|
-
|
|
642
|
+
const [indexed, queries] = a.length <= b.length ? [a, b] : [b, a];
|
|
643
|
+
const index = new import_spatial_index.BoxIndex({ dimension: 2, bounds: indexed.flatMap((segment) => segment.bounds) });
|
|
644
|
+
for (const segment of queries) {
|
|
645
|
+
const [x0, y0, x1, y1] = segment.bounds;
|
|
646
|
+
const { result: result2 } = index.searchQuery([expandBound(x0, radius, -1), expandBound(y0, radius, -1)], [expandBound(x1, radius, 1), expandBound(y1, radius, 1)], { filter: (candidate2) => segmentsWithin(segment, indexed[candidate2], radius), maxResults: 1 });
|
|
647
|
+
if (result2.length)
|
|
648
|
+
return true;
|
|
518
649
|
}
|
|
519
|
-
|
|
520
|
-
const latitude = Math.atan(Math.sinh(y / EPSG3857_EARTH_RADIUS)) * RADIANS_TO_DEGREES;
|
|
521
|
-
return xyz.length >= 3 ? [longitude, latitude, z] : [longitude, latitude];
|
|
650
|
+
return false;
|
|
522
651
|
}
|
|
523
|
-
var EPSG4326ToEPSG3857 = lngLatToEPSG3857;
|
|
524
652
|
|
|
525
|
-
// dist/
|
|
526
|
-
|
|
527
|
-
|
|
653
|
+
// dist/route-editing.js
|
|
654
|
+
var import_arrow5 = require("@math.gl/core/arrow");
|
|
655
|
+
var import_polygon3 = require("@math.gl/geometry/polygon");
|
|
656
|
+
|
|
657
|
+
// dist/spatial-line-intersection-result.js
|
|
658
|
+
var import_arrow = require("@math.gl/core/arrow");
|
|
659
|
+
var concrete = [
|
|
660
|
+
{ type: "Point", encoding: "geoarrow.point", id: 1 },
|
|
661
|
+
{ type: "LineString", encoding: "geoarrow.linestring", id: 2 },
|
|
662
|
+
{ type: "MultiPoint", encoding: "geoarrow.multipoint", id: 4 },
|
|
663
|
+
{ type: "MultiLineString", encoding: "geoarrow.multilinestring", id: 5 }
|
|
664
|
+
];
|
|
665
|
+
function lineIntersectionResult() {
|
|
666
|
+
const build = (rows2) => (0, import_arrow.makeArrowVectorFromGeoArrowColumn)({
|
|
667
|
+
encoding: "geoarrow.geometry",
|
|
668
|
+
dimension: "xy",
|
|
669
|
+
coordinateLayout: "interleaved",
|
|
670
|
+
chunks: [union(rows2, true)]
|
|
671
|
+
});
|
|
672
|
+
return { encoding: "geoarrow.geometry", type: build([]).type, build };
|
|
528
673
|
}
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
674
|
+
function union(rows2, collections) {
|
|
675
|
+
const groups = concrete.map(() => []);
|
|
676
|
+
const mixed = [];
|
|
677
|
+
const typeIds = new Int8Array(rows2.length);
|
|
678
|
+
const valueOffsets = new Int32Array(rows2.length);
|
|
679
|
+
for (let row = 0; row < rows2.length; row++) {
|
|
680
|
+
const geometry = rows2[row] ?? null;
|
|
681
|
+
if (collections && (geometry == null ? void 0 : geometry.type) === "GeometryCollection") {
|
|
682
|
+
typeIds[row] = 7;
|
|
683
|
+
valueOffsets[row] = mixed.length;
|
|
684
|
+
mixed.push(geometry);
|
|
685
|
+
} else {
|
|
686
|
+
const index = geometry ? concrete.findIndex((child) => child.type === geometry.type) : 0;
|
|
687
|
+
const group = groups[index];
|
|
688
|
+
if (!group)
|
|
689
|
+
throw new Error("Unexpected line intersection result geometry");
|
|
690
|
+
typeIds[row] = concrete[index].id;
|
|
691
|
+
valueOffsets[row] = group.length;
|
|
692
|
+
group.push(geometry);
|
|
693
|
+
}
|
|
544
694
|
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
695
|
+
const children = concrete.map(({ type, encoding, id }, index) => ({
|
|
696
|
+
name: type,
|
|
697
|
+
encoding,
|
|
698
|
+
typeId: id,
|
|
699
|
+
dimension: "xy",
|
|
700
|
+
coordinateLayout: "interleaved",
|
|
701
|
+
data: import_arrow.GeoArrowBuilder.build(groups[index], { encoding, dimension: "xy" }).chunks[0]
|
|
702
|
+
}));
|
|
703
|
+
if (collections) {
|
|
704
|
+
children.push({
|
|
705
|
+
name: "GeometryCollection",
|
|
706
|
+
encoding: "geoarrow.geometrycollection",
|
|
707
|
+
typeId: 7,
|
|
708
|
+
dimension: "xy",
|
|
709
|
+
coordinateLayout: "interleaved",
|
|
710
|
+
data: collection(mixed)
|
|
711
|
+
});
|
|
558
712
|
}
|
|
713
|
+
return { kind: "dense-union", length: rows2.length, typeIds, valueOffsets, children };
|
|
559
714
|
}
|
|
560
|
-
function
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
case "MultiPoint":
|
|
570
|
-
return g.coordinates[index] ? { type: "Point", coordinates: g.coordinates[index] } : null;
|
|
571
|
-
case "MultiLineString":
|
|
572
|
-
return g.coordinates[index] ? { type: "LineString", coordinates: g.coordinates[index] } : null;
|
|
573
|
-
case "MultiPolygon":
|
|
574
|
-
return g.coordinates[index] ? { type: "Polygon", coordinates: g.coordinates[index] } : null;
|
|
575
|
-
default:
|
|
576
|
-
return position === 1 ? g : null;
|
|
715
|
+
function collection(rows2) {
|
|
716
|
+
const members = [];
|
|
717
|
+
const offsets = new Int32Array(rows2.length + 1);
|
|
718
|
+
for (let row = 0; row < rows2.length; row++) {
|
|
719
|
+
const geometry = rows2[row];
|
|
720
|
+
if (geometry.type === "GeometryCollection")
|
|
721
|
+
for (const child of geometry.geometries)
|
|
722
|
+
members.push(child);
|
|
723
|
+
offsets[row + 1] = members.length;
|
|
577
724
|
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// dist/line-simplification.js
|
|
581
|
-
function removeRepeated(path, tolerance) {
|
|
582
|
-
if (path.length <= 2)
|
|
583
|
-
return path;
|
|
584
|
-
const kept = [path[0]];
|
|
585
|
-
for (let i = 1; i < path.length; i++) {
|
|
586
|
-
const current = path[i], last = kept[kept.length - 1];
|
|
587
|
-
const close = Math.hypot(current[0] - last[0], current[1] - last[1]) <= tolerance;
|
|
588
|
-
if (i === path.length - 1) {
|
|
589
|
-
if (close && kept.length > 1)
|
|
590
|
-
kept.pop();
|
|
591
|
-
} else if (close)
|
|
592
|
-
continue;
|
|
593
|
-
kept.push(current);
|
|
594
|
-
}
|
|
595
|
-
return kept;
|
|
596
|
-
}
|
|
597
|
-
function distanceToSegment(p, a, b) {
|
|
598
|
-
const dx = b[0] - a[0], dy = b[1] - a[1];
|
|
599
|
-
const length = Math.hypot(dx, dy);
|
|
600
|
-
const px = p[0] - a[0], py = p[1] - a[1];
|
|
601
|
-
const t = length ? Math.max(0, Math.min(1, (px * (dx / length) + py * (dy / length)) / length)) : 0;
|
|
602
|
-
return Math.hypot(px - t * dx, py - t * dy);
|
|
603
|
-
}
|
|
604
|
-
function simplify(path, tolerance) {
|
|
605
|
-
if (!path.length)
|
|
606
|
-
return path;
|
|
607
|
-
const last = path.length - 1;
|
|
608
|
-
const kept = new Uint8Array(path.length);
|
|
609
|
-
kept[0] = kept[last] = 1;
|
|
610
|
-
const spans = [0, last];
|
|
611
|
-
while (spans.length) {
|
|
612
|
-
const end = spans.pop(), start = spans.pop();
|
|
613
|
-
let split = start, maximum = tolerance;
|
|
614
|
-
for (let i = start + 1; i < end; i++) {
|
|
615
|
-
const distance = distanceToSegment(path[i], path[start], path[end]);
|
|
616
|
-
if (distance > maximum) {
|
|
617
|
-
maximum = distance;
|
|
618
|
-
split = i;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
if (split !== start) {
|
|
622
|
-
kept[split] = 1;
|
|
623
|
-
spans.push(start, split, split, end);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
const result2 = path.filter((_, i) => kept[i]);
|
|
627
|
-
if (result2.length === 2 && result2[0][0] === result2[1][0] && result2[0][1] === result2[1][1])
|
|
628
|
-
return [];
|
|
629
|
-
return result2;
|
|
630
|
-
}
|
|
631
|
-
function reduceLineVertices(geometry, tolerance, mode) {
|
|
632
|
-
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
633
|
-
throw new Error("Expected a finite nonnegative tolerance");
|
|
634
|
-
if ((geometry.type === "LineString" || geometry.type === "MultiLineString") && (!geometry.coordinates.length || geometry.type === "MultiLineString" && geometry.coordinates.every((path) => !path.length)))
|
|
635
|
-
return geometry;
|
|
636
|
-
const reduce = mode === "simplify" ? simplify : removeRepeated;
|
|
637
|
-
if (geometry.type === "LineString") {
|
|
638
|
-
const coordinates2 = reduce(geometry.coordinates, tolerance);
|
|
639
|
-
return coordinates2.length || mode === "removeRepeated" ? { type: "LineString", coordinates: coordinates2 } : null;
|
|
640
|
-
}
|
|
641
|
-
if (geometry.type !== "MultiLineString")
|
|
642
|
-
throw new Error("Expected line geometry");
|
|
643
|
-
const reduced = geometry.coordinates.map((path) => reduce(path, tolerance));
|
|
644
|
-
if (mode === "removeRepeated")
|
|
645
|
-
return { type: "MultiLineString", coordinates: reduced };
|
|
646
|
-
const coordinates = reduced.filter((path) => path.length);
|
|
647
|
-
return coordinates.length ? { type: "MultiLineString", coordinates } : null;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
// dist/geometry-constructors.js
|
|
651
|
-
function collectPair(a, b) {
|
|
652
|
-
if (a.type === "Point" && b.type === "Point")
|
|
653
|
-
return { type: "MultiPoint", coordinates: [a.coordinates, b.coordinates] };
|
|
654
|
-
if (a.type === "LineString" && b.type === "LineString")
|
|
655
|
-
return { type: "MultiLineString", coordinates: [a.coordinates, b.coordinates] };
|
|
656
|
-
if (a.type === "Polygon" && b.type === "Polygon")
|
|
657
|
-
return { type: "MultiPolygon", coordinates: [a.coordinates, b.coordinates] };
|
|
658
|
-
return { type: "GeometryCollection", geometries: [a, b] };
|
|
659
|
-
}
|
|
660
|
-
function makeLine(parts) {
|
|
661
|
-
const coordinates = [];
|
|
662
|
-
for (const part of parts) {
|
|
663
|
-
if (part.type === "Point") {
|
|
664
|
-
if (part.coordinates.length)
|
|
665
|
-
coordinates.push(part.coordinates);
|
|
666
|
-
} else if (part.type === "MultiPoint") {
|
|
667
|
-
for (const point2 of part.coordinates)
|
|
668
|
-
if (point2.length && !point2.every(Number.isNaN))
|
|
669
|
-
coordinates.push(point2);
|
|
670
|
-
} else if (part.type === "LineString") {
|
|
671
|
-
const previous = coordinates[coordinates.length - 1];
|
|
672
|
-
const first = part.coordinates[0];
|
|
673
|
-
const shared = previous && first && previous[0] === first[0] && previous[1] === first[1];
|
|
674
|
-
for (let i = shared ? 1 : 0; i < part.coordinates.length; i++)
|
|
675
|
-
coordinates.push(part.coordinates[i]);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
return { type: "LineString", coordinates };
|
|
725
|
+
return { kind: "list", length: rows2.length, offsets, child: union(members, false) };
|
|
679
726
|
}
|
|
680
727
|
|
|
681
728
|
// dist/spatial-sql.js
|
|
682
729
|
var import_apache_arrow = require("apache-arrow");
|
|
683
|
-
var
|
|
730
|
+
var import_arrow4 = require("@math.gl/core/arrow");
|
|
684
731
|
|
|
685
732
|
// dist/turf.js
|
|
686
|
-
var import_arrow = require("@math.gl/core/arrow");
|
|
687
733
|
var import_arrow2 = require("@math.gl/core/arrow");
|
|
734
|
+
var import_arrow3 = require("@math.gl/core/arrow");
|
|
688
735
|
var RAD = Math.PI / 180;
|
|
689
736
|
var depths = {
|
|
690
737
|
"geoarrow.point": 0,
|
|
@@ -700,7 +747,7 @@ function rows(column2, allowed) {
|
|
|
700
747
|
const result2 = [];
|
|
701
748
|
for (const array of column2.chunks)
|
|
702
749
|
for (let index = 0; index < array.length; index++)
|
|
703
|
-
result2.push({ array, index, valid: (0,
|
|
750
|
+
result2.push({ array, index, valid: (0, import_arrow2.isGeoArrowValueValid)(array.validity, index) });
|
|
704
751
|
return result2;
|
|
705
752
|
}
|
|
706
753
|
function range(array, index) {
|
|
@@ -716,12 +763,12 @@ function range(array, index) {
|
|
|
716
763
|
function scalar(array, index) {
|
|
717
764
|
if (array.kind !== "primitive")
|
|
718
765
|
throw new Error("Invalid GeoArrow coordinate");
|
|
719
|
-
if (!(0,
|
|
766
|
+
if (!(0, import_arrow2.isGeoArrowValueValid)(array.validity, index))
|
|
720
767
|
return NaN;
|
|
721
768
|
return Number(array.values[(array.offset || 0) + index * (array.stride || 1)]);
|
|
722
769
|
}
|
|
723
770
|
function point(array, index) {
|
|
724
|
-
if (!(0,
|
|
771
|
+
if (!(0, import_arrow2.isGeoArrowValueValid)(array.validity, index))
|
|
725
772
|
return null;
|
|
726
773
|
if (array.kind === "fixed-size-list") {
|
|
727
774
|
const i = ((array.offset || 0) + index) * array.size;
|
|
@@ -755,7 +802,7 @@ function paired(a, b) {
|
|
|
755
802
|
}
|
|
756
803
|
var native = Object.keys(depths);
|
|
757
804
|
var points = ["geoarrow.point"];
|
|
758
|
-
var
|
|
805
|
+
var polygons2 = ["geoarrow.polygon", "geoarrow.multipolygon"];
|
|
759
806
|
function ringContains(array, a, b, p) {
|
|
760
807
|
let inside = false;
|
|
761
808
|
for (let i = a, j = b - 1; i < b; j = i++) {
|
|
@@ -774,10 +821,10 @@ function polygonContains(array, index, p) {
|
|
|
774
821
|
const [a, b] = range(array, index);
|
|
775
822
|
if (array.kind !== "list")
|
|
776
823
|
throw new Error("Invalid polygon");
|
|
777
|
-
if (a === b || !(0,
|
|
824
|
+
if (a === b || !(0, import_arrow2.isGeoArrowValueValid)(array.child.validity, a))
|
|
778
825
|
return -1;
|
|
779
826
|
for (let i = a; i < b; i++) {
|
|
780
|
-
if (!(0,
|
|
827
|
+
if (!(0, import_arrow2.isGeoArrowValueValid)(array.child.validity, i))
|
|
781
828
|
continue;
|
|
782
829
|
const [x, y] = range(array.child, i);
|
|
783
830
|
if (array.child.kind !== "list")
|
|
@@ -791,7 +838,7 @@ function polygonContains(array, index, p) {
|
|
|
791
838
|
return a === b ? -1 : 1;
|
|
792
839
|
}
|
|
793
840
|
function booleanPointInPolygon(pointColumn, polygonColumn, options = {}) {
|
|
794
|
-
const a = rows(pointColumn, points), b = rows(polygonColumn,
|
|
841
|
+
const a = rows(pointColumn, points), b = rows(polygonColumn, polygons2), n = paired(a, b), out = result(n, true);
|
|
795
842
|
for (let i = 0; i < n; i++) {
|
|
796
843
|
const x = a[a.length === 1 ? 0 : i], y = b[b.length === 1 ? 0 : i];
|
|
797
844
|
if (!x.valid || !y.valid)
|
|
@@ -808,7 +855,7 @@ function booleanPointInPolygon(pointColumn, polygonColumn, options = {}) {
|
|
|
808
855
|
if (y.array.kind !== "list")
|
|
809
856
|
throw new Error("Invalid multipolygon");
|
|
810
857
|
for (let j = start; j < end; j++) {
|
|
811
|
-
if (!(0,
|
|
858
|
+
if (!(0, import_arrow2.isGeoArrowValueValid)(y.array.child.validity, j))
|
|
812
859
|
continue;
|
|
813
860
|
const c = polygonContains(y.array.child, j, p);
|
|
814
861
|
if (c > 0 || c === 0 && !options.ignoreBoundary) {
|
|
@@ -822,7 +869,7 @@ function booleanPointInPolygon(pointColumn, polygonColumn, options = {}) {
|
|
|
822
869
|
}
|
|
823
870
|
return out;
|
|
824
871
|
}
|
|
825
|
-
var lineFamilies = ["geoarrow.linestring", "geoarrow.multilinestring", ...
|
|
872
|
+
var lineFamilies = ["geoarrow.linestring", "geoarrow.multilinestring", ...polygons2];
|
|
826
873
|
|
|
827
874
|
// dist/spatial-sql.js
|
|
828
875
|
var EXTENSION_NAME = "ARROW:extension:name";
|
|
@@ -838,10 +885,47 @@ var geometryTypes = [
|
|
|
838
885
|
var pointKinds = ["Point"];
|
|
839
886
|
var lineKinds = ["LineString", "MultiLineString"];
|
|
840
887
|
var polygonKinds = ["Polygon", "MultiPolygon"];
|
|
888
|
+
function nativePointVector(type, data, nullBitmap, nullCount) {
|
|
889
|
+
const child = (0, import_apache_arrow.makeData)({ type: type.valueType, data, length: data.length });
|
|
890
|
+
return (0, import_apache_arrow.makeVector)((0, import_apache_arrow.makeData)({ type, length: data.length / type.listSize, nullCount, nullBitmap, child }));
|
|
891
|
+
}
|
|
892
|
+
function nativeXYPointResult() {
|
|
893
|
+
const type = new import_apache_arrow.FixedSizeList(2, new import_apache_arrow.Field("xy", new import_apache_arrow.Float64(), true));
|
|
894
|
+
return {
|
|
895
|
+
encoding: "geoarrow.point",
|
|
896
|
+
type,
|
|
897
|
+
/** Writes empty points as NaN coordinates and uses a bitmap for null rows. */
|
|
898
|
+
build(rows2) {
|
|
899
|
+
const values = new Float64Array(rows2.length * 2);
|
|
900
|
+
const validity = new Uint8Array(Math.ceil(rows2.length / 8));
|
|
901
|
+
let nullCount = 0;
|
|
902
|
+
for (let row = 0; row < rows2.length; row++) {
|
|
903
|
+
const point2 = rows2[row];
|
|
904
|
+
if (!point2) {
|
|
905
|
+
nullCount++;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (point2.type !== "Point")
|
|
909
|
+
throw new Error("Expected a Point result");
|
|
910
|
+
validity[row >> 3] |= 1 << (row & 7);
|
|
911
|
+
values[2 * row] = point2.coordinates[0] ?? NaN;
|
|
912
|
+
values[2 * row + 1] = point2.coordinates[1] ?? NaN;
|
|
913
|
+
}
|
|
914
|
+
return nativePointVector(type, values, validity, nullCount);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function nativeGeometryResult(encoding) {
|
|
919
|
+
if (encoding === "geoarrow.point")
|
|
920
|
+
return nativeXYPointResult();
|
|
921
|
+
const options = { encoding, dimension: "xy", coordinateLayout: "interleaved" };
|
|
922
|
+
const build = (rows2) => (0, import_arrow4.makeArrowVectorFromGeoArrowColumn)(import_arrow4.GeoArrowBuilder.build(rows2, options));
|
|
923
|
+
return { encoding, type: build([]).type, build };
|
|
924
|
+
}
|
|
841
925
|
function readGeometryValue(vector, field, active, value, captureMembers = false) {
|
|
842
926
|
if (import_apache_arrow.DataType.isBinary(field.type) || import_apache_arrow.DataType.isLargeBinary(field.type)) {
|
|
843
927
|
return (row) => {
|
|
844
|
-
const { geometry, dimension, srid, members } = (0,
|
|
928
|
+
const { geometry, dimension, srid, members } = (0, import_arrow4.parseWKB)(vector.get(row), {
|
|
845
929
|
captureMembers
|
|
846
930
|
});
|
|
847
931
|
if (srid)
|
|
@@ -849,131 +933,2551 @@ function readGeometryValue(vector, field, active, value, captureMembers = false)
|
|
|
849
933
|
return value(geometry.type === "Point" && geometry.coordinates.every(Number.isNaN) ? { type: "Point", coordinates: [] } : geometry, dimension, members);
|
|
850
934
|
};
|
|
851
935
|
}
|
|
852
|
-
const column2 = readActiveGeoArrowColumn(vector, field, active);
|
|
853
|
-
const geometries = (0,
|
|
854
|
-
return (row) => value(geometries[row], column2.dimension);
|
|
936
|
+
const column2 = readActiveGeoArrowColumn(vector, field, active);
|
|
937
|
+
const geometries = (0, import_arrow4.materializeGeoArrowRows)(column2);
|
|
938
|
+
return (row) => value(geometries[row], column2.dimension);
|
|
939
|
+
}
|
|
940
|
+
function readActiveGeoArrowColumn(vector, field, active) {
|
|
941
|
+
const column2 = (0, import_arrow4.makeGeoArrowColumnFromArrowVector)(vector, { field });
|
|
942
|
+
let offset = 0;
|
|
943
|
+
const chunks = column2.chunks.map((chunk) => {
|
|
944
|
+
const start = offset;
|
|
945
|
+
offset += chunk.length;
|
|
946
|
+
let needsMask = false;
|
|
947
|
+
for (let row = 0; row < chunk.length; row++) {
|
|
948
|
+
if (!active[start + row] && (0, import_arrow4.isGeoArrowValueValid)(chunk.validity, row)) {
|
|
949
|
+
needsMask = true;
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if (!needsMask)
|
|
954
|
+
return chunk;
|
|
955
|
+
const values = new Uint8Array(Math.ceil(chunk.length / 8));
|
|
956
|
+
for (let row = 0; row < chunk.length; row++) {
|
|
957
|
+
if (active[start + row] && (0, import_arrow4.isGeoArrowValueValid)(chunk.validity, row)) {
|
|
958
|
+
values[row >> 3] |= 1 << (row & 7);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return { ...chunk, validity: { values } };
|
|
962
|
+
});
|
|
963
|
+
return { ...column2, chunks };
|
|
964
|
+
}
|
|
965
|
+
function planarGeometry(geometry, dimension) {
|
|
966
|
+
if (dimension !== "xy")
|
|
967
|
+
throw new Error("Spatial SQL functions require 2D geometry");
|
|
968
|
+
return geometry;
|
|
969
|
+
}
|
|
970
|
+
function spatialFunction(name, signatures, output, evaluate, numericArguments = 0, allDimensions = false, skipNullGeometries = false, validateCRS) {
|
|
971
|
+
const type = "encoding" in output ? output.type : output;
|
|
972
|
+
return {
|
|
973
|
+
kind: "scalar",
|
|
974
|
+
name,
|
|
975
|
+
prototypes: [],
|
|
976
|
+
/** Binds the allowed geometry types and result metadata to a call. */
|
|
977
|
+
resolvePrototype(fields) {
|
|
978
|
+
var _a;
|
|
979
|
+
if (fields.length !== signatures.length + numericArguments)
|
|
980
|
+
return void 0;
|
|
981
|
+
const geometryFields = fields.slice(0, signatures.length);
|
|
982
|
+
const numberFields = fields.slice(signatures.length).map((field) => {
|
|
983
|
+
if (field && !import_apache_arrow.DataType.isInt(field.type) && !import_apache_arrow.DataType.isFloat(field.type))
|
|
984
|
+
throw new Error(`${name} requires numeric arguments`);
|
|
985
|
+
return field ?? new import_apache_arrow.Field("number", new import_apache_arrow.Float64(), true);
|
|
986
|
+
});
|
|
987
|
+
const extensions = geometryFields.map((field, index) => {
|
|
988
|
+
if (!field)
|
|
989
|
+
return void 0;
|
|
990
|
+
const extension = (0, import_arrow4.getGeoArrowFieldInfo)(field);
|
|
991
|
+
const encoding = extension == null ? void 0 : extension.encoding;
|
|
992
|
+
const kinds = signatures[index];
|
|
993
|
+
if (encoding === "geoarrow.wkb" && (import_apache_arrow.DataType.isBinary(field.type) || import_apache_arrow.DataType.isLargeBinary(field.type))) {
|
|
994
|
+
} else if (encoding === "geoarrow.geometry" && extension.dimension === "xy") {
|
|
995
|
+
} else if (kinds.some((kind) => encoding === "geoarrow." + kind.toLowerCase())) {
|
|
996
|
+
if (!allDimensions && (extension == null ? void 0 : extension.dimension) !== "xy")
|
|
997
|
+
throw new Error(`${name} requires 2D geometry`);
|
|
998
|
+
} else {
|
|
999
|
+
throw new Error(`${name} argument ${index + 1} requires GeoArrow ${kinds.join(" or ")}`);
|
|
1000
|
+
}
|
|
1001
|
+
validateCRS == null ? void 0 : validateCRS(extension == null ? void 0 : extension.metadata["crs"], name);
|
|
1002
|
+
if (!validateCRS && name.startsWith("ST_") && name !== "ST_SRID" && name !== "ST_SetSRID" && (extension == null ? void 0 : extension.metadata["edges"]) === "spherical")
|
|
1003
|
+
throw new Error(`${name} requires planar geometry`);
|
|
1004
|
+
return extension;
|
|
1005
|
+
});
|
|
1006
|
+
const crsValues = extensions.map((extension) => extension == null ? void 0 : extension.metadata["crs"]).filter((crs) => crs !== void 0 && crs !== null);
|
|
1007
|
+
if (!validateCRS && name.startsWith("ST_") && crsValues.some((crs) => JSON.stringify(crs) !== JSON.stringify(crsValues[0]))) {
|
|
1008
|
+
throw new Error(`${name} requires arguments in the same CRS`);
|
|
1009
|
+
}
|
|
1010
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
1011
|
+
if ("encoding" in output || import_apache_arrow.DataType.isBinary(type)) {
|
|
1012
|
+
metadata.set(EXTENSION_NAME, "encoding" in output ? output.encoding : "geoarrow.wkb");
|
|
1013
|
+
const inputMetadata = (_a = extensions[0]) == null ? void 0 : _a.metadata;
|
|
1014
|
+
const crs = inputMetadata == null ? void 0 : inputMetadata["crs"];
|
|
1015
|
+
const crsType = crs === void 0 ? void 0 : inputMetadata == null ? void 0 : inputMetadata["crs_type"];
|
|
1016
|
+
const edges2 = inputMetadata == null ? void 0 : inputMetadata["edges"];
|
|
1017
|
+
if (crs !== void 0 || edges2 !== void 0) {
|
|
1018
|
+
metadata.set(EXTENSION_METADATA, JSON.stringify({ crs, crs_type: crsType, edges: edges2 }));
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
const arguments_ = [
|
|
1022
|
+
...geometryFields.map((field) => field ?? new import_apache_arrow.Field("geometry", new import_apache_arrow.Binary(), true)),
|
|
1023
|
+
...numberFields
|
|
1024
|
+
];
|
|
1025
|
+
return {
|
|
1026
|
+
arguments: arguments_,
|
|
1027
|
+
nullHandling: skipNullGeometries ? "call" : "propagate",
|
|
1028
|
+
result: new import_apache_arrow.Field(name, type, true, metadata),
|
|
1029
|
+
/** Evaluates active rows and retains their positions in the output batch. */
|
|
1030
|
+
evaluate(vectors, { activeRows, length: rowCount }) {
|
|
1031
|
+
const numbers = vectors.slice(signatures.length);
|
|
1032
|
+
const readers = vectors.slice(0, signatures.length).map((vector, index) => readGeometryValue(vector, arguments_[index], activeRows, allDimensions ? (g, dimension, members) => ({ ...g, dimension, members }) : planarGeometry, name === "ST_GeometryN"));
|
|
1033
|
+
const values = new Array(rowCount).fill(null);
|
|
1034
|
+
for (let row = 0; row < rowCount; row++) {
|
|
1035
|
+
if (!activeRows[row])
|
|
1036
|
+
continue;
|
|
1037
|
+
const geometries = [];
|
|
1038
|
+
for (let index = 0; index < readers.length; index++) {
|
|
1039
|
+
if (skipNullGeometries && !vectors[index].isValid(row))
|
|
1040
|
+
continue;
|
|
1041
|
+
const geometry = readers[index](row);
|
|
1042
|
+
if (!signatures[index].includes(geometry.type))
|
|
1043
|
+
throw new Error(`${name} argument ${index + 1} does not support ${geometry.type} at row ${row}`);
|
|
1044
|
+
geometries.push(geometry);
|
|
1045
|
+
}
|
|
1046
|
+
values[row] = evaluate(geometries, ...numbers.map((vector) => Number(vector.get(row))));
|
|
1047
|
+
}
|
|
1048
|
+
return "encoding" in output ? output.build(values) : (0, import_apache_arrow.vectorFromArray)(values, output);
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function pointCoordinates(geometry) {
|
|
1055
|
+
return geometry.type === "Point" && Number.isFinite(geometry.coordinates[0]) && Number.isFinite(geometry.coordinates[1]) ? geometry.coordinates : null;
|
|
1056
|
+
}
|
|
1057
|
+
function column(geometry) {
|
|
1058
|
+
return (0, import_arrow4.makeGeoArrowColumnFromGeometryRows)([geometry], { dimension: "xy" });
|
|
1059
|
+
}
|
|
1060
|
+
function scalar2(result2) {
|
|
1061
|
+
return result2.validity[0] & 1 ? result2.values[0] : null;
|
|
1062
|
+
}
|
|
1063
|
+
function pointInPolygon(point2, polygon, ignoreBoundary = false) {
|
|
1064
|
+
if (!pointCoordinates(point2))
|
|
1065
|
+
return null;
|
|
1066
|
+
const value = scalar2(booleanPointInPolygon(column(point2), column(polygon), { ignoreBoundary }));
|
|
1067
|
+
return value === null ? null : value === 1;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// dist/route-editing.js
|
|
1071
|
+
function mergeRoute(geometry) {
|
|
1072
|
+
if (geometry.type === "LineString")
|
|
1073
|
+
return geometry;
|
|
1074
|
+
if (geometry.type !== "MultiLineString")
|
|
1075
|
+
throw new Error("ST_LineMerge requires linear geometry");
|
|
1076
|
+
const merged = (0, import_polygon3.mergePolylinePaths)(geometry.coordinates);
|
|
1077
|
+
return merged.length === 1 ? { type: "LineString", coordinates: merged[0] } : { type: "MultiLineString", coordinates: merged };
|
|
1078
|
+
}
|
|
1079
|
+
var MAX_ADDED_VERTICES = 1e6;
|
|
1080
|
+
function segmentizeRoute(geometry, step, name, segmentFor) {
|
|
1081
|
+
if (!Number.isFinite(step) || step <= 0)
|
|
1082
|
+
throw new Error(name + " requires a finite positive maximum segment length");
|
|
1083
|
+
if (geometry.type === "LineString") {
|
|
1084
|
+
const [coordinates] = (0, import_polygon3.segmentizePolylinePaths)([geometry.coordinates], step, MAX_ADDED_VERTICES, segmentFor);
|
|
1085
|
+
return { type: "LineString", coordinates };
|
|
1086
|
+
}
|
|
1087
|
+
if (geometry.type === "MultiLineString") {
|
|
1088
|
+
return {
|
|
1089
|
+
type: "MultiLineString",
|
|
1090
|
+
coordinates: (0, import_polygon3.segmentizePolylinePaths)(geometry.coordinates, step, MAX_ADDED_VERTICES, segmentFor)
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
throw new Error(name + " requires linear geometry");
|
|
1094
|
+
}
|
|
1095
|
+
function routeEditingFunction(name, preservesLineKind, evaluate, numericArguments = 0, validateCRS) {
|
|
1096
|
+
return {
|
|
1097
|
+
kind: "scalar",
|
|
1098
|
+
name,
|
|
1099
|
+
prototypes: [],
|
|
1100
|
+
/** Binds a stable native output for specialized, WKB, and mixed inputs. */
|
|
1101
|
+
resolvePrototype(fields) {
|
|
1102
|
+
var _a;
|
|
1103
|
+
const encoding = fields[0] && ((_a = (0, import_arrow5.getGeoArrowFieldInfo)(fields[0])) == null ? void 0 : _a.encoding);
|
|
1104
|
+
const output = encoding === "geoarrow.linestring" || preservesLineKind && encoding === "geoarrow.multilinestring" ? nativeGeometryResult(encoding) : lineIntersectionResult();
|
|
1105
|
+
return spatialFunction(name, [lineKinds], output, ([geometry], ...numbers) => evaluate(geometry, ...numbers), numericArguments, false, false, validateCRS).resolvePrototype(fields);
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
function segmentizeFunction(name, segmentFor, validateCRS) {
|
|
1110
|
+
return routeEditingFunction(name, true, (geometry, step) => segmentizeRoute(geometry, step, name, segmentFor), 1, validateCRS);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// dist/linear-referencing.js
|
|
1114
|
+
var import_polygon4 = require("@math.gl/geometry/polygon");
|
|
1115
|
+
function cumulativeDistances(path) {
|
|
1116
|
+
const distances = [0];
|
|
1117
|
+
for (let i = 1; i < path.length; i++) {
|
|
1118
|
+
const a = path[i - 1], b = path[i];
|
|
1119
|
+
distances.push(distances[i - 1] + Math.hypot(b[0] - a[0], b[1] - a[1]));
|
|
1120
|
+
}
|
|
1121
|
+
return distances;
|
|
1122
|
+
}
|
|
1123
|
+
function coordinateAt(path, distances, target) {
|
|
1124
|
+
for (let i = 0; i < path.length; i++) {
|
|
1125
|
+
if (target === distances[i])
|
|
1126
|
+
return path[i];
|
|
1127
|
+
if (target < distances[i]) {
|
|
1128
|
+
const t = (target - distances[i - 1]) / (distances[i] - distances[i - 1]);
|
|
1129
|
+
const a = path[i - 1], b = path[i];
|
|
1130
|
+
return [(1 - t) * a[0] + t * b[0], (1 - t) * a[1] + t * b[1]];
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return path[path.length - 1];
|
|
1134
|
+
}
|
|
1135
|
+
function lineSubstring(line, start, end) {
|
|
1136
|
+
if (!(start >= 0 && end <= 1 && start <= end))
|
|
1137
|
+
throw new Error("Expected ordered route fractions in [0, 1]");
|
|
1138
|
+
if (line.type !== "LineString" || !line.coordinates.length)
|
|
1139
|
+
return null;
|
|
1140
|
+
const path = line.coordinates;
|
|
1141
|
+
const distances = cumulativeDistances(path);
|
|
1142
|
+
const total = distances[distances.length - 1];
|
|
1143
|
+
const from = start * total, to = end * total;
|
|
1144
|
+
if (from === to)
|
|
1145
|
+
return { type: "Point", coordinates: coordinateAt(path, distances, from) };
|
|
1146
|
+
const coordinates = [];
|
|
1147
|
+
let startSegment = 0;
|
|
1148
|
+
while (distances[startSegment + 1] <= from)
|
|
1149
|
+
startSegment++;
|
|
1150
|
+
let endSegment = startSegment;
|
|
1151
|
+
while (distances[endSegment + 1] < to)
|
|
1152
|
+
endSegment++;
|
|
1153
|
+
(0, import_polygon4.visitPolylineSpan)((vertex, ordinate) => path[vertex][ordinate], startSegment, (from - distances[startSegment]) / (distances[startSegment + 1] - distances[startSegment]), endSegment, (to - distances[endSegment]) / (distances[endSegment + 1] - distances[endSegment]), (x, y, vertex) => {
|
|
1154
|
+
if (vertex === void 0 || distances[vertex] !== distances[vertex - 1])
|
|
1155
|
+
coordinates.push([x, y]);
|
|
1156
|
+
});
|
|
1157
|
+
return { type: "LineString", coordinates };
|
|
1158
|
+
}
|
|
1159
|
+
function projectPointToLine(line, point2) {
|
|
1160
|
+
return line.type === "LineString" && point2.type === "Point" ? (0, import_polygon4.projectPointToPolyline)(line.coordinates, point2.coordinates) : null;
|
|
1161
|
+
}
|
|
1162
|
+
function lineLocatePoint(line, point2) {
|
|
1163
|
+
var _a;
|
|
1164
|
+
return ((_a = projectPointToLine(line, point2)) == null ? void 0 : _a.fraction) ?? null;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// dist/measure-referencing.js
|
|
1168
|
+
function pathsOf(geometry) {
|
|
1169
|
+
if (geometry.type === "LineString")
|
|
1170
|
+
return [geometry.coordinates];
|
|
1171
|
+
if (geometry.type === "MultiLineString")
|
|
1172
|
+
return geometry.coordinates;
|
|
1173
|
+
throw new Error("Measured routes require a LineString or MultiLineString");
|
|
1174
|
+
}
|
|
1175
|
+
function measuredDimension(dimension) {
|
|
1176
|
+
if (dimension === "xym" || dimension === "xyzm")
|
|
1177
|
+
return dimension;
|
|
1178
|
+
throw new Error("Input geometry requires a measure (M) ordinate");
|
|
1179
|
+
}
|
|
1180
|
+
function addMeasure(geometry, dimension, start, end) {
|
|
1181
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
1182
|
+
throw new Error("Expected finite measures");
|
|
1183
|
+
const paths3 = pathsOf(geometry);
|
|
1184
|
+
let total = 0;
|
|
1185
|
+
const distances = paths3.map((path) => path.map((point2, i) => {
|
|
1186
|
+
if (i > 0) {
|
|
1187
|
+
const previous = path[i - 1];
|
|
1188
|
+
total += Math.hypot(point2[0] - previous[0], point2[1] - previous[1]);
|
|
1189
|
+
}
|
|
1190
|
+
return total;
|
|
1191
|
+
}));
|
|
1192
|
+
if (!Number.isFinite(total))
|
|
1193
|
+
throw new Error("Expected finite route length");
|
|
1194
|
+
const spatialSize = dimension.includes("z") ? 3 : 2;
|
|
1195
|
+
const coordinates = paths3.map((path, part) => path.map((point2, i) => {
|
|
1196
|
+
const fraction = total ? distances[part][i] / total : 0;
|
|
1197
|
+
return [...point2.slice(0, spatialSize), (1 - fraction) * start + fraction * end];
|
|
1198
|
+
}));
|
|
1199
|
+
return {
|
|
1200
|
+
geometry: geometry.type === "LineString" ? { type: "LineString", coordinates: coordinates[0] } : { type: "MultiLineString", coordinates },
|
|
1201
|
+
dimension: spatialSize === 3 ? "xyzm" : "xym"
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
function samePosition(a, b) {
|
|
1205
|
+
return a.every((value, i) => value === b[i]);
|
|
1206
|
+
}
|
|
1207
|
+
function atMeasure(a, b, index, measure) {
|
|
1208
|
+
const from = a[index];
|
|
1209
|
+
const to = b[index];
|
|
1210
|
+
if (from !== to) {
|
|
1211
|
+
if (measure === from)
|
|
1212
|
+
return a;
|
|
1213
|
+
if (measure === to)
|
|
1214
|
+
return b;
|
|
1215
|
+
}
|
|
1216
|
+
const span = to - from;
|
|
1217
|
+
const fraction = span === 0 ? 0.5 : Number.isFinite(span) ? (measure - from) / span : (measure / 2 - from / 2) / (to / 2 - from / 2);
|
|
1218
|
+
return a.map((value, i) => i === index ? measure : (1 - fraction) * value + fraction * b[i]);
|
|
1219
|
+
}
|
|
1220
|
+
function measureAt(position, index) {
|
|
1221
|
+
const value = position[index];
|
|
1222
|
+
if (!Number.isFinite(value))
|
|
1223
|
+
throw new Error("Expected finite route measures");
|
|
1224
|
+
return value;
|
|
1225
|
+
}
|
|
1226
|
+
function locateAlong(geometry, dimension, measure) {
|
|
1227
|
+
if (!Number.isFinite(measure))
|
|
1228
|
+
throw new Error("Expected a finite measure");
|
|
1229
|
+
const index = dimension.indexOf("m");
|
|
1230
|
+
const coordinates = [];
|
|
1231
|
+
for (const path of pathsOf(geometry)) {
|
|
1232
|
+
let previousEndsAtVertex = false;
|
|
1233
|
+
for (let i = 1; i < path.length; i++) {
|
|
1234
|
+
const a = path[i - 1];
|
|
1235
|
+
const b = path[i];
|
|
1236
|
+
const from = measureAt(a, index);
|
|
1237
|
+
const to = measureAt(b, index);
|
|
1238
|
+
if (measure < Math.min(from, to) || measure > Math.max(from, to)) {
|
|
1239
|
+
previousEndsAtVertex = false;
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
const startsAtVertex = from !== to && measure === from;
|
|
1243
|
+
if (!previousEndsAtVertex || !startsAtVertex) {
|
|
1244
|
+
coordinates.push(atMeasure(a, b, index, measure));
|
|
1245
|
+
}
|
|
1246
|
+
previousEndsAtVertex = from !== to && measure === to;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return { type: "MultiPoint", coordinates };
|
|
1250
|
+
}
|
|
1251
|
+
function appendPortion(parts, path) {
|
|
1252
|
+
if (path.length === 1)
|
|
1253
|
+
parts.push({ type: "Point", coordinates: path[0] });
|
|
1254
|
+
else if (path.length > 1)
|
|
1255
|
+
parts.push({ type: "LineString", coordinates: path });
|
|
1256
|
+
}
|
|
1257
|
+
function locateBetween(geometry, dimension, start, end) {
|
|
1258
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
1259
|
+
throw new Error("Expected finite measures");
|
|
1260
|
+
const low = Math.min(start, end);
|
|
1261
|
+
const high = Math.max(start, end);
|
|
1262
|
+
const index = dimension.indexOf("m");
|
|
1263
|
+
const parts = [];
|
|
1264
|
+
for (const path of pathsOf(geometry)) {
|
|
1265
|
+
let portion = [];
|
|
1266
|
+
for (let i = 1; i < path.length; i++) {
|
|
1267
|
+
const a = path[i - 1];
|
|
1268
|
+
const b = path[i];
|
|
1269
|
+
const from = measureAt(a, index);
|
|
1270
|
+
const to = measureAt(b, index);
|
|
1271
|
+
const begin = Math.max(low, Math.min(from, to));
|
|
1272
|
+
const finish = Math.min(high, Math.max(from, to));
|
|
1273
|
+
if (begin > finish)
|
|
1274
|
+
continue;
|
|
1275
|
+
const first = from === to ? a : atMeasure(a, b, index, from <= to ? begin : finish);
|
|
1276
|
+
const last = from === to ? b : atMeasure(a, b, index, from <= to ? finish : begin);
|
|
1277
|
+
if (!portion.length)
|
|
1278
|
+
portion.push(first);
|
|
1279
|
+
if (!samePosition(portion[portion.length - 1], last))
|
|
1280
|
+
portion.push(last);
|
|
1281
|
+
if (to < low || to > high) {
|
|
1282
|
+
appendPortion(parts, portion);
|
|
1283
|
+
portion = [];
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
appendPortion(parts, portion);
|
|
1287
|
+
}
|
|
1288
|
+
return parts.every((part) => part.type === "LineString") ? { type: "MultiLineString", coordinates: parts.map((part) => part.coordinates) } : { type: "GeometryCollection", geometries: parts };
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// dist/crs/crs-identifier.js
|
|
1292
|
+
var WMS_CRS_CODES = /* @__PURE__ */ new Map([
|
|
1293
|
+
["84", "CRS84"],
|
|
1294
|
+
["83", "CRS83"],
|
|
1295
|
+
["27", "CRS27"]
|
|
1296
|
+
]);
|
|
1297
|
+
var KNOWN_AUTHORITIES = /* @__PURE__ */ new Set(["EPSG", "OGC", "ESRI", "IAU"]);
|
|
1298
|
+
var OGC_CRS_CODES = /* @__PURE__ */ new Map([
|
|
1299
|
+
["CRS84", "CRS84"],
|
|
1300
|
+
["CRS83", "CRS83"],
|
|
1301
|
+
["CRS27", "CRS27"],
|
|
1302
|
+
["CRS84H", "CRS84h"]
|
|
1303
|
+
]);
|
|
1304
|
+
var AUTHORITY_CODE = /^([A-Z][A-Z0-9_-]*):([A-Z0-9_.-]+)$/i;
|
|
1305
|
+
var OGC_URN = /^urn:ogc:def:crs:([A-Z][A-Z0-9_-]*):([^:]*):([A-Z0-9_.-]+)$/i;
|
|
1306
|
+
var OGC_URI = /^https?:\/\/www\.opengis\.net\/def\/crs\/([A-Z][A-Z0-9_-]*)\/([^/]+)\/([A-Z0-9_.-]+)\/?$/i;
|
|
1307
|
+
function normalizeCRSIdentifier(identifier) {
|
|
1308
|
+
const text = identifier.trim();
|
|
1309
|
+
const authorityCode = AUTHORITY_CODE.exec(text);
|
|
1310
|
+
if (authorityCode) {
|
|
1311
|
+
const [, authority, code] = authorityCode;
|
|
1312
|
+
if (authority.toUpperCase() === "CRS") {
|
|
1313
|
+
const ogcCode = WMS_CRS_CODES.get(code);
|
|
1314
|
+
return ogcCode ? `OGC:${ogcCode}` : identifier;
|
|
1315
|
+
}
|
|
1316
|
+
return formatIdentifier(authority, code);
|
|
1317
|
+
}
|
|
1318
|
+
const versioned = OGC_URN.exec(text) || OGC_URI.exec(text);
|
|
1319
|
+
if (versioned) {
|
|
1320
|
+
const [, authority, version, code] = versioned;
|
|
1321
|
+
return isUnversioned(authority, version, code) ? formatIdentifier(authority, code) : identifier;
|
|
1322
|
+
}
|
|
1323
|
+
return identifier;
|
|
1324
|
+
}
|
|
1325
|
+
function isUnversioned(authority, version, code) {
|
|
1326
|
+
if (version === "" || version === "0")
|
|
1327
|
+
return true;
|
|
1328
|
+
const ogcCode = code.toUpperCase();
|
|
1329
|
+
return authority.toUpperCase() === "OGC" && version === "1.3" && Array.from(WMS_CRS_CODES.values()).includes(ogcCode);
|
|
1330
|
+
}
|
|
1331
|
+
function formatIdentifier(authority, code) {
|
|
1332
|
+
const upperAuthority = authority.toUpperCase();
|
|
1333
|
+
const canonicalAuthority = KNOWN_AUTHORITIES.has(upperAuthority) ? upperAuthority : authority;
|
|
1334
|
+
const canonicalCode = canonicalAuthority === "OGC" ? OGC_CRS_CODES.get(code.toUpperCase()) || code : code;
|
|
1335
|
+
return `${canonicalAuthority}:${canonicalCode}`;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// dist/web-mercator/mercator-meters.js
|
|
1339
|
+
var PI = Math.PI;
|
|
1340
|
+
var DEGREES_TO_RADIANS = PI / 180;
|
|
1341
|
+
var RADIANS_TO_DEGREES = 180 / PI;
|
|
1342
|
+
var EPSG3857_EARTH_RADIUS = 6378137;
|
|
1343
|
+
var EPSG3857_HALF_CIRCUMFERENCE = PI * EPSG3857_EARTH_RADIUS;
|
|
1344
|
+
var EPSG3857_MAX_LATITUDE = Math.atan(Math.sinh(PI)) * RADIANS_TO_DEGREES;
|
|
1345
|
+
var EPSG3857_UNITS_PER_METER = 512 / (2 * EPSG3857_HALF_CIRCUMFERENCE);
|
|
1346
|
+
function lngLatToEPSG3857(lngLatZ, options = {}) {
|
|
1347
|
+
const [longitude, latitude, z] = lngLatZ;
|
|
1348
|
+
const { clampLatitude = true } = options;
|
|
1349
|
+
if (!Number.isFinite(longitude) || !Number.isFinite(latitude)) {
|
|
1350
|
+
throw new Error("Invalid longitude or latitude");
|
|
1351
|
+
}
|
|
1352
|
+
if (lngLatZ.length >= 3 && !Number.isFinite(z)) {
|
|
1353
|
+
throw new Error("Invalid elevation");
|
|
1354
|
+
}
|
|
1355
|
+
const projectedLatitude = clampLatitude ? Math.max(-EPSG3857_MAX_LATITUDE, Math.min(EPSG3857_MAX_LATITUDE, latitude)) : latitude;
|
|
1356
|
+
if (projectedLatitude < -EPSG3857_MAX_LATITUDE || projectedLatitude > EPSG3857_MAX_LATITUDE) {
|
|
1357
|
+
throw new Error("Latitude is outside the finite EPSG:3857 range");
|
|
1358
|
+
}
|
|
1359
|
+
const x = EPSG3857_EARTH_RADIUS * longitude * DEGREES_TO_RADIANS;
|
|
1360
|
+
const y = EPSG3857_EARTH_RADIUS * Math.log(Math.tan(PI / 4 + projectedLatitude * DEGREES_TO_RADIANS / 2));
|
|
1361
|
+
return lngLatZ.length >= 3 ? [x, y, z] : [x, y];
|
|
1362
|
+
}
|
|
1363
|
+
function EPSG3857ToLngLat(xyz) {
|
|
1364
|
+
const [x, y, z] = xyz;
|
|
1365
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
1366
|
+
throw new Error("Invalid EPSG:3857 coordinate");
|
|
1367
|
+
}
|
|
1368
|
+
if (xyz.length >= 3 && !Number.isFinite(z)) {
|
|
1369
|
+
throw new Error("Invalid elevation");
|
|
1370
|
+
}
|
|
1371
|
+
const longitude = x / EPSG3857_EARTH_RADIUS * RADIANS_TO_DEGREES;
|
|
1372
|
+
const latitude = Math.atan(Math.sinh(y / EPSG3857_EARTH_RADIUS)) * RADIANS_TO_DEGREES;
|
|
1373
|
+
return xyz.length >= 3 ? [longitude, latitude, z] : [longitude, latitude];
|
|
1374
|
+
}
|
|
1375
|
+
var EPSG4326ToEPSG3857 = lngLatToEPSG3857;
|
|
1376
|
+
|
|
1377
|
+
// dist/geometry-inspection.js
|
|
1378
|
+
function hasPosition(position) {
|
|
1379
|
+
return position.length > 0 && !position.every(Number.isNaN);
|
|
1380
|
+
}
|
|
1381
|
+
function vertexCount(g) {
|
|
1382
|
+
switch (g.type) {
|
|
1383
|
+
case "Point":
|
|
1384
|
+
return Number(hasPosition(g.coordinates));
|
|
1385
|
+
case "MultiPoint":
|
|
1386
|
+
return g.coordinates.reduce((sum, p) => sum + Number(hasPosition(p)), 0);
|
|
1387
|
+
case "LineString":
|
|
1388
|
+
return g.coordinates.length;
|
|
1389
|
+
case "Polygon":
|
|
1390
|
+
case "MultiLineString":
|
|
1391
|
+
return g.coordinates.reduce((sum, path) => sum + path.length, 0);
|
|
1392
|
+
case "MultiPolygon":
|
|
1393
|
+
return g.coordinates.reduce((sum, polygon) => sum + polygon.reduce((count, ring) => count + ring.length, 0), 0);
|
|
1394
|
+
case "GeometryCollection":
|
|
1395
|
+
return g.geometries.reduce((sum, child) => sum + vertexCount(child), 0);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
function memberCount(g) {
|
|
1399
|
+
if (!vertexCount(g))
|
|
1400
|
+
return 0;
|
|
1401
|
+
switch (g.type) {
|
|
1402
|
+
case "GeometryCollection":
|
|
1403
|
+
return g.geometries.length;
|
|
1404
|
+
case "MultiPoint":
|
|
1405
|
+
case "MultiLineString":
|
|
1406
|
+
case "MultiPolygon":
|
|
1407
|
+
return g.coordinates.length;
|
|
1408
|
+
default:
|
|
1409
|
+
return 1;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
function geometryMember(g, position) {
|
|
1413
|
+
if (!Number.isInteger(position))
|
|
1414
|
+
throw new Error("ST_GeometryN requires an integer position");
|
|
1415
|
+
if (!vertexCount(g))
|
|
1416
|
+
return null;
|
|
1417
|
+
const index = position - 1;
|
|
1418
|
+
switch (g.type) {
|
|
1419
|
+
case "GeometryCollection":
|
|
1420
|
+
return g.geometries[index] ?? null;
|
|
1421
|
+
case "MultiPoint":
|
|
1422
|
+
return g.coordinates[index] ? { type: "Point", coordinates: g.coordinates[index] } : null;
|
|
1423
|
+
case "MultiLineString":
|
|
1424
|
+
return g.coordinates[index] ? { type: "LineString", coordinates: g.coordinates[index] } : null;
|
|
1425
|
+
case "MultiPolygon":
|
|
1426
|
+
return g.coordinates[index] ? { type: "Polygon", coordinates: g.coordinates[index] } : null;
|
|
1427
|
+
default:
|
|
1428
|
+
return position === 1 ? g : null;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// dist/line-simplification.js
|
|
1433
|
+
function removeRepeated(path, tolerance) {
|
|
1434
|
+
if (path.length <= 2)
|
|
1435
|
+
return path;
|
|
1436
|
+
const kept = [path[0]];
|
|
1437
|
+
for (let i = 1; i < path.length; i++) {
|
|
1438
|
+
const current = path[i], last = kept[kept.length - 1];
|
|
1439
|
+
const close = Math.hypot(current[0] - last[0], current[1] - last[1]) <= tolerance;
|
|
1440
|
+
if (i === path.length - 1) {
|
|
1441
|
+
if (close && kept.length > 1)
|
|
1442
|
+
kept.pop();
|
|
1443
|
+
} else if (close)
|
|
1444
|
+
continue;
|
|
1445
|
+
kept.push(current);
|
|
1446
|
+
}
|
|
1447
|
+
return kept;
|
|
1448
|
+
}
|
|
1449
|
+
function simplifyLine(path, tolerance) {
|
|
1450
|
+
if (!path.length)
|
|
1451
|
+
return path;
|
|
1452
|
+
const last = path.length - 1;
|
|
1453
|
+
const kept = new Uint8Array(path.length);
|
|
1454
|
+
kept[0] = kept[last] = 1;
|
|
1455
|
+
const spans = [0, last];
|
|
1456
|
+
while (spans.length) {
|
|
1457
|
+
const end = spans.pop(), start = spans.pop();
|
|
1458
|
+
let split = start, maximum = tolerance;
|
|
1459
|
+
for (let i = start + 1; i < end; i++) {
|
|
1460
|
+
const distance = distanceToPlanarSegment(path[i], path[start], path[end]);
|
|
1461
|
+
if (distance > maximum) {
|
|
1462
|
+
maximum = distance;
|
|
1463
|
+
split = i;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (split !== start) {
|
|
1467
|
+
kept[split] = 1;
|
|
1468
|
+
spans.push(start, split, split, end);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
const result2 = path.filter((_, i) => kept[i]);
|
|
1472
|
+
if (result2.length === 2 && result2[0][0] === result2[1][0] && result2[0][1] === result2[1][1])
|
|
1473
|
+
return [];
|
|
1474
|
+
return result2;
|
|
1475
|
+
}
|
|
1476
|
+
function reduceLineVertices(geometry, tolerance, mode) {
|
|
1477
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
1478
|
+
throw new Error("Expected a finite nonnegative tolerance");
|
|
1479
|
+
if ((geometry.type === "LineString" || geometry.type === "MultiLineString") && (!geometry.coordinates.length || geometry.type === "MultiLineString" && geometry.coordinates.every((path) => !path.length)))
|
|
1480
|
+
return geometry;
|
|
1481
|
+
const reduce = mode === "simplify" ? simplifyLine : removeRepeated;
|
|
1482
|
+
if (geometry.type === "LineString") {
|
|
1483
|
+
const coordinates2 = reduce(geometry.coordinates, tolerance);
|
|
1484
|
+
return coordinates2.length || mode === "removeRepeated" ? { type: "LineString", coordinates: coordinates2 } : null;
|
|
1485
|
+
}
|
|
1486
|
+
if (geometry.type !== "MultiLineString")
|
|
1487
|
+
throw new Error("Expected line geometry");
|
|
1488
|
+
const reduced = geometry.coordinates.map((path) => reduce(path, tolerance));
|
|
1489
|
+
if (mode === "removeRepeated")
|
|
1490
|
+
return { type: "MultiLineString", coordinates: reduced };
|
|
1491
|
+
const coordinates = reduced.filter((path) => path.length);
|
|
1492
|
+
return coordinates.length ? { type: "MultiLineString", coordinates } : null;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// dist/polygon-simplification.js
|
|
1496
|
+
var import_robust_predicates = require("robust-predicates");
|
|
1497
|
+
var import_processing = require("@math.gl/geometry/processing");
|
|
1498
|
+
function samePoint2(a, b) {
|
|
1499
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
1500
|
+
}
|
|
1501
|
+
function signedArea(ring) {
|
|
1502
|
+
const [x, y] = ring[0];
|
|
1503
|
+
let area = 0;
|
|
1504
|
+
for (let i = 1; i + 1 < ring.length; i++) {
|
|
1505
|
+
const a = ring[i];
|
|
1506
|
+
const b = ring[i + 1];
|
|
1507
|
+
area += (a[0] - x) * (b[1] - y) - (a[1] - y) * (b[0] - x);
|
|
1508
|
+
}
|
|
1509
|
+
return area;
|
|
1510
|
+
}
|
|
1511
|
+
function separatedBoundaries(rings) {
|
|
1512
|
+
const edges2 = [];
|
|
1513
|
+
for (const ring of rings) {
|
|
1514
|
+
const size = ring.length - 1;
|
|
1515
|
+
if (size < 3 || !samePoint2(ring[0], ring[size]))
|
|
1516
|
+
return false;
|
|
1517
|
+
for (let i = 0; i < size; i++) {
|
|
1518
|
+
const a = ring[i];
|
|
1519
|
+
const b = ring[i + 1];
|
|
1520
|
+
const c = ring[(i + 2) % size];
|
|
1521
|
+
if (!Number.isFinite(a[0]) || !Number.isFinite(a[1]) || samePoint2(a, b))
|
|
1522
|
+
return false;
|
|
1523
|
+
if ((0, import_robust_predicates.orient2d)(a[0], a[1], b[0], b[1], c[0], c[1]) === 0 && (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1]) > 0)
|
|
1524
|
+
return false;
|
|
1525
|
+
edges2.push({
|
|
1526
|
+
a,
|
|
1527
|
+
b,
|
|
1528
|
+
ring,
|
|
1529
|
+
index: i,
|
|
1530
|
+
bounds: [
|
|
1531
|
+
Math.min(a[0], b[0]),
|
|
1532
|
+
Math.min(a[1], b[1]),
|
|
1533
|
+
Math.max(a[0], b[0]),
|
|
1534
|
+
Math.max(a[1], b[1])
|
|
1535
|
+
]
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return !(0, import_processing.anyBoundsOverlap)(edges2, (a, b) => {
|
|
1540
|
+
if (a.ring === b.ring) {
|
|
1541
|
+
const gap = Math.abs(a.index - b.index);
|
|
1542
|
+
if (gap === 1 || gap === a.ring.length - 2)
|
|
1543
|
+
return false;
|
|
1544
|
+
}
|
|
1545
|
+
return (0, import_polygon2.segmentsMeet)(a.a, a.b, b.a, b.b);
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
function contains(outer, inner) {
|
|
1549
|
+
return planarIntersects({ type: "Polygon", coordinates: [outer] }, { type: "Point", coordinates: inner[0] });
|
|
1550
|
+
}
|
|
1551
|
+
function preservesNesting(before, after) {
|
|
1552
|
+
const rings = before.map((original, index) => ({
|
|
1553
|
+
original,
|
|
1554
|
+
simplified: after[index],
|
|
1555
|
+
bounds: planarBounds({ type: "LineString", coordinates: original })
|
|
1556
|
+
}));
|
|
1557
|
+
return !(0, import_processing.anyBoundsOverlap)(rings, (a, b) => contains(a.original, b.original) !== contains(a.simplified, b.simplified) || contains(b.original, a.original) !== contains(b.simplified, a.simplified));
|
|
1558
|
+
}
|
|
1559
|
+
function simplifyRing(ring, tolerance) {
|
|
1560
|
+
const reduced = simplifyLine(ring, tolerance);
|
|
1561
|
+
if (reduced.length < 4 || reduced.length === ring.length)
|
|
1562
|
+
return ring;
|
|
1563
|
+
const before = signedArea(ring);
|
|
1564
|
+
const after = signedArea(reduced);
|
|
1565
|
+
return Number.isFinite(before) && Number.isFinite(after) && after && Math.sign(before) === Math.sign(after) ? reduced : ring;
|
|
1566
|
+
}
|
|
1567
|
+
function simplifyPolygonTopology(geometry, tolerance) {
|
|
1568
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
1569
|
+
throw new Error("Expected a finite nonnegative tolerance");
|
|
1570
|
+
if (!tolerance)
|
|
1571
|
+
return geometry;
|
|
1572
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
1573
|
+
const before = polygons3.flat();
|
|
1574
|
+
const reduced = polygons3.map((polygon) => polygon.map((ring) => simplifyRing(ring, tolerance)));
|
|
1575
|
+
const after = reduced.flat();
|
|
1576
|
+
if (before.every((ring, index) => ring === after[index]))
|
|
1577
|
+
return geometry;
|
|
1578
|
+
if (!separatedBoundaries(before) || !separatedBoundaries(after) || !preservesNesting(before, after))
|
|
1579
|
+
return geometry;
|
|
1580
|
+
return geometry.type === "Polygon" ? { type: "Polygon", coordinates: reduced[0] } : { type: "MultiPolygon", coordinates: reduced };
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// dist/geometry-constructors.js
|
|
1584
|
+
function collectPair(a, b) {
|
|
1585
|
+
if (a.type === "Point" && b.type === "Point")
|
|
1586
|
+
return { type: "MultiPoint", coordinates: [a.coordinates, b.coordinates] };
|
|
1587
|
+
if (a.type === "LineString" && b.type === "LineString")
|
|
1588
|
+
return { type: "MultiLineString", coordinates: [a.coordinates, b.coordinates] };
|
|
1589
|
+
if (a.type === "Polygon" && b.type === "Polygon")
|
|
1590
|
+
return { type: "MultiPolygon", coordinates: [a.coordinates, b.coordinates] };
|
|
1591
|
+
return { type: "GeometryCollection", geometries: [a, b] };
|
|
1592
|
+
}
|
|
1593
|
+
function makeLine(parts) {
|
|
1594
|
+
const coordinates = [];
|
|
1595
|
+
for (const part of parts) {
|
|
1596
|
+
if (part.type === "Point") {
|
|
1597
|
+
if (part.coordinates.length)
|
|
1598
|
+
coordinates.push(part.coordinates);
|
|
1599
|
+
} else if (part.type === "MultiPoint") {
|
|
1600
|
+
for (const point2 of part.coordinates)
|
|
1601
|
+
if (point2.length && !point2.every(Number.isNaN))
|
|
1602
|
+
coordinates.push(point2);
|
|
1603
|
+
} else if (part.type === "LineString") {
|
|
1604
|
+
const previous = coordinates[coordinates.length - 1];
|
|
1605
|
+
const first = part.coordinates[0];
|
|
1606
|
+
const shared = previous && first && previous[0] === first[0] && previous[1] === first[1];
|
|
1607
|
+
for (let i = shared ? 1 : 0; i < part.coordinates.length; i++)
|
|
1608
|
+
coordinates.push(part.coordinates[i]);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return { type: "LineString", coordinates };
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// dist/st-geodesic-functions.js
|
|
1615
|
+
var import_apache_arrow2 = require("apache-arrow");
|
|
1616
|
+
|
|
1617
|
+
// dist/constants.js
|
|
1618
|
+
var WGS84_RADIUS_X = 6378137;
|
|
1619
|
+
var WGS84_RADIUS_Y = 6378137;
|
|
1620
|
+
var WGS84_RADIUS_Z = 6356752314245179e-9;
|
|
1621
|
+
var WGS84_CONSTANTS = {
|
|
1622
|
+
radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
|
|
1623
|
+
radiiSquared: [
|
|
1624
|
+
WGS84_RADIUS_X * WGS84_RADIUS_X,
|
|
1625
|
+
WGS84_RADIUS_Y * WGS84_RADIUS_Y,
|
|
1626
|
+
WGS84_RADIUS_Z * WGS84_RADIUS_Z
|
|
1627
|
+
],
|
|
1628
|
+
oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
|
|
1629
|
+
oneOverRadiiSquared: [
|
|
1630
|
+
1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
|
|
1631
|
+
1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
|
|
1632
|
+
1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
|
|
1633
|
+
],
|
|
1634
|
+
maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
|
|
1635
|
+
centerToleranceSquared: 0.1
|
|
1636
|
+
// EPSILON1;
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
// dist/vendor/geographiclib-geodesic/runtime.js
|
|
1640
|
+
var geodesic = {};
|
|
1641
|
+
geodesic.Constants = {};
|
|
1642
|
+
geodesic.Math = {};
|
|
1643
|
+
geodesic.Accumulator = {};
|
|
1644
|
+
(function(c) {
|
|
1645
|
+
"use strict";
|
|
1646
|
+
c.WGS84 = { a: 6378137, f: 1 / 298.257223563 };
|
|
1647
|
+
c.version = {
|
|
1648
|
+
major: 2,
|
|
1649
|
+
minor: 2,
|
|
1650
|
+
patch: 0
|
|
1651
|
+
};
|
|
1652
|
+
c.version_string = "2.2.0";
|
|
1653
|
+
})(geodesic.Constants);
|
|
1654
|
+
(function(m) {
|
|
1655
|
+
"use strict";
|
|
1656
|
+
m.digits = 53;
|
|
1657
|
+
m.epsilon = Math.pow(0.5, m.digits - 1);
|
|
1658
|
+
m.degree = Math.PI / 180;
|
|
1659
|
+
m.sq = function(x) {
|
|
1660
|
+
return x * x;
|
|
1661
|
+
};
|
|
1662
|
+
m.hypot = function(x, y) {
|
|
1663
|
+
return Math.sqrt(x * x + y * y);
|
|
1664
|
+
};
|
|
1665
|
+
m.cbrt = Math.cbrt || function(x) {
|
|
1666
|
+
var y = Math.pow(Math.abs(x), 1 / 3);
|
|
1667
|
+
return x > 0 ? y : x < 0 ? -y : x;
|
|
1668
|
+
};
|
|
1669
|
+
m.log1p = Math.log1p || function(x) {
|
|
1670
|
+
var y = 1 + x, z = y - 1;
|
|
1671
|
+
return z === 0 ? x : x * Math.log(y) / z;
|
|
1672
|
+
};
|
|
1673
|
+
m.atanh = Math.atanh || function(x) {
|
|
1674
|
+
var y = Math.abs(x);
|
|
1675
|
+
y = m.log1p(2 * y / (1 - y)) / 2;
|
|
1676
|
+
return x > 0 ? y : x < 0 ? -y : x;
|
|
1677
|
+
};
|
|
1678
|
+
m.copysign = function(x, y) {
|
|
1679
|
+
return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
|
|
1680
|
+
};
|
|
1681
|
+
m.sum = function(u, v) {
|
|
1682
|
+
var s = u + v, up = s - v, vpp = s - up, t;
|
|
1683
|
+
up -= u;
|
|
1684
|
+
vpp -= v;
|
|
1685
|
+
t = s ? 0 - (up + vpp) : s;
|
|
1686
|
+
return { s, t };
|
|
1687
|
+
};
|
|
1688
|
+
m.polyval = function(N, p, s, x) {
|
|
1689
|
+
var y = N < 0 ? 0 : p[s++];
|
|
1690
|
+
while (--N >= 0)
|
|
1691
|
+
y = y * x + p[s++];
|
|
1692
|
+
return y;
|
|
1693
|
+
};
|
|
1694
|
+
m.AngRound = function(x) {
|
|
1695
|
+
var z = 1 / 16, y = Math.abs(x);
|
|
1696
|
+
y = y < z ? z - (z - y) : y;
|
|
1697
|
+
return m.copysign(y, x);
|
|
1698
|
+
};
|
|
1699
|
+
m.remainder = function(x, y) {
|
|
1700
|
+
x %= y;
|
|
1701
|
+
return x < -y / 2 ? x + y : x < y / 2 ? x : x - y;
|
|
1702
|
+
};
|
|
1703
|
+
m.AngNormalize = function(x) {
|
|
1704
|
+
var y = m.remainder(x, 360);
|
|
1705
|
+
return Math.abs(y) === 180 ? m.copysign(180, x) : y;
|
|
1706
|
+
};
|
|
1707
|
+
m.LatFix = function(x) {
|
|
1708
|
+
return Math.abs(x) > 90 ? NaN : x;
|
|
1709
|
+
};
|
|
1710
|
+
m.AngDiff = function(x, y) {
|
|
1711
|
+
var r = m.sum(m.remainder(-x, 360), m.remainder(y, 360)), d, e;
|
|
1712
|
+
r = m.sum(m.remainder(r.s, 360), r.t);
|
|
1713
|
+
d = r.s;
|
|
1714
|
+
e = r.t;
|
|
1715
|
+
if (d === 0 || Math.abs(d) === 180)
|
|
1716
|
+
d = m.copysign(d, e === 0 ? y - x : -e);
|
|
1717
|
+
return { d, e };
|
|
1718
|
+
};
|
|
1719
|
+
m.sincosd = function(x) {
|
|
1720
|
+
var d, r, q, s, c, sinx, cosx;
|
|
1721
|
+
d = x % 360;
|
|
1722
|
+
q = Math.round(d / 90);
|
|
1723
|
+
d -= 90 * q;
|
|
1724
|
+
r = d * this.degree;
|
|
1725
|
+
s = Math.sin(r);
|
|
1726
|
+
c = Math.cos(r);
|
|
1727
|
+
if (Math.abs(d) === 45) {
|
|
1728
|
+
c = Math.sqrt(0.5);
|
|
1729
|
+
s = m.copysign(c, r);
|
|
1730
|
+
} else if (Math.abs(d) === 30) {
|
|
1731
|
+
c = Math.sqrt(0.75);
|
|
1732
|
+
s = m.copysign(0.5, r);
|
|
1733
|
+
}
|
|
1734
|
+
switch (q & 3) {
|
|
1735
|
+
case 0:
|
|
1736
|
+
sinx = s;
|
|
1737
|
+
cosx = c;
|
|
1738
|
+
break;
|
|
1739
|
+
case 1:
|
|
1740
|
+
sinx = c;
|
|
1741
|
+
cosx = -s;
|
|
1742
|
+
break;
|
|
1743
|
+
case 2:
|
|
1744
|
+
sinx = -s;
|
|
1745
|
+
cosx = -c;
|
|
1746
|
+
break;
|
|
1747
|
+
default:
|
|
1748
|
+
sinx = -c;
|
|
1749
|
+
cosx = s;
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
cosx += 0;
|
|
1753
|
+
if (sinx === 0)
|
|
1754
|
+
sinx = m.copysign(sinx, x);
|
|
1755
|
+
return { s: sinx, c: cosx };
|
|
1756
|
+
};
|
|
1757
|
+
m.sincosde = function(x, t) {
|
|
1758
|
+
var d, r, q, s, c, sinx, cosx;
|
|
1759
|
+
d = x % 360;
|
|
1760
|
+
q = Math.round(d / 90);
|
|
1761
|
+
d = m.AngRound(d - 90 * q + t);
|
|
1762
|
+
r = d * this.degree;
|
|
1763
|
+
s = Math.sin(r);
|
|
1764
|
+
c = Math.cos(r);
|
|
1765
|
+
if (Math.abs(d) === 45) {
|
|
1766
|
+
c = Math.sqrt(0.5);
|
|
1767
|
+
s = m.copysign(c, r);
|
|
1768
|
+
} else if (Math.abs(d) === 30) {
|
|
1769
|
+
c = Math.sqrt(0.75);
|
|
1770
|
+
s = m.copysign(0.5, r);
|
|
1771
|
+
}
|
|
1772
|
+
switch (q & 3) {
|
|
1773
|
+
case 0:
|
|
1774
|
+
sinx = s;
|
|
1775
|
+
cosx = c;
|
|
1776
|
+
break;
|
|
1777
|
+
case 1:
|
|
1778
|
+
sinx = c;
|
|
1779
|
+
cosx = -s;
|
|
1780
|
+
break;
|
|
1781
|
+
case 2:
|
|
1782
|
+
sinx = -s;
|
|
1783
|
+
cosx = -c;
|
|
1784
|
+
break;
|
|
1785
|
+
default:
|
|
1786
|
+
sinx = -c;
|
|
1787
|
+
cosx = s;
|
|
1788
|
+
break;
|
|
1789
|
+
}
|
|
1790
|
+
cosx += 0;
|
|
1791
|
+
if (sinx === 0)
|
|
1792
|
+
sinx = m.copysign(sinx, x + t);
|
|
1793
|
+
return { s: sinx, c: cosx };
|
|
1794
|
+
};
|
|
1795
|
+
m.atan2d = function(y, x) {
|
|
1796
|
+
var q = 0, ang;
|
|
1797
|
+
if (Math.abs(y) > Math.abs(x)) {
|
|
1798
|
+
[y, x] = [x, y];
|
|
1799
|
+
q = 2;
|
|
1800
|
+
}
|
|
1801
|
+
if (m.copysign(1, x) < 0) {
|
|
1802
|
+
x = -x;
|
|
1803
|
+
++q;
|
|
1804
|
+
}
|
|
1805
|
+
ang = Math.atan2(y, x) / this.degree;
|
|
1806
|
+
switch (q) {
|
|
1807
|
+
// Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
|
|
1808
|
+
// atan2d will not be called with y = -0. If need be, include
|
|
1809
|
+
//
|
|
1810
|
+
// case 0: ang = 0 + ang; break;
|
|
1811
|
+
//
|
|
1812
|
+
// and handle mpfr as in AngRound.
|
|
1813
|
+
case 1:
|
|
1814
|
+
ang = m.copysign(180, y) - ang;
|
|
1815
|
+
break;
|
|
1816
|
+
case 2:
|
|
1817
|
+
ang = 90 - ang;
|
|
1818
|
+
break;
|
|
1819
|
+
case 3:
|
|
1820
|
+
ang = -90 + ang;
|
|
1821
|
+
break;
|
|
1822
|
+
default:
|
|
1823
|
+
break;
|
|
1824
|
+
}
|
|
1825
|
+
return ang;
|
|
1826
|
+
};
|
|
1827
|
+
})(geodesic.Math);
|
|
1828
|
+
(function(a, m) {
|
|
1829
|
+
"use strict";
|
|
1830
|
+
a.Accumulator = function(y) {
|
|
1831
|
+
this.Set(y);
|
|
1832
|
+
};
|
|
1833
|
+
a.Accumulator.prototype.Set = function(y) {
|
|
1834
|
+
if (!y)
|
|
1835
|
+
y = 0;
|
|
1836
|
+
if (y.constructor === a.Accumulator) {
|
|
1837
|
+
this._s = y._s;
|
|
1838
|
+
this._t = y._t;
|
|
1839
|
+
} else {
|
|
1840
|
+
this._s = y;
|
|
1841
|
+
this._t = 0;
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
a.Accumulator.prototype.Add = function(y) {
|
|
1845
|
+
var u = m.sum(y, this._t), v = m.sum(u.s, this._s);
|
|
1846
|
+
u = u.t;
|
|
1847
|
+
this._s = v.s;
|
|
1848
|
+
this._t = v.t;
|
|
1849
|
+
if (this._s === 0)
|
|
1850
|
+
this._s = u;
|
|
1851
|
+
else
|
|
1852
|
+
this._t += u;
|
|
1853
|
+
};
|
|
1854
|
+
a.Accumulator.prototype.Sum = function(y) {
|
|
1855
|
+
var b;
|
|
1856
|
+
if (!y)
|
|
1857
|
+
return this._s;
|
|
1858
|
+
else {
|
|
1859
|
+
b = new a.Accumulator(this);
|
|
1860
|
+
b.Add(y);
|
|
1861
|
+
return b._s;
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
a.Accumulator.prototype.Negate = function() {
|
|
1865
|
+
this._s *= -1;
|
|
1866
|
+
this._t *= -1;
|
|
1867
|
+
};
|
|
1868
|
+
a.Accumulator.prototype.Remainder = function(y) {
|
|
1869
|
+
this._s = m.remainder(this._s, y);
|
|
1870
|
+
this.Add(0);
|
|
1871
|
+
};
|
|
1872
|
+
})(geodesic.Accumulator, geodesic.Math);
|
|
1873
|
+
geodesic.Geodesic = {};
|
|
1874
|
+
geodesic.GeodesicLine = {};
|
|
1875
|
+
geodesic.PolygonArea = {};
|
|
1876
|
+
(function(g, l, p, m, c) {
|
|
1877
|
+
"use strict";
|
|
1878
|
+
var GEOGRAPHICLIB_GEODESIC_ORDER = 6, nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA3x_ = nA3_, nC3x_, nC4x_, maxit1_ = 20, maxit2_ = maxit1_ + m.digits + 10, tol0_ = m.epsilon, tol1_ = 200 * tol0_, tol2_ = Math.sqrt(tol0_), tolb_ = tol0_, xthresh_ = 1e3 * tol2_, CAP_NONE = 0, CAP_ALL = 31, OUT_ALL = 32640, astroid, A1m1f_coeff, C1f_coeff, C1pf_coeff, A2m1f_coeff, C2f_coeff, A3_coeff, C3_coeff, C4_coeff;
|
|
1879
|
+
g.tiny_ = Math.sqrt(Number.MIN_VALUE / Number.EPSILON);
|
|
1880
|
+
g.nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1881
|
+
g.nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1882
|
+
g.nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1883
|
+
g.nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1884
|
+
g.nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1885
|
+
nC3x_ = g.nC3_ * (g.nC3_ - 1) / 2;
|
|
1886
|
+
nC4x_ = g.nC4_ * (g.nC4_ + 1) / 2;
|
|
1887
|
+
g.CAP_C1 = 1 << 0;
|
|
1888
|
+
g.CAP_C1p = 1 << 1;
|
|
1889
|
+
g.CAP_C2 = 1 << 2;
|
|
1890
|
+
g.CAP_C3 = 1 << 3;
|
|
1891
|
+
g.CAP_C4 = 1 << 4;
|
|
1892
|
+
g.NONE = 0;
|
|
1893
|
+
g.ARC = 1 << 6;
|
|
1894
|
+
g.LATITUDE = 1 << 7 | CAP_NONE;
|
|
1895
|
+
g.LONGITUDE = 1 << 8 | g.CAP_C3;
|
|
1896
|
+
g.AZIMUTH = 1 << 9 | CAP_NONE;
|
|
1897
|
+
g.DISTANCE = 1 << 10 | g.CAP_C1;
|
|
1898
|
+
g.STANDARD = g.LATITUDE | g.LONGITUDE | g.AZIMUTH | g.DISTANCE;
|
|
1899
|
+
g.DISTANCE_IN = 1 << 11 | g.CAP_C1 | g.CAP_C1p;
|
|
1900
|
+
g.REDUCEDLENGTH = 1 << 12 | g.CAP_C1 | g.CAP_C2;
|
|
1901
|
+
g.GEODESICSCALE = 1 << 13 | g.CAP_C1 | g.CAP_C2;
|
|
1902
|
+
g.AREA = 1 << 14 | g.CAP_C4;
|
|
1903
|
+
g.ALL = OUT_ALL | CAP_ALL;
|
|
1904
|
+
g.LONG_UNROLL = 1 << 15;
|
|
1905
|
+
g.OUT_MASK = OUT_ALL | g.LONG_UNROLL;
|
|
1906
|
+
g.SinCosSeries = function(sinp, sinx, cosx, c2, delta) {
|
|
1907
|
+
if (delta !== void 0) {
|
|
1908
|
+
var h = delta / 2, sh = Math.sin(h), ch = Math.cos(h);
|
|
1909
|
+
return -2 * g.SinCosSeries(false, cosx * ch - sinx * sh, sinx * ch + cosx * sh, c2.map(function(v, i) {
|
|
1910
|
+
return (i % 2 ? -v : v) * Math.sin((2 * i + 1) * h);
|
|
1911
|
+
}));
|
|
1912
|
+
}
|
|
1913
|
+
var k = c2.length, n = k - (sinp ? 1 : 0), ar = 2 * (cosx - sinx) * (cosx + sinx), y0 = n & 1 ? c2[--k] : 0, y1 = 0;
|
|
1914
|
+
n = Math.floor(n / 2);
|
|
1915
|
+
while (n--) {
|
|
1916
|
+
y1 = ar * y0 - y1 + c2[--k];
|
|
1917
|
+
y0 = ar * y1 - y0 + c2[--k];
|
|
1918
|
+
}
|
|
1919
|
+
return sinp ? 2 * sinx * cosx * y0 : (
|
|
1920
|
+
// sin(2 * x) * y0
|
|
1921
|
+
cosx * (y0 - y1)
|
|
1922
|
+
);
|
|
1923
|
+
};
|
|
1924
|
+
astroid = function(x, y) {
|
|
1925
|
+
var k, p2 = m.sq(x), q = m.sq(y), r = (p2 + q - 1) / 6, S, r2, r3, disc, u, T3, T, ang, v, uv, w;
|
|
1926
|
+
if (!(q === 0 && r <= 0)) {
|
|
1927
|
+
S = p2 * q / 4;
|
|
1928
|
+
r2 = m.sq(r);
|
|
1929
|
+
r3 = r * r2;
|
|
1930
|
+
disc = S * (S + 2 * r3);
|
|
1931
|
+
u = r;
|
|
1932
|
+
if (disc >= 0) {
|
|
1933
|
+
T3 = S + r3;
|
|
1934
|
+
T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc);
|
|
1935
|
+
T = m.cbrt(T3);
|
|
1936
|
+
u += T + (T !== 0 ? r2 / T : 0);
|
|
1937
|
+
} else {
|
|
1938
|
+
ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
|
|
1939
|
+
u += 2 * r * Math.cos(ang / 3);
|
|
1940
|
+
}
|
|
1941
|
+
v = Math.sqrt(m.sq(u) + q);
|
|
1942
|
+
uv = u < 0 ? q / (v - u) : u + v;
|
|
1943
|
+
w = (uv - q) / (2 * v);
|
|
1944
|
+
k = uv / (Math.sqrt(uv + m.sq(w)) + w);
|
|
1945
|
+
} else {
|
|
1946
|
+
k = 0;
|
|
1947
|
+
}
|
|
1948
|
+
return k;
|
|
1949
|
+
};
|
|
1950
|
+
A1m1f_coeff = [
|
|
1951
|
+
// (1-eps)*A1-1, polynomial in eps2 of order 3
|
|
1952
|
+
1,
|
|
1953
|
+
4,
|
|
1954
|
+
64,
|
|
1955
|
+
0,
|
|
1956
|
+
256
|
|
1957
|
+
];
|
|
1958
|
+
g.A1m1f = function(eps) {
|
|
1959
|
+
var p2 = Math.floor(nA1_ / 2), t = m.polyval(p2, A1m1f_coeff, 0, m.sq(eps)) / A1m1f_coeff[p2 + 1];
|
|
1960
|
+
return (t + eps) / (1 - eps);
|
|
1961
|
+
};
|
|
1962
|
+
C1f_coeff = [
|
|
1963
|
+
// C1[1]/eps^1, polynomial in eps2 of order 2
|
|
1964
|
+
-1,
|
|
1965
|
+
6,
|
|
1966
|
+
-16,
|
|
1967
|
+
32,
|
|
1968
|
+
// C1[2]/eps^2, polynomial in eps2 of order 2
|
|
1969
|
+
-9,
|
|
1970
|
+
64,
|
|
1971
|
+
-128,
|
|
1972
|
+
2048,
|
|
1973
|
+
// C1[3]/eps^3, polynomial in eps2 of order 1
|
|
1974
|
+
9,
|
|
1975
|
+
-16,
|
|
1976
|
+
768,
|
|
1977
|
+
// C1[4]/eps^4, polynomial in eps2 of order 1
|
|
1978
|
+
3,
|
|
1979
|
+
-5,
|
|
1980
|
+
512,
|
|
1981
|
+
// C1[5]/eps^5, polynomial in eps2 of order 0
|
|
1982
|
+
-7,
|
|
1983
|
+
1280,
|
|
1984
|
+
// C1[6]/eps^6, polynomial in eps2 of order 0
|
|
1985
|
+
-7,
|
|
1986
|
+
2048
|
|
1987
|
+
];
|
|
1988
|
+
g.C1f = function(eps, c2) {
|
|
1989
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
1990
|
+
for (l2 = 1; l2 <= g.nC1_; ++l2) {
|
|
1991
|
+
p2 = Math.floor((g.nC1_ - l2) / 2);
|
|
1992
|
+
c2[l2] = d * m.polyval(p2, C1f_coeff, o, eps2) / C1f_coeff[o + p2 + 1];
|
|
1993
|
+
o += p2 + 2;
|
|
1994
|
+
d *= eps;
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
C1pf_coeff = [
|
|
1998
|
+
// C1p[1]/eps^1, polynomial in eps2 of order 2
|
|
1999
|
+
205,
|
|
2000
|
+
-432,
|
|
2001
|
+
768,
|
|
2002
|
+
1536,
|
|
2003
|
+
// C1p[2]/eps^2, polynomial in eps2 of order 2
|
|
2004
|
+
4005,
|
|
2005
|
+
-4736,
|
|
2006
|
+
3840,
|
|
2007
|
+
12288,
|
|
2008
|
+
// C1p[3]/eps^3, polynomial in eps2 of order 1
|
|
2009
|
+
-225,
|
|
2010
|
+
116,
|
|
2011
|
+
384,
|
|
2012
|
+
// C1p[4]/eps^4, polynomial in eps2 of order 1
|
|
2013
|
+
-7173,
|
|
2014
|
+
2695,
|
|
2015
|
+
7680,
|
|
2016
|
+
// C1p[5]/eps^5, polynomial in eps2 of order 0
|
|
2017
|
+
3467,
|
|
2018
|
+
7680,
|
|
2019
|
+
// C1p[6]/eps^6, polynomial in eps2 of order 0
|
|
2020
|
+
38081,
|
|
2021
|
+
61440
|
|
2022
|
+
];
|
|
2023
|
+
g.C1pf = function(eps, c2) {
|
|
2024
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
2025
|
+
for (l2 = 1; l2 <= g.nC1p_; ++l2) {
|
|
2026
|
+
p2 = Math.floor((g.nC1p_ - l2) / 2);
|
|
2027
|
+
c2[l2] = d * m.polyval(p2, C1pf_coeff, o, eps2) / C1pf_coeff[o + p2 + 1];
|
|
2028
|
+
o += p2 + 2;
|
|
2029
|
+
d *= eps;
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
A2m1f_coeff = [
|
|
2033
|
+
// (eps+1)*A2-1, polynomial in eps2 of order 3
|
|
2034
|
+
-11,
|
|
2035
|
+
-28,
|
|
2036
|
+
-192,
|
|
2037
|
+
0,
|
|
2038
|
+
256
|
|
2039
|
+
];
|
|
2040
|
+
g.A2m1f = function(eps) {
|
|
2041
|
+
var p2 = Math.floor(nA2_ / 2), t = m.polyval(p2, A2m1f_coeff, 0, m.sq(eps)) / A2m1f_coeff[p2 + 1];
|
|
2042
|
+
return (t - eps) / (1 + eps);
|
|
2043
|
+
};
|
|
2044
|
+
C2f_coeff = [
|
|
2045
|
+
// C2[1]/eps^1, polynomial in eps2 of order 2
|
|
2046
|
+
1,
|
|
2047
|
+
2,
|
|
2048
|
+
16,
|
|
2049
|
+
32,
|
|
2050
|
+
// C2[2]/eps^2, polynomial in eps2 of order 2
|
|
2051
|
+
35,
|
|
2052
|
+
64,
|
|
2053
|
+
384,
|
|
2054
|
+
2048,
|
|
2055
|
+
// C2[3]/eps^3, polynomial in eps2 of order 1
|
|
2056
|
+
15,
|
|
2057
|
+
80,
|
|
2058
|
+
768,
|
|
2059
|
+
// C2[4]/eps^4, polynomial in eps2 of order 1
|
|
2060
|
+
7,
|
|
2061
|
+
35,
|
|
2062
|
+
512,
|
|
2063
|
+
// C2[5]/eps^5, polynomial in eps2 of order 0
|
|
2064
|
+
63,
|
|
2065
|
+
1280,
|
|
2066
|
+
// C2[6]/eps^6, polynomial in eps2 of order 0
|
|
2067
|
+
77,
|
|
2068
|
+
2048
|
|
2069
|
+
];
|
|
2070
|
+
g.C2f = function(eps, c2) {
|
|
2071
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
2072
|
+
for (l2 = 1; l2 <= g.nC2_; ++l2) {
|
|
2073
|
+
p2 = Math.floor((g.nC2_ - l2) / 2);
|
|
2074
|
+
c2[l2] = d * m.polyval(p2, C2f_coeff, o, eps2) / C2f_coeff[o + p2 + 1];
|
|
2075
|
+
o += p2 + 2;
|
|
2076
|
+
d *= eps;
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
g.Geodesic = function(a, f) {
|
|
2080
|
+
this.a = a;
|
|
2081
|
+
this.f = f;
|
|
2082
|
+
this._f1 = 1 - this.f;
|
|
2083
|
+
this._e2 = this.f * (2 - this.f);
|
|
2084
|
+
this._ep2 = this._e2 / m.sq(this._f1);
|
|
2085
|
+
this._n = this.f / (2 - this.f);
|
|
2086
|
+
this._b = this.a * this._f1;
|
|
2087
|
+
this._c2 = (m.sq(this.a) + m.sq(this._b) * (this._e2 === 0 ? 1 : (this._e2 > 0 ? m.atanh(Math.sqrt(this._e2)) : Math.atan(Math.sqrt(-this._e2))) / Math.sqrt(Math.abs(this._e2)))) / 2;
|
|
2088
|
+
this._etol2 = 0.1 * tol2_ / Math.sqrt(Math.max(1e-3, Math.abs(this.f)) * Math.min(1, 1 - this.f / 2) / 2);
|
|
2089
|
+
if (!(isFinite(this.a) && this.a > 0))
|
|
2090
|
+
throw new Error("Equatorial radius is not positive");
|
|
2091
|
+
if (!(isFinite(this._b) && this._b > 0))
|
|
2092
|
+
throw new Error("Polar semi-axis is not positive");
|
|
2093
|
+
this._A3x = new Array(nA3x_);
|
|
2094
|
+
this._C3x = new Array(nC3x_);
|
|
2095
|
+
this._C4x = new Array(nC4x_);
|
|
2096
|
+
this.A3coeff();
|
|
2097
|
+
this.C3coeff();
|
|
2098
|
+
this.C4coeff();
|
|
2099
|
+
};
|
|
2100
|
+
A3_coeff = [
|
|
2101
|
+
// A3, coeff of eps^5, polynomial in n of order 0
|
|
2102
|
+
-3,
|
|
2103
|
+
128,
|
|
2104
|
+
// A3, coeff of eps^4, polynomial in n of order 1
|
|
2105
|
+
-2,
|
|
2106
|
+
-3,
|
|
2107
|
+
64,
|
|
2108
|
+
// A3, coeff of eps^3, polynomial in n of order 2
|
|
2109
|
+
-1,
|
|
2110
|
+
-3,
|
|
2111
|
+
-1,
|
|
2112
|
+
16,
|
|
2113
|
+
// A3, coeff of eps^2, polynomial in n of order 2
|
|
2114
|
+
3,
|
|
2115
|
+
-1,
|
|
2116
|
+
-2,
|
|
2117
|
+
8,
|
|
2118
|
+
// A3, coeff of eps^1, polynomial in n of order 1
|
|
2119
|
+
1,
|
|
2120
|
+
-1,
|
|
2121
|
+
2,
|
|
2122
|
+
// A3, coeff of eps^0, polynomial in n of order 0
|
|
2123
|
+
1,
|
|
2124
|
+
1
|
|
2125
|
+
];
|
|
2126
|
+
g.Geodesic.prototype.A3coeff = function() {
|
|
2127
|
+
var o = 0, k = 0, j, p2;
|
|
2128
|
+
for (j = nA3_ - 1; j >= 0; --j) {
|
|
2129
|
+
p2 = Math.min(nA3_ - j - 1, j);
|
|
2130
|
+
this._A3x[k++] = m.polyval(p2, A3_coeff, o, this._n) / A3_coeff[o + p2 + 1];
|
|
2131
|
+
o += p2 + 2;
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
C3_coeff = [
|
|
2135
|
+
// C3[1], coeff of eps^5, polynomial in n of order 0
|
|
2136
|
+
3,
|
|
2137
|
+
128,
|
|
2138
|
+
// C3[1], coeff of eps^4, polynomial in n of order 1
|
|
2139
|
+
2,
|
|
2140
|
+
5,
|
|
2141
|
+
128,
|
|
2142
|
+
// C3[1], coeff of eps^3, polynomial in n of order 2
|
|
2143
|
+
-1,
|
|
2144
|
+
3,
|
|
2145
|
+
3,
|
|
2146
|
+
64,
|
|
2147
|
+
// C3[1], coeff of eps^2, polynomial in n of order 2
|
|
2148
|
+
-1,
|
|
2149
|
+
0,
|
|
2150
|
+
1,
|
|
2151
|
+
8,
|
|
2152
|
+
// C3[1], coeff of eps^1, polynomial in n of order 1
|
|
2153
|
+
-1,
|
|
2154
|
+
1,
|
|
2155
|
+
4,
|
|
2156
|
+
// C3[2], coeff of eps^5, polynomial in n of order 0
|
|
2157
|
+
5,
|
|
2158
|
+
256,
|
|
2159
|
+
// C3[2], coeff of eps^4, polynomial in n of order 1
|
|
2160
|
+
1,
|
|
2161
|
+
3,
|
|
2162
|
+
128,
|
|
2163
|
+
// C3[2], coeff of eps^3, polynomial in n of order 2
|
|
2164
|
+
-3,
|
|
2165
|
+
-2,
|
|
2166
|
+
3,
|
|
2167
|
+
64,
|
|
2168
|
+
// C3[2], coeff of eps^2, polynomial in n of order 2
|
|
2169
|
+
1,
|
|
2170
|
+
-3,
|
|
2171
|
+
2,
|
|
2172
|
+
32,
|
|
2173
|
+
// C3[3], coeff of eps^5, polynomial in n of order 0
|
|
2174
|
+
7,
|
|
2175
|
+
512,
|
|
2176
|
+
// C3[3], coeff of eps^4, polynomial in n of order 1
|
|
2177
|
+
-10,
|
|
2178
|
+
9,
|
|
2179
|
+
384,
|
|
2180
|
+
// C3[3], coeff of eps^3, polynomial in n of order 2
|
|
2181
|
+
5,
|
|
2182
|
+
-9,
|
|
2183
|
+
5,
|
|
2184
|
+
192,
|
|
2185
|
+
// C3[4], coeff of eps^5, polynomial in n of order 0
|
|
2186
|
+
7,
|
|
2187
|
+
512,
|
|
2188
|
+
// C3[4], coeff of eps^4, polynomial in n of order 1
|
|
2189
|
+
-14,
|
|
2190
|
+
7,
|
|
2191
|
+
512,
|
|
2192
|
+
// C3[5], coeff of eps^5, polynomial in n of order 0
|
|
2193
|
+
21,
|
|
2194
|
+
2560
|
|
2195
|
+
];
|
|
2196
|
+
g.Geodesic.prototype.C3coeff = function() {
|
|
2197
|
+
var o = 0, k = 0, l2, j, p2;
|
|
2198
|
+
for (l2 = 1; l2 < g.nC3_; ++l2) {
|
|
2199
|
+
for (j = g.nC3_ - 1; j >= l2; --j) {
|
|
2200
|
+
p2 = Math.min(g.nC3_ - j - 1, j);
|
|
2201
|
+
this._C3x[k++] = m.polyval(p2, C3_coeff, o, this._n) / C3_coeff[o + p2 + 1];
|
|
2202
|
+
o += p2 + 2;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
};
|
|
2206
|
+
C4_coeff = [
|
|
2207
|
+
// C4[0], coeff of eps^5, polynomial in n of order 0
|
|
2208
|
+
97,
|
|
2209
|
+
15015,
|
|
2210
|
+
// C4[0], coeff of eps^4, polynomial in n of order 1
|
|
2211
|
+
1088,
|
|
2212
|
+
156,
|
|
2213
|
+
45045,
|
|
2214
|
+
// C4[0], coeff of eps^3, polynomial in n of order 2
|
|
2215
|
+
-224,
|
|
2216
|
+
-4784,
|
|
2217
|
+
1573,
|
|
2218
|
+
45045,
|
|
2219
|
+
// C4[0], coeff of eps^2, polynomial in n of order 3
|
|
2220
|
+
-10656,
|
|
2221
|
+
14144,
|
|
2222
|
+
-4576,
|
|
2223
|
+
-858,
|
|
2224
|
+
45045,
|
|
2225
|
+
// C4[0], coeff of eps^1, polynomial in n of order 4
|
|
2226
|
+
64,
|
|
2227
|
+
624,
|
|
2228
|
+
-4576,
|
|
2229
|
+
6864,
|
|
2230
|
+
-3003,
|
|
2231
|
+
15015,
|
|
2232
|
+
// C4[0], coeff of eps^0, polynomial in n of order 5
|
|
2233
|
+
100,
|
|
2234
|
+
208,
|
|
2235
|
+
572,
|
|
2236
|
+
3432,
|
|
2237
|
+
-12012,
|
|
2238
|
+
30030,
|
|
2239
|
+
45045,
|
|
2240
|
+
// C4[1], coeff of eps^5, polynomial in n of order 0
|
|
2241
|
+
1,
|
|
2242
|
+
9009,
|
|
2243
|
+
// C4[1], coeff of eps^4, polynomial in n of order 1
|
|
2244
|
+
-2944,
|
|
2245
|
+
468,
|
|
2246
|
+
135135,
|
|
2247
|
+
// C4[1], coeff of eps^3, polynomial in n of order 2
|
|
2248
|
+
5792,
|
|
2249
|
+
1040,
|
|
2250
|
+
-1287,
|
|
2251
|
+
135135,
|
|
2252
|
+
// C4[1], coeff of eps^2, polynomial in n of order 3
|
|
2253
|
+
5952,
|
|
2254
|
+
-11648,
|
|
2255
|
+
9152,
|
|
2256
|
+
-2574,
|
|
2257
|
+
135135,
|
|
2258
|
+
// C4[1], coeff of eps^1, polynomial in n of order 4
|
|
2259
|
+
-64,
|
|
2260
|
+
-624,
|
|
2261
|
+
4576,
|
|
2262
|
+
-6864,
|
|
2263
|
+
3003,
|
|
2264
|
+
135135,
|
|
2265
|
+
// C4[2], coeff of eps^5, polynomial in n of order 0
|
|
2266
|
+
8,
|
|
2267
|
+
10725,
|
|
2268
|
+
// C4[2], coeff of eps^4, polynomial in n of order 1
|
|
2269
|
+
1856,
|
|
2270
|
+
-936,
|
|
2271
|
+
225225,
|
|
2272
|
+
// C4[2], coeff of eps^3, polynomial in n of order 2
|
|
2273
|
+
-8448,
|
|
2274
|
+
4992,
|
|
2275
|
+
-1144,
|
|
2276
|
+
225225,
|
|
2277
|
+
// C4[2], coeff of eps^2, polynomial in n of order 3
|
|
2278
|
+
-1440,
|
|
2279
|
+
4160,
|
|
2280
|
+
-4576,
|
|
2281
|
+
1716,
|
|
2282
|
+
225225,
|
|
2283
|
+
// C4[3], coeff of eps^5, polynomial in n of order 0
|
|
2284
|
+
-136,
|
|
2285
|
+
63063,
|
|
2286
|
+
// C4[3], coeff of eps^4, polynomial in n of order 1
|
|
2287
|
+
1024,
|
|
2288
|
+
-208,
|
|
2289
|
+
105105,
|
|
2290
|
+
// C4[3], coeff of eps^3, polynomial in n of order 2
|
|
2291
|
+
3584,
|
|
2292
|
+
-3328,
|
|
2293
|
+
1144,
|
|
2294
|
+
315315,
|
|
2295
|
+
// C4[4], coeff of eps^5, polynomial in n of order 0
|
|
2296
|
+
-128,
|
|
2297
|
+
135135,
|
|
2298
|
+
// C4[4], coeff of eps^4, polynomial in n of order 1
|
|
2299
|
+
-2560,
|
|
2300
|
+
832,
|
|
2301
|
+
405405,
|
|
2302
|
+
// C4[5], coeff of eps^5, polynomial in n of order 0
|
|
2303
|
+
128,
|
|
2304
|
+
99099
|
|
2305
|
+
];
|
|
2306
|
+
g.Geodesic.prototype.C4coeff = function() {
|
|
2307
|
+
var o = 0, k = 0, l2, j, p2;
|
|
2308
|
+
for (l2 = 0; l2 < g.nC4_; ++l2) {
|
|
2309
|
+
for (j = g.nC4_ - 1; j >= l2; --j) {
|
|
2310
|
+
p2 = g.nC4_ - j - 1;
|
|
2311
|
+
this._C4x[k++] = m.polyval(p2, C4_coeff, o, this._n) / C4_coeff[o + p2 + 1];
|
|
2312
|
+
o += p2 + 2;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
g.Geodesic.prototype.A3f = function(eps) {
|
|
2317
|
+
return m.polyval(nA3x_ - 1, this._A3x, 0, eps);
|
|
2318
|
+
};
|
|
2319
|
+
g.Geodesic.prototype.C3f = function(eps, c2) {
|
|
2320
|
+
var mult = 1, o = 0, l2, p2;
|
|
2321
|
+
for (l2 = 1; l2 < g.nC3_; ++l2) {
|
|
2322
|
+
p2 = g.nC3_ - l2 - 1;
|
|
2323
|
+
mult *= eps;
|
|
2324
|
+
c2[l2] = mult * m.polyval(p2, this._C3x, o, eps);
|
|
2325
|
+
o += p2 + 1;
|
|
2326
|
+
}
|
|
2327
|
+
};
|
|
2328
|
+
g.Geodesic.prototype.C4f = function(eps, c2) {
|
|
2329
|
+
var mult = 1, o = 0, l2, p2;
|
|
2330
|
+
for (l2 = 0; l2 < g.nC4_; ++l2) {
|
|
2331
|
+
p2 = g.nC4_ - l2 - 1;
|
|
2332
|
+
c2[l2] = mult * m.polyval(p2, this._C4x, o, eps);
|
|
2333
|
+
o += p2 + 1;
|
|
2334
|
+
mult *= eps;
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
g.Geodesic.prototype.Lengths = function(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask, C1a, C2a) {
|
|
2338
|
+
outmask &= g.OUT_MASK;
|
|
2339
|
+
var vals = {}, m0x = 0, J12 = 0, A1 = 0, A2 = 0, B1, B2, l2, csig12, t;
|
|
2340
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2341
|
+
A1 = g.A1m1f(eps);
|
|
2342
|
+
g.C1f(eps, C1a);
|
|
2343
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2344
|
+
A2 = g.A2m1f(eps);
|
|
2345
|
+
g.C2f(eps, C2a);
|
|
2346
|
+
m0x = A1 - A2;
|
|
2347
|
+
A2 = 1 + A2;
|
|
2348
|
+
}
|
|
2349
|
+
A1 = 1 + A1;
|
|
2350
|
+
}
|
|
2351
|
+
if (outmask & g.DISTANCE) {
|
|
2352
|
+
B1 = g.SinCosSeries(true, ssig2, csig2, C1a) - g.SinCosSeries(true, ssig1, csig1, C1a);
|
|
2353
|
+
vals.s12b = A1 * (sig12 + B1);
|
|
2354
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2355
|
+
B2 = g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a);
|
|
2356
|
+
J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
|
|
2357
|
+
}
|
|
2358
|
+
} else if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2359
|
+
for (l2 = 1; l2 <= g.nC2_; ++l2)
|
|
2360
|
+
C2a[l2] = A1 * C1a[l2] - A2 * C2a[l2];
|
|
2361
|
+
J12 = m0x * sig12 + (g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a));
|
|
2362
|
+
}
|
|
2363
|
+
if (outmask & g.REDUCEDLENGTH) {
|
|
2364
|
+
vals.m0 = m0x;
|
|
2365
|
+
vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12;
|
|
2366
|
+
} else
|
|
2367
|
+
vals.m12b = NaN;
|
|
2368
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2369
|
+
csig12 = csig1 * csig2 + ssig1 * ssig2;
|
|
2370
|
+
t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
|
|
2371
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
|
|
2372
|
+
vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
|
|
2373
|
+
}
|
|
2374
|
+
return vals;
|
|
2375
|
+
};
|
|
2376
|
+
g.Geodesic.prototype.InverseStart = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a) {
|
|
2377
|
+
var vals = {}, sbet12 = sbet2 * cbet1 - cbet2 * sbet1, cbet12 = cbet2 * cbet1 + sbet2 * sbet1, sbet12a, shortline, omg12, sbetm2, somg12, comg12, t, ssig12, csig12, x, y, lamscale, betscale, k2, eps, cbet12a, bet12a, m12b, m0, nvals, k, omg12a, lam12x;
|
|
2378
|
+
vals.sig12 = -1;
|
|
2379
|
+
sbet12a = sbet2 * cbet1;
|
|
2380
|
+
sbet12a += cbet2 * sbet1;
|
|
2381
|
+
shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
|
|
2382
|
+
if (shortline) {
|
|
2383
|
+
sbetm2 = m.sq(sbet1 + sbet2);
|
|
2384
|
+
sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
|
|
2385
|
+
vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
|
|
2386
|
+
omg12 = lam12 / (this._f1 * vals.dnm);
|
|
2387
|
+
somg12 = Math.sin(omg12);
|
|
2388
|
+
comg12 = Math.cos(omg12);
|
|
2389
|
+
} else {
|
|
2390
|
+
somg12 = slam12;
|
|
2391
|
+
comg12 = clam12;
|
|
2392
|
+
}
|
|
2393
|
+
vals.salp1 = cbet2 * somg12;
|
|
2394
|
+
vals.calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * m.sq(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
|
2395
|
+
ssig12 = m.hypot(vals.salp1, vals.calp1);
|
|
2396
|
+
csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
|
|
2397
|
+
if (shortline && ssig12 < this._etol2) {
|
|
2398
|
+
vals.salp2 = cbet1 * somg12;
|
|
2399
|
+
vals.calp2 = sbet12 - cbet1 * sbet2 * (comg12 >= 0 ? m.sq(somg12) / (1 + comg12) : 1 - comg12);
|
|
2400
|
+
t = m.hypot(vals.salp2, vals.calp2);
|
|
2401
|
+
vals.salp2 /= t;
|
|
2402
|
+
vals.calp2 /= t;
|
|
2403
|
+
vals.sig12 = Math.atan2(ssig12, csig12);
|
|
2404
|
+
} else if (Math.abs(this._n) > 0.1 || // Skip astroid calc if too eccentric
|
|
2405
|
+
csig12 >= 0 || ssig12 >= 6 * Math.abs(this._n) * Math.PI * m.sq(cbet1)) {
|
|
2406
|
+
} else {
|
|
2407
|
+
lam12x = Math.atan2(-slam12, -clam12);
|
|
2408
|
+
if (this.f >= 0) {
|
|
2409
|
+
k2 = m.sq(sbet1) * this._ep2;
|
|
2410
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2411
|
+
lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
|
|
2412
|
+
betscale = lamscale * cbet1;
|
|
2413
|
+
x = lam12x / lamscale;
|
|
2414
|
+
y = sbet12a / betscale;
|
|
2415
|
+
} else {
|
|
2416
|
+
cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
|
|
2417
|
+
bet12a = Math.atan2(sbet12a, cbet12a);
|
|
2418
|
+
nvals = this.Lengths(this._n, Math.PI + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
|
2419
|
+
m12b = nvals.m12b;
|
|
2420
|
+
m0 = nvals.m0;
|
|
2421
|
+
x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
|
|
2422
|
+
betscale = x < -0.01 ? sbet12a / x : -this.f * m.sq(cbet1) * Math.PI;
|
|
2423
|
+
lamscale = betscale / cbet1;
|
|
2424
|
+
y = lam12 / lamscale;
|
|
2425
|
+
}
|
|
2426
|
+
if (y > -tol1_ && x > -1 - xthresh_) {
|
|
2427
|
+
if (this.f >= 0) {
|
|
2428
|
+
vals.salp1 = Math.min(1, -x);
|
|
2429
|
+
vals.calp1 = -Math.sqrt(1 - m.sq(vals.salp1));
|
|
2430
|
+
} else {
|
|
2431
|
+
vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
|
|
2432
|
+
vals.salp1 = Math.sqrt(1 - m.sq(vals.calp1));
|
|
2433
|
+
}
|
|
2434
|
+
} else {
|
|
2435
|
+
k = astroid(x, y);
|
|
2436
|
+
omg12a = lamscale * (this.f >= 0 ? -x * k / (1 + k) : -y * (1 + k) / k);
|
|
2437
|
+
somg12 = Math.sin(omg12a);
|
|
2438
|
+
comg12 = -Math.cos(omg12a);
|
|
2439
|
+
vals.salp1 = cbet2 * somg12;
|
|
2440
|
+
vals.calp1 = sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
if (!(vals.salp1 <= 0)) {
|
|
2444
|
+
t = m.hypot(vals.salp1, vals.calp1);
|
|
2445
|
+
vals.salp1 /= t;
|
|
2446
|
+
vals.calp1 /= t;
|
|
2447
|
+
} else {
|
|
2448
|
+
vals.salp1 = 1;
|
|
2449
|
+
vals.calp1 = 0;
|
|
2450
|
+
}
|
|
2451
|
+
return vals;
|
|
2452
|
+
};
|
|
2453
|
+
g.Geodesic.prototype.Lambda12 = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam120, clam120, diffp, C1a, C2a, C3a) {
|
|
2454
|
+
var vals = {}, t, salp0, calp0, somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
|
|
2455
|
+
if (sbet1 === 0 && calp1 === 0)
|
|
2456
|
+
calp1 = -g.tiny_;
|
|
2457
|
+
salp0 = salp1 * cbet1;
|
|
2458
|
+
calp0 = m.hypot(calp1, salp1 * sbet1);
|
|
2459
|
+
vals.ssig1 = sbet1;
|
|
2460
|
+
somg1 = salp0 * sbet1;
|
|
2461
|
+
vals.csig1 = comg1 = calp1 * cbet1;
|
|
2462
|
+
t = m.hypot(vals.ssig1, vals.csig1);
|
|
2463
|
+
vals.ssig1 /= t;
|
|
2464
|
+
vals.csig1 /= t;
|
|
2465
|
+
vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
|
|
2466
|
+
vals.calp2 = cbet2 !== cbet1 || Math.abs(sbet2) !== -sbet1 ? Math.sqrt(m.sq(calp1 * cbet1) + (cbet1 < -sbet1 ? (cbet2 - cbet1) * (cbet1 + cbet2) : (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2 : Math.abs(calp1);
|
|
2467
|
+
vals.ssig2 = sbet2;
|
|
2468
|
+
somg2 = salp0 * sbet2;
|
|
2469
|
+
vals.csig2 = comg2 = vals.calp2 * cbet2;
|
|
2470
|
+
t = m.hypot(vals.ssig2, vals.csig2);
|
|
2471
|
+
vals.ssig2 /= t;
|
|
2472
|
+
vals.csig2 /= t;
|
|
2473
|
+
vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 - vals.ssig1 * vals.csig2), vals.csig1 * vals.csig2 + vals.ssig1 * vals.ssig2);
|
|
2474
|
+
somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
|
|
2475
|
+
comg12 = comg1 * comg2 + somg1 * somg2;
|
|
2476
|
+
eta = Math.atan2(somg12 * clam120 - comg12 * slam120, comg12 * clam120 + somg12 * slam120);
|
|
2477
|
+
k2 = m.sq(calp0) * this._ep2;
|
|
2478
|
+
vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2479
|
+
this.C3f(vals.eps, C3a);
|
|
2480
|
+
B312 = g.SinCosSeries(true, vals.ssig2, vals.csig2, C3a) - g.SinCosSeries(true, vals.ssig1, vals.csig1, C3a);
|
|
2481
|
+
vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
|
|
2482
|
+
vals.lam12 = eta + vals.domg12;
|
|
2483
|
+
if (diffp) {
|
|
2484
|
+
if (vals.calp2 === 0)
|
|
2485
|
+
vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
|
|
2486
|
+
else {
|
|
2487
|
+
nvals = this.Lengths(vals.eps, vals.sig12, vals.ssig1, vals.csig1, dn1, vals.ssig2, vals.csig2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
|
2488
|
+
vals.dlam12 = nvals.m12b;
|
|
2489
|
+
vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
return vals;
|
|
2493
|
+
};
|
|
2494
|
+
g.Geodesic.prototype.Inverse = function(lat1, lon1, lat2, lon2, outmask) {
|
|
2495
|
+
var r, vals;
|
|
2496
|
+
if (!outmask)
|
|
2497
|
+
outmask = g.STANDARD;
|
|
2498
|
+
if (outmask === g.LONG_UNROLL)
|
|
2499
|
+
outmask |= g.STANDARD;
|
|
2500
|
+
outmask &= g.OUT_MASK;
|
|
2501
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
|
|
2502
|
+
vals = r.vals;
|
|
2503
|
+
if (outmask & g.AZIMUTH) {
|
|
2504
|
+
vals.azi1 = m.atan2d(r.salp1, r.calp1);
|
|
2505
|
+
vals.azi2 = m.atan2d(r.salp2, r.calp2);
|
|
2506
|
+
}
|
|
2507
|
+
return vals;
|
|
2508
|
+
};
|
|
2509
|
+
g.Geodesic.prototype.InverseInt = function(lat1, lon1, lat2, lon2, outmask) {
|
|
2510
|
+
var vals = {}, lon12, lon12s, lonsign, t, swapp, latsign, sbet1, cbet1, sbet2, cbet2, s12x, m12x, dn1, dn2, lam12, slam12, clam12, sig12, calp1, salp1, calp2, salp2, C1a, C2a, C3a, meridian, nvals, ssig1, csig1, ssig2, csig2, eps, omg12, dnm, numit, salp1a, calp1a, salp1b, calp1b, tripn, tripb, v, dv, dalp1, sdalp1, cdalp1, nsalp1, lengthmask, salp0, calp0, alp12, k2, A4, C4a, B41, B42, somg12, comg12, domg12, dbet1, dbet2, salp12, calp12, sdomg12, cdomg12;
|
|
2511
|
+
vals.lat1 = lat1 = m.LatFix(lat1);
|
|
2512
|
+
vals.lat2 = lat2 = m.LatFix(lat2);
|
|
2513
|
+
lat1 = m.AngRound(lat1);
|
|
2514
|
+
lat2 = m.AngRound(lat2);
|
|
2515
|
+
lon12 = m.AngDiff(lon1, lon2);
|
|
2516
|
+
lon12s = lon12.e;
|
|
2517
|
+
lon12 = lon12.d;
|
|
2518
|
+
if (outmask & g.LONG_UNROLL) {
|
|
2519
|
+
vals.lon1 = lon1;
|
|
2520
|
+
vals.lon2 = lon1 + lon12 + lon12s;
|
|
2521
|
+
} else {
|
|
2522
|
+
vals.lon1 = m.AngNormalize(lon1);
|
|
2523
|
+
vals.lon2 = m.AngNormalize(lon2);
|
|
2524
|
+
}
|
|
2525
|
+
lonsign = m.copysign(1, lon12);
|
|
2526
|
+
lon12 *= lonsign;
|
|
2527
|
+
lon12s *= lonsign;
|
|
2528
|
+
lam12 = lon12 * m.degree;
|
|
2529
|
+
t = m.sincosde(lon12, lon12s);
|
|
2530
|
+
slam12 = t.s;
|
|
2531
|
+
clam12 = t.c;
|
|
2532
|
+
lon12s = 180 - lon12 - lon12s;
|
|
2533
|
+
swapp = Math.abs(lat1) < Math.abs(lat2) || isNaN(lat2) ? -1 : 1;
|
|
2534
|
+
if (swapp < 0) {
|
|
2535
|
+
lonsign *= -1;
|
|
2536
|
+
[lat2, lat1] = [lat1, lat2];
|
|
2537
|
+
}
|
|
2538
|
+
latsign = m.copysign(1, -lat1);
|
|
2539
|
+
lat1 *= latsign;
|
|
2540
|
+
lat2 *= latsign;
|
|
2541
|
+
t = m.sincosd(lat1);
|
|
2542
|
+
sbet1 = this._f1 * t.s;
|
|
2543
|
+
cbet1 = t.c;
|
|
2544
|
+
t = m.hypot(sbet1, cbet1);
|
|
2545
|
+
sbet1 /= t;
|
|
2546
|
+
cbet1 /= t;
|
|
2547
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
|
2548
|
+
t = m.sincosd(lat2);
|
|
2549
|
+
sbet2 = this._f1 * t.s;
|
|
2550
|
+
cbet2 = t.c;
|
|
2551
|
+
t = m.hypot(sbet2, cbet2);
|
|
2552
|
+
sbet2 /= t;
|
|
2553
|
+
cbet2 /= t;
|
|
2554
|
+
cbet2 = Math.max(g.tiny_, cbet2);
|
|
2555
|
+
if (cbet1 < -sbet1) {
|
|
2556
|
+
if (cbet2 === cbet1)
|
|
2557
|
+
sbet2 = m.copysign(sbet1, sbet2);
|
|
2558
|
+
} else {
|
|
2559
|
+
if (Math.abs(sbet2) === -sbet1)
|
|
2560
|
+
cbet2 = cbet1;
|
|
2561
|
+
}
|
|
2562
|
+
dn1 = Math.sqrt(1 + this._ep2 * m.sq(sbet1));
|
|
2563
|
+
dn2 = Math.sqrt(1 + this._ep2 * m.sq(sbet2));
|
|
2564
|
+
C1a = new Array(g.nC1_ + 1);
|
|
2565
|
+
C2a = new Array(g.nC2_ + 1);
|
|
2566
|
+
C3a = new Array(g.nC3_);
|
|
2567
|
+
meridian = lat1 === -90 || slam12 === 0;
|
|
2568
|
+
if (meridian) {
|
|
2569
|
+
calp1 = clam12;
|
|
2570
|
+
salp1 = slam12;
|
|
2571
|
+
calp2 = 1;
|
|
2572
|
+
salp2 = 0;
|
|
2573
|
+
ssig1 = sbet1;
|
|
2574
|
+
csig1 = calp1 * cbet1;
|
|
2575
|
+
ssig2 = sbet2;
|
|
2576
|
+
csig2 = calp2 * cbet2;
|
|
2577
|
+
sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2), csig1 * csig2 + ssig1 * ssig2);
|
|
2578
|
+
nvals = this.Lengths(this._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask | g.DISTANCE | g.REDUCEDLENGTH, C1a, C2a);
|
|
2579
|
+
s12x = nvals.s12b;
|
|
2580
|
+
m12x = nvals.m12b;
|
|
2581
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2582
|
+
vals.M12 = nvals.M12;
|
|
2583
|
+
vals.M21 = nvals.M21;
|
|
2584
|
+
}
|
|
2585
|
+
if (sig12 < tol2_ || m12x >= 0) {
|
|
2586
|
+
if (sig12 < 3 * g.tiny_ || // Prevent negative s12 or m12 for short lines
|
|
2587
|
+
sig12 < tol0_ && (s12x < 0 || m12x < 0))
|
|
2588
|
+
sig12 = m12x = s12x = 0;
|
|
2589
|
+
m12x *= this._b;
|
|
2590
|
+
s12x *= this._b;
|
|
2591
|
+
vals.a12 = sig12 / m.degree;
|
|
2592
|
+
} else
|
|
2593
|
+
meridian = false;
|
|
2594
|
+
}
|
|
2595
|
+
somg12 = 2;
|
|
2596
|
+
if (!meridian && sbet1 === 0 && // and sbet2 == 0
|
|
2597
|
+
(this.f <= 0 || lon12s >= this.f * 180)) {
|
|
2598
|
+
calp1 = calp2 = 0;
|
|
2599
|
+
salp1 = salp2 = 1;
|
|
2600
|
+
s12x = this.a * lam12;
|
|
2601
|
+
sig12 = omg12 = lam12 / this._f1;
|
|
2602
|
+
m12x = this._b * Math.sin(sig12);
|
|
2603
|
+
if (outmask & g.GEODESICSCALE)
|
|
2604
|
+
vals.M12 = vals.M21 = Math.cos(sig12);
|
|
2605
|
+
vals.a12 = lon12 / this._f1;
|
|
2606
|
+
} else if (!meridian) {
|
|
2607
|
+
nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a);
|
|
2608
|
+
sig12 = nvals.sig12;
|
|
2609
|
+
salp1 = nvals.salp1;
|
|
2610
|
+
calp1 = nvals.calp1;
|
|
2611
|
+
if (sig12 >= 0) {
|
|
2612
|
+
salp2 = nvals.salp2;
|
|
2613
|
+
calp2 = nvals.calp2;
|
|
2614
|
+
dnm = nvals.dnm;
|
|
2615
|
+
s12x = sig12 * this._b * dnm;
|
|
2616
|
+
m12x = m.sq(dnm) * this._b * Math.sin(sig12 / dnm);
|
|
2617
|
+
if (outmask & g.GEODESICSCALE)
|
|
2618
|
+
vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
|
|
2619
|
+
vals.a12 = sig12 / m.degree;
|
|
2620
|
+
omg12 = lam12 / (this._f1 * dnm);
|
|
2621
|
+
} else {
|
|
2622
|
+
numit = 0;
|
|
2623
|
+
salp1a = g.tiny_;
|
|
2624
|
+
calp1a = 1;
|
|
2625
|
+
salp1b = g.tiny_;
|
|
2626
|
+
calp1b = -1;
|
|
2627
|
+
for (tripn = false, tripb = false; ; ++numit) {
|
|
2628
|
+
nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
|
|
2629
|
+
v = nvals.lam12;
|
|
2630
|
+
salp2 = nvals.salp2;
|
|
2631
|
+
calp2 = nvals.calp2;
|
|
2632
|
+
sig12 = nvals.sig12;
|
|
2633
|
+
ssig1 = nvals.ssig1;
|
|
2634
|
+
csig1 = nvals.csig1;
|
|
2635
|
+
ssig2 = nvals.ssig2;
|
|
2636
|
+
csig2 = nvals.csig2;
|
|
2637
|
+
eps = nvals.eps;
|
|
2638
|
+
domg12 = nvals.domg12;
|
|
2639
|
+
dv = nvals.dlam12;
|
|
2640
|
+
if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_)
|
|
2641
|
+
break;
|
|
2642
|
+
if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
|
|
2643
|
+
salp1b = salp1;
|
|
2644
|
+
calp1b = calp1;
|
|
2645
|
+
} else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
|
|
2646
|
+
salp1a = salp1;
|
|
2647
|
+
calp1a = calp1;
|
|
2648
|
+
}
|
|
2649
|
+
if (numit < maxit1_ && dv > 0) {
|
|
2650
|
+
dalp1 = -v / dv;
|
|
2651
|
+
if (Math.abs(dalp1) < Math.PI) {
|
|
2652
|
+
sdalp1 = Math.sin(dalp1);
|
|
2653
|
+
cdalp1 = Math.cos(dalp1);
|
|
2654
|
+
nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
|
|
2655
|
+
if (nsalp1 > 0) {
|
|
2656
|
+
calp1 = calp1 * cdalp1 - salp1 * sdalp1;
|
|
2657
|
+
salp1 = nsalp1;
|
|
2658
|
+
t = m.hypot(salp1, calp1);
|
|
2659
|
+
salp1 /= t;
|
|
2660
|
+
calp1 /= t;
|
|
2661
|
+
tripn = Math.abs(v) <= 16 * tol0_;
|
|
2662
|
+
continue;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
salp1 = (salp1a + salp1b) / 2;
|
|
2667
|
+
calp1 = (calp1a + calp1b) / 2;
|
|
2668
|
+
t = m.hypot(salp1, calp1);
|
|
2669
|
+
salp1 /= t;
|
|
2670
|
+
calp1 /= t;
|
|
2671
|
+
tripn = false;
|
|
2672
|
+
tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
|
|
2673
|
+
}
|
|
2674
|
+
lengthmask = outmask | (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ? g.DISTANCE : g.NONE);
|
|
2675
|
+
nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
|
|
2676
|
+
s12x = nvals.s12b;
|
|
2677
|
+
m12x = nvals.m12b;
|
|
2678
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2679
|
+
vals.M12 = nvals.M12;
|
|
2680
|
+
vals.M21 = nvals.M21;
|
|
2681
|
+
}
|
|
2682
|
+
m12x *= this._b;
|
|
2683
|
+
s12x *= this._b;
|
|
2684
|
+
vals.a12 = sig12 / m.degree;
|
|
2685
|
+
if (outmask & g.AREA) {
|
|
2686
|
+
sdomg12 = Math.sin(domg12);
|
|
2687
|
+
cdomg12 = Math.cos(domg12);
|
|
2688
|
+
somg12 = slam12 * cdomg12 - clam12 * sdomg12;
|
|
2689
|
+
comg12 = clam12 * cdomg12 + slam12 * sdomg12;
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
if (outmask & g.DISTANCE)
|
|
2694
|
+
vals.s12 = 0 + s12x;
|
|
2695
|
+
if (outmask & g.REDUCEDLENGTH)
|
|
2696
|
+
vals.m12 = 0 + m12x;
|
|
2697
|
+
if (outmask & g.AREA) {
|
|
2698
|
+
salp0 = salp1 * cbet1;
|
|
2699
|
+
calp0 = m.hypot(calp1, salp1 * sbet1);
|
|
2700
|
+
if (calp0 !== 0 && salp0 !== 0) {
|
|
2701
|
+
ssig1 = sbet1;
|
|
2702
|
+
csig1 = calp1 * cbet1;
|
|
2703
|
+
ssig2 = sbet2;
|
|
2704
|
+
csig2 = calp2 * cbet2;
|
|
2705
|
+
k2 = m.sq(calp0) * this._ep2;
|
|
2706
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2707
|
+
A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
|
|
2708
|
+
t = m.hypot(ssig1, csig1);
|
|
2709
|
+
ssig1 /= t;
|
|
2710
|
+
csig1 /= t;
|
|
2711
|
+
t = m.hypot(ssig2, csig2);
|
|
2712
|
+
ssig2 /= t;
|
|
2713
|
+
csig2 /= t;
|
|
2714
|
+
C4a = new Array(g.nC4_);
|
|
2715
|
+
this.C4f(eps, C4a);
|
|
2716
|
+
B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
|
|
2717
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
|
|
2718
|
+
vals.S12 = A4 * (sig12 < 0.01 ? g.SinCosSeries(false, ssig1, csig1, C4a, sig12) : B42 - B41);
|
|
2719
|
+
} else
|
|
2720
|
+
vals.S12 = 0;
|
|
2721
|
+
if (!meridian && somg12 == 2) {
|
|
2722
|
+
somg12 = Math.sin(omg12);
|
|
2723
|
+
comg12 = Math.cos(omg12);
|
|
2724
|
+
}
|
|
2725
|
+
if (!meridian && comg12 > -0.7071 && // Long difference not too big
|
|
2726
|
+
sbet2 - sbet1 < 1.75) {
|
|
2727
|
+
domg12 = 1 + comg12;
|
|
2728
|
+
dbet1 = 1 + cbet1;
|
|
2729
|
+
dbet2 = 1 + cbet2;
|
|
2730
|
+
alp12 = 2 * Math.atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1), domg12 * (sbet1 * sbet2 + dbet1 * dbet2));
|
|
2731
|
+
} else {
|
|
2732
|
+
salp12 = salp2 * calp1 - calp2 * salp1;
|
|
2733
|
+
calp12 = calp2 * calp1 + salp2 * salp1;
|
|
2734
|
+
if (salp12 === 0 && calp12 < 0) {
|
|
2735
|
+
salp12 = g.tiny_ * calp1;
|
|
2736
|
+
calp12 = -1;
|
|
2737
|
+
}
|
|
2738
|
+
alp12 = Math.atan2(salp12, calp12);
|
|
2739
|
+
}
|
|
2740
|
+
vals.S12 += this._c2 * alp12;
|
|
2741
|
+
vals.S12 *= swapp * lonsign * latsign;
|
|
2742
|
+
vals.S12 += 0;
|
|
2743
|
+
}
|
|
2744
|
+
if (swapp < 0) {
|
|
2745
|
+
[salp2, salp1] = [salp1, salp2];
|
|
2746
|
+
[calp2, calp1] = [calp1, calp2];
|
|
2747
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2748
|
+
[vals.M21, vals.M12] = [vals.M12, vals.M21];
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
salp1 *= swapp * lonsign;
|
|
2752
|
+
calp1 *= swapp * latsign;
|
|
2753
|
+
salp2 *= swapp * lonsign;
|
|
2754
|
+
calp2 *= swapp * latsign;
|
|
2755
|
+
return {
|
|
2756
|
+
vals,
|
|
2757
|
+
salp1,
|
|
2758
|
+
calp1,
|
|
2759
|
+
salp2,
|
|
2760
|
+
calp2
|
|
2761
|
+
};
|
|
2762
|
+
};
|
|
2763
|
+
g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1, arcmode, s12_a12, outmask) {
|
|
2764
|
+
var line;
|
|
2765
|
+
if (!outmask)
|
|
2766
|
+
outmask = g.STANDARD;
|
|
2767
|
+
else if (outmask === g.LONG_UNROLL)
|
|
2768
|
+
outmask |= g.STANDARD;
|
|
2769
|
+
if (!arcmode)
|
|
2770
|
+
outmask |= g.DISTANCE_IN;
|
|
2771
|
+
line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
|
|
2772
|
+
return line.GenPosition(arcmode, s12_a12, outmask);
|
|
2773
|
+
};
|
|
2774
|
+
g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
|
|
2775
|
+
return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
|
|
2776
|
+
};
|
|
2777
|
+
g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
|
|
2778
|
+
return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
|
|
2779
|
+
};
|
|
2780
|
+
g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
|
|
2781
|
+
return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
2782
|
+
};
|
|
2783
|
+
g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
|
|
2784
|
+
return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
|
|
2785
|
+
};
|
|
2786
|
+
g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
|
|
2787
|
+
return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
|
|
2788
|
+
};
|
|
2789
|
+
g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1, arcmode, s12_a12, caps) {
|
|
2790
|
+
var t;
|
|
2791
|
+
if (!caps)
|
|
2792
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2793
|
+
if (!arcmode)
|
|
2794
|
+
caps |= g.DISTANCE_IN;
|
|
2795
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
2796
|
+
t.GenSetDistance(arcmode, s12_a12);
|
|
2797
|
+
return t;
|
|
2798
|
+
};
|
|
2799
|
+
g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
|
|
2800
|
+
var r, t, azi1;
|
|
2801
|
+
if (!caps)
|
|
2802
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2803
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
|
|
2804
|
+
azi1 = m.atan2d(r.salp1, r.calp1);
|
|
2805
|
+
if (caps & (g.OUT_MASK & g.DISTANCE_IN))
|
|
2806
|
+
caps |= g.DISTANCE;
|
|
2807
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
|
|
2808
|
+
t.SetArc(r.vals.a12);
|
|
2809
|
+
return t;
|
|
2810
|
+
};
|
|
2811
|
+
g.Geodesic.prototype.Polygon = function(polyline) {
|
|
2812
|
+
return new p.PolygonArea(this, polyline);
|
|
2813
|
+
};
|
|
2814
|
+
g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
|
|
2815
|
+
})(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.PolygonArea, geodesic.Math, geodesic.Constants);
|
|
2816
|
+
(function(g, l, m) {
|
|
2817
|
+
"use strict";
|
|
2818
|
+
l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
|
|
2819
|
+
var t, cbet1, sbet1, eps, s, c;
|
|
2820
|
+
if (!caps)
|
|
2821
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2822
|
+
this.a = geod.a;
|
|
2823
|
+
this.f = geod.f;
|
|
2824
|
+
this._b = geod._b;
|
|
2825
|
+
this._c2 = geod._c2;
|
|
2826
|
+
this._f1 = geod._f1;
|
|
2827
|
+
this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
|
|
2828
|
+
this.lat1 = m.LatFix(lat1);
|
|
2829
|
+
this.lon1 = lon1;
|
|
2830
|
+
if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
|
|
2831
|
+
this.azi1 = m.AngNormalize(azi1);
|
|
2832
|
+
t = m.sincosd(m.AngRound(this.azi1));
|
|
2833
|
+
this.salp1 = t.s;
|
|
2834
|
+
this.calp1 = t.c;
|
|
2835
|
+
} else {
|
|
2836
|
+
this.azi1 = azi1;
|
|
2837
|
+
this.salp1 = salp1;
|
|
2838
|
+
this.calp1 = calp1;
|
|
2839
|
+
}
|
|
2840
|
+
t = m.sincosd(m.AngRound(this.lat1));
|
|
2841
|
+
sbet1 = this._f1 * t.s;
|
|
2842
|
+
cbet1 = t.c;
|
|
2843
|
+
t = m.hypot(sbet1, cbet1);
|
|
2844
|
+
sbet1 /= t;
|
|
2845
|
+
cbet1 /= t;
|
|
2846
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
|
2847
|
+
this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
|
|
2848
|
+
this._salp0 = this.salp1 * cbet1;
|
|
2849
|
+
this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
|
|
2850
|
+
this._ssig1 = sbet1;
|
|
2851
|
+
this._somg1 = this._salp0 * sbet1;
|
|
2852
|
+
this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
|
|
2853
|
+
t = m.hypot(this._ssig1, this._csig1);
|
|
2854
|
+
this._ssig1 /= t;
|
|
2855
|
+
this._csig1 /= t;
|
|
2856
|
+
this._k2 = m.sq(this._calp0) * geod._ep2;
|
|
2857
|
+
eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
|
|
2858
|
+
if (this.caps & g.CAP_C1) {
|
|
2859
|
+
this._A1m1 = g.A1m1f(eps);
|
|
2860
|
+
this._C1a = new Array(g.nC1_ + 1);
|
|
2861
|
+
g.C1f(eps, this._C1a);
|
|
2862
|
+
this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
|
|
2863
|
+
s = Math.sin(this._B11);
|
|
2864
|
+
c = Math.cos(this._B11);
|
|
2865
|
+
this._stau1 = this._ssig1 * c + this._csig1 * s;
|
|
2866
|
+
this._ctau1 = this._csig1 * c - this._ssig1 * s;
|
|
2867
|
+
}
|
|
2868
|
+
if (this.caps & g.CAP_C1p) {
|
|
2869
|
+
this._C1pa = new Array(g.nC1p_ + 1);
|
|
2870
|
+
g.C1pf(eps, this._C1pa);
|
|
2871
|
+
}
|
|
2872
|
+
if (this.caps & g.CAP_C2) {
|
|
2873
|
+
this._A2m1 = g.A2m1f(eps);
|
|
2874
|
+
this._C2a = new Array(g.nC2_ + 1);
|
|
2875
|
+
g.C2f(eps, this._C2a);
|
|
2876
|
+
this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
|
|
2877
|
+
}
|
|
2878
|
+
if (this.caps & g.CAP_C3) {
|
|
2879
|
+
this._C3a = new Array(g.nC3_);
|
|
2880
|
+
geod.C3f(eps, this._C3a);
|
|
2881
|
+
this._A3c = -this.f * this._salp0 * geod.A3f(eps);
|
|
2882
|
+
this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
|
|
2883
|
+
}
|
|
2884
|
+
if (this.caps & g.CAP_C4) {
|
|
2885
|
+
this._C4a = new Array(g.nC4_);
|
|
2886
|
+
geod.C4f(eps, this._C4a);
|
|
2887
|
+
this._A4 = m.sq(this.a) * this._calp0 * this._salp0 * geod._e2;
|
|
2888
|
+
this._B41 = g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
|
|
2889
|
+
}
|
|
2890
|
+
this.a13 = this.s13 = NaN;
|
|
2891
|
+
};
|
|
2892
|
+
l.GeodesicLine.prototype.GenPosition = function(arcmode, s12_a12, outmask, vals = {}) {
|
|
2893
|
+
var sig12, ssig12, csig12, B12, AB1, ssig2, csig2, tau12, s, c, serr, omg12, lam12, lon12, E, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2, B22, AB2, J12, t, B42, salp12, calp12;
|
|
2894
|
+
if (!outmask)
|
|
2895
|
+
outmask = g.STANDARD;
|
|
2896
|
+
else if (outmask === g.LONG_UNROLL)
|
|
2897
|
+
outmask |= g.STANDARD;
|
|
2898
|
+
outmask &= this.caps & g.OUT_MASK;
|
|
2899
|
+
vals.lat1 = this.lat1;
|
|
2900
|
+
vals.azi1 = this.azi1;
|
|
2901
|
+
vals.lon1 = outmask & g.LONG_UNROLL ? this.lon1 : m.AngNormalize(this.lon1);
|
|
2902
|
+
if (arcmode)
|
|
2903
|
+
vals.a12 = s12_a12;
|
|
2904
|
+
else
|
|
2905
|
+
vals.s12 = s12_a12;
|
|
2906
|
+
if (!(arcmode || this.caps & g.DISTANCE_IN & g.OUT_MASK)) {
|
|
2907
|
+
vals.a12 = NaN;
|
|
2908
|
+
return vals;
|
|
2909
|
+
}
|
|
2910
|
+
B12 = 0;
|
|
2911
|
+
AB1 = 0;
|
|
2912
|
+
if (arcmode) {
|
|
2913
|
+
sig12 = s12_a12 * m.degree;
|
|
2914
|
+
t = m.sincosd(s12_a12);
|
|
2915
|
+
ssig12 = t.s;
|
|
2916
|
+
csig12 = t.c;
|
|
2917
|
+
} else {
|
|
2918
|
+
tau12 = s12_a12 / (this._b * (1 + this._A1m1));
|
|
2919
|
+
s = Math.sin(tau12);
|
|
2920
|
+
c = Math.cos(tau12);
|
|
2921
|
+
B12 = -g.SinCosSeries(true, this._stau1 * c + this._ctau1 * s, this._ctau1 * c - this._stau1 * s, this._C1pa);
|
|
2922
|
+
sig12 = tau12 - (B12 - this._B11);
|
|
2923
|
+
ssig12 = Math.sin(sig12);
|
|
2924
|
+
csig12 = Math.cos(sig12);
|
|
2925
|
+
if (Math.abs(this.f) > 0.01) {
|
|
2926
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
2927
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
2928
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
2929
|
+
serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) - s12_a12 / this._b;
|
|
2930
|
+
sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
|
2931
|
+
ssig12 = Math.sin(sig12);
|
|
2932
|
+
csig12 = Math.cos(sig12);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
2936
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
2937
|
+
dn2 = Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
|
2938
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2939
|
+
if (arcmode || Math.abs(this.f) > 0.01)
|
|
2940
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
2941
|
+
AB1 = (1 + this._A1m1) * (B12 - this._B11);
|
|
2942
|
+
}
|
|
2943
|
+
sbet2 = this._calp0 * ssig2;
|
|
2944
|
+
cbet2 = m.hypot(this._salp0, this._calp0 * csig2);
|
|
2945
|
+
if (cbet2 === 0)
|
|
2946
|
+
cbet2 = csig2 = g.tiny_;
|
|
2947
|
+
salp2 = this._salp0;
|
|
2948
|
+
calp2 = this._calp0 * csig2;
|
|
2949
|
+
if (arcmode && outmask & g.DISTANCE)
|
|
2950
|
+
vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
|
|
2951
|
+
if (outmask & g.LONGITUDE) {
|
|
2952
|
+
somg2 = this._salp0 * ssig2;
|
|
2953
|
+
comg2 = csig2;
|
|
2954
|
+
E = m.copysign(1, this._salp0);
|
|
2955
|
+
omg12 = outmask & g.LONG_UNROLL ? E * (sig12 - (Math.atan2(ssig2, csig2) - Math.atan2(this._ssig1, this._csig1)) + (Math.atan2(E * somg2, comg2) - Math.atan2(E * this._somg1, this._comg1))) : Math.atan2(somg2 * this._comg1 - comg2 * this._somg1, comg2 * this._comg1 + somg2 * this._somg1);
|
|
2956
|
+
lam12 = omg12 + this._A3c * (sig12 + (g.SinCosSeries(true, ssig2, csig2, this._C3a) - this._B31));
|
|
2957
|
+
lon12 = lam12 / m.degree;
|
|
2958
|
+
vals.lon2 = outmask & g.LONG_UNROLL ? this.lon1 + lon12 : m.AngNormalize(m.AngNormalize(this.lon1) + m.AngNormalize(lon12));
|
|
2959
|
+
}
|
|
2960
|
+
if (outmask & g.LATITUDE)
|
|
2961
|
+
vals.lat2 = m.atan2d(sbet2, this._f1 * cbet2);
|
|
2962
|
+
if (outmask & g.AZIMUTH)
|
|
2963
|
+
vals.azi2 = m.atan2d(salp2, calp2);
|
|
2964
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2965
|
+
B22 = g.SinCosSeries(true, ssig2, csig2, this._C2a);
|
|
2966
|
+
AB2 = (1 + this._A2m1) * (B22 - this._B21);
|
|
2967
|
+
J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
|
|
2968
|
+
if (outmask & g.REDUCEDLENGTH)
|
|
2969
|
+
vals.m12 = this._b * (dn2 * (this._csig1 * ssig2) - this._dn1 * (this._ssig1 * csig2) - this._csig1 * csig2 * J12);
|
|
2970
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2971
|
+
t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) / (this._dn1 + dn2);
|
|
2972
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
|
|
2973
|
+
vals.M21 = csig12 - (t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
if (outmask & g.AREA) {
|
|
2977
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, this._C4a);
|
|
2978
|
+
if (this._calp0 === 0 || this._salp0 === 0) {
|
|
2979
|
+
salp12 = salp2 * this.calp1 - calp2 * this.salp1;
|
|
2980
|
+
calp12 = calp2 * this.calp1 + salp2 * this.salp1;
|
|
2981
|
+
} else {
|
|
2982
|
+
salp12 = this._calp0 * this._salp0 * (csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 : ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
|
|
2983
|
+
calp12 = m.sq(this._salp0) + m.sq(this._calp0) * this._csig1 * csig2;
|
|
2984
|
+
}
|
|
2985
|
+
vals.S12 = this._c2 * Math.atan2(salp12, calp12) + this._A4 * (Math.abs(sig12) < 0.01 ? g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a, sig12) : B42 - this._B41);
|
|
2986
|
+
}
|
|
2987
|
+
if (!arcmode)
|
|
2988
|
+
vals.a12 = sig12 / m.degree;
|
|
2989
|
+
return vals;
|
|
2990
|
+
};
|
|
2991
|
+
l.GeodesicLine.prototype.Position = function(s12, outmask) {
|
|
2992
|
+
return this.GenPosition(false, s12, outmask);
|
|
2993
|
+
};
|
|
2994
|
+
l.GeodesicLine.prototype.ArcPosition = function(a12, outmask) {
|
|
2995
|
+
return this.GenPosition(true, a12, outmask);
|
|
2996
|
+
};
|
|
2997
|
+
l.GeodesicLine.prototype.GenSetDistance = function(arcmode, s13_a13) {
|
|
2998
|
+
if (arcmode)
|
|
2999
|
+
this.SetArc(s13_a13);
|
|
3000
|
+
else
|
|
3001
|
+
this.SetDistance(s13_a13);
|
|
3002
|
+
};
|
|
3003
|
+
l.GeodesicLine.prototype.SetDistance = function(s13) {
|
|
3004
|
+
var r;
|
|
3005
|
+
this.s13 = s13;
|
|
3006
|
+
r = this.GenPosition(false, this.s13, g.ARC);
|
|
3007
|
+
this.a13 = 0 + r.a12;
|
|
3008
|
+
};
|
|
3009
|
+
l.GeodesicLine.prototype.SetArc = function(a13) {
|
|
3010
|
+
var r;
|
|
3011
|
+
this.a13 = a13;
|
|
3012
|
+
r = this.GenPosition(true, this.a13, g.DISTANCE);
|
|
3013
|
+
this.s13 = 0 + r.s12;
|
|
3014
|
+
};
|
|
3015
|
+
})(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.Math);
|
|
3016
|
+
|
|
3017
|
+
// dist/ellipsoid-geodesic.js
|
|
3018
|
+
var library = geodesic.Geodesic;
|
|
3019
|
+
var EllipsoidGeodesic = class {
|
|
3020
|
+
constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
|
|
3021
|
+
this.engine = createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b });
|
|
3022
|
+
}
|
|
3023
|
+
/** Total area in squared axis units, with the same normalization as S12. */
|
|
3024
|
+
get surfaceArea() {
|
|
3025
|
+
return 4 * Math.PI * this.engine._c2;
|
|
3026
|
+
}
|
|
3027
|
+
inverse(lat1, lon1, lat2, lon2, options = {}) {
|
|
3028
|
+
validatePoint(lat1, lon1);
|
|
3029
|
+
validatePoint(lat2, lon2);
|
|
3030
|
+
return this.engine.Inverse(lat1, lon1, lat2, lon2, outputMask(options));
|
|
3031
|
+
}
|
|
3032
|
+
direct(latitude, longitude, azimuth, distance, options = {}) {
|
|
3033
|
+
return this.line(latitude, longitude, azimuth, options).position(distance);
|
|
3034
|
+
}
|
|
3035
|
+
arcDirect(latitude, longitude, azimuth, arc, options = {}) {
|
|
3036
|
+
return this.line(latitude, longitude, azimuth, options).arcPosition(arc);
|
|
3037
|
+
}
|
|
3038
|
+
line(latitude, longitude, azimuth, options = {}) {
|
|
3039
|
+
validatePoint(latitude, longitude);
|
|
3040
|
+
validateFinite(azimuth);
|
|
3041
|
+
const selectedMask = outputMask(options);
|
|
3042
|
+
const line = this.engine.Line(latitude, longitude, azimuth, selectedMask | library.DISTANCE_IN);
|
|
3043
|
+
return {
|
|
3044
|
+
// Fourth argument is an internal result request; ordinary Array.map arguments remain ignored.
|
|
3045
|
+
position(distance, _index, _array, output) {
|
|
3046
|
+
validateFinite(distance);
|
|
3047
|
+
return line.GenPosition(false, distance, selectedMask, output);
|
|
3048
|
+
},
|
|
3049
|
+
arcPosition(arc) {
|
|
3050
|
+
validateFinite(arc);
|
|
3051
|
+
return line.ArcPosition(arc, selectedMask);
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
function validatePoint(latitude, longitude) {
|
|
3057
|
+
if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
|
|
3058
|
+
throw new Error("Invalid geodesic coordinates");
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
function outputMask(options) {
|
|
3062
|
+
return library.ALL & ~(options.area ? 0 : library.AREA) | (options.unrollLongitude ? library.LONG_UNROLL : 0);
|
|
3063
|
+
}
|
|
3064
|
+
function validateFinite(value) {
|
|
3065
|
+
if (!Number.isFinite(value))
|
|
3066
|
+
throw new Error("Nonfinite axis, azimuth, distance or arc");
|
|
3067
|
+
}
|
|
3068
|
+
var nonAreaGeodesicMask = library.ALL & ~library.AREA;
|
|
3069
|
+
function createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b }) {
|
|
3070
|
+
validateFinite(a);
|
|
3071
|
+
validateFinite(b);
|
|
3072
|
+
return new library.Geodesic(a, (a - b) / a);
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
// dist/st-geodesic-functions.js
|
|
3076
|
+
var kernel;
|
|
3077
|
+
function getKernel() {
|
|
3078
|
+
kernel ?? (kernel = new EllipsoidGeodesic({
|
|
3079
|
+
semiMajorAxis: WGS84_RADIUS_X,
|
|
3080
|
+
semiMinorAxis: WGS84_RADIUS_Z
|
|
3081
|
+
}));
|
|
3082
|
+
return kernel;
|
|
3083
|
+
}
|
|
3084
|
+
function meters(a, b) {
|
|
3085
|
+
return getKernel().inverse(a[1], a[0], b[1], b[0]).s12;
|
|
3086
|
+
}
|
|
3087
|
+
function emptyPoint(coordinate) {
|
|
3088
|
+
return !coordinate.length || coordinate.every(Number.isNaN);
|
|
3089
|
+
}
|
|
3090
|
+
var pointSetKinds = ["Point", "MultiPoint"];
|
|
3091
|
+
function pointSet(geometry) {
|
|
3092
|
+
if (geometry.type === "Point")
|
|
3093
|
+
return [geometry.coordinates];
|
|
3094
|
+
if (geometry.type === "MultiPoint")
|
|
3095
|
+
return geometry.coordinates;
|
|
3096
|
+
throw new Error("Expected Point or MultiPoint");
|
|
3097
|
+
}
|
|
3098
|
+
function pointSetDistance(a, b, stopAt = 0) {
|
|
3099
|
+
const left = pointSet(a);
|
|
3100
|
+
const points2 = pointSet(b);
|
|
3101
|
+
const right = points2.some(emptyPoint) ? points2.filter((point2) => !emptyPoint(point2)) : points2;
|
|
3102
|
+
let minimum = Infinity;
|
|
3103
|
+
for (const x of left) {
|
|
3104
|
+
if (emptyPoint(x))
|
|
3105
|
+
continue;
|
|
3106
|
+
for (const y of right) {
|
|
3107
|
+
const distance = meters(x, y);
|
|
3108
|
+
if (distance <= stopAt)
|
|
3109
|
+
return distance;
|
|
3110
|
+
minimum = Math.min(minimum, distance);
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
return minimum === Infinity ? null : minimum;
|
|
3114
|
+
}
|
|
3115
|
+
function isPointSet(geometry) {
|
|
3116
|
+
return geometry.type === "Point" || geometry.type === "MultiPoint";
|
|
3117
|
+
}
|
|
3118
|
+
function paths2(geometry) {
|
|
3119
|
+
if (geometry.type === "LineString")
|
|
3120
|
+
return [geometry.coordinates];
|
|
3121
|
+
if (geometry.type === "MultiLineString")
|
|
3122
|
+
return geometry.coordinates;
|
|
3123
|
+
throw new Error("Expected geodesic line geometry");
|
|
3124
|
+
}
|
|
3125
|
+
function lineLength(geometry) {
|
|
3126
|
+
let length = 0;
|
|
3127
|
+
for (const path of paths2(geometry))
|
|
3128
|
+
for (let index = 1; index < path.length; index++)
|
|
3129
|
+
length += meters(path[index - 1], path[index]);
|
|
3130
|
+
return length;
|
|
3131
|
+
}
|
|
3132
|
+
var MAX_SEARCH_INTERVAL = 1e6;
|
|
3133
|
+
var SEARCH_TOLERANCE = 1e-7;
|
|
3134
|
+
var GOLDEN_RATIO = (Math.sqrt(5) - 1) / 2;
|
|
3135
|
+
function distanceAt(line, offset, point2) {
|
|
3136
|
+
const position = line.position(offset);
|
|
3137
|
+
return getKernel().inverse(position.lat2, position.lon2, point2[1], point2[0]).s12;
|
|
3138
|
+
}
|
|
3139
|
+
function minimizeDistance(line, point2, lo, hi, threshold) {
|
|
3140
|
+
let a = hi - GOLDEN_RATIO * (hi - lo);
|
|
3141
|
+
let b = lo + GOLDEN_RATIO * (hi - lo);
|
|
3142
|
+
let da = distanceAt(line, a, point2);
|
|
3143
|
+
let db = distanceAt(line, b, point2);
|
|
3144
|
+
while (hi - lo > SEARCH_TOLERANCE && Math.min(da, db) > threshold) {
|
|
3145
|
+
if (da <= db) {
|
|
3146
|
+
hi = b;
|
|
3147
|
+
b = a;
|
|
3148
|
+
db = da;
|
|
3149
|
+
a = hi - GOLDEN_RATIO * (hi - lo);
|
|
3150
|
+
da = distanceAt(line, a, point2);
|
|
3151
|
+
} else {
|
|
3152
|
+
lo = a;
|
|
3153
|
+
a = b;
|
|
3154
|
+
da = db;
|
|
3155
|
+
b = lo + GOLDEN_RATIO * (hi - lo);
|
|
3156
|
+
db = distanceAt(line, b, point2);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return Math.min(da, db);
|
|
855
3160
|
}
|
|
856
|
-
function
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
3161
|
+
function intervalLowerBound(start, end, length) {
|
|
3162
|
+
return (start + end - length) / 2;
|
|
3163
|
+
}
|
|
3164
|
+
function segmentDistance(a, b, point2, startDistance, endDistance, best, threshold) {
|
|
3165
|
+
const limit = threshold >= 0 ? threshold : best;
|
|
3166
|
+
const solver = getKernel();
|
|
3167
|
+
const { s12: length, azi1 } = solver.inverse(a[1], a[0], b[1], b[0]);
|
|
3168
|
+
if (length === 0 || intervalLowerBound(startDistance, endDistance, length) > limit)
|
|
3169
|
+
return best;
|
|
3170
|
+
const line = solver.line(a[1], a[0], azi1);
|
|
3171
|
+
const count = Math.ceil(length / MAX_SEARCH_INTERVAL);
|
|
3172
|
+
let start = 0;
|
|
3173
|
+
for (let interval = 1; interval <= count; interval++) {
|
|
3174
|
+
const end = interval * length / count;
|
|
3175
|
+
const distance = interval === count ? endDistance : distanceAt(line, end, point2);
|
|
3176
|
+
best = Math.min(best, distance);
|
|
3177
|
+
if (intervalLowerBound(startDistance, distance, end - start) <= Math.min(limit, best)) {
|
|
3178
|
+
best = Math.min(best, minimizeDistance(line, point2, start, end, threshold));
|
|
868
3179
|
}
|
|
869
|
-
if (
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
3180
|
+
if (best <= threshold)
|
|
3181
|
+
break;
|
|
3182
|
+
start = end;
|
|
3183
|
+
startDistance = distance;
|
|
3184
|
+
}
|
|
3185
|
+
return best;
|
|
3186
|
+
}
|
|
3187
|
+
function routeDistance(route, point2, threshold) {
|
|
3188
|
+
let best = Infinity;
|
|
3189
|
+
for (const path of paths2(route)) {
|
|
3190
|
+
if (!path.length)
|
|
3191
|
+
continue;
|
|
3192
|
+
let previous = meters(path[0], point2);
|
|
3193
|
+
best = Math.min(previous, best);
|
|
3194
|
+
if (best <= threshold)
|
|
3195
|
+
return best;
|
|
3196
|
+
for (let vertex = 1; vertex < path.length; vertex++) {
|
|
3197
|
+
const distance = meters(path[vertex], point2);
|
|
3198
|
+
best = Math.min(distance, best);
|
|
3199
|
+
if (best <= threshold)
|
|
3200
|
+
return best;
|
|
3201
|
+
best = segmentDistance(path[vertex - 1], path[vertex], point2, previous, distance, best, threshold);
|
|
3202
|
+
if (best <= threshold)
|
|
3203
|
+
return best;
|
|
3204
|
+
previous = distance;
|
|
876
3205
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
return { ...column2, chunks };
|
|
3206
|
+
}
|
|
3207
|
+
return Number.isFinite(best) ? best : null;
|
|
880
3208
|
}
|
|
881
|
-
function
|
|
882
|
-
if (
|
|
883
|
-
|
|
884
|
-
|
|
3209
|
+
function proximityDistance(a, b, threshold = -1) {
|
|
3210
|
+
if (isPointSet(a) && isPointSet(b)) {
|
|
3211
|
+
return pointSetDistance(a, b, Math.max(0, threshold));
|
|
3212
|
+
}
|
|
3213
|
+
const point2 = a.type === "Point" ? a : b;
|
|
3214
|
+
if (point2.type !== "Point")
|
|
3215
|
+
throw new Error("Geodesic proximity requires at least one Point");
|
|
3216
|
+
const other = a.type === "Point" ? b : a;
|
|
3217
|
+
if (emptyPoint(point2.coordinates))
|
|
3218
|
+
return null;
|
|
3219
|
+
if (other.type !== "LineString" && other.type !== "MultiLineString")
|
|
3220
|
+
throw new Error("Expected a Point or MultiPoint pair, or a Point paired with a route");
|
|
3221
|
+
return routeDistance(other, point2.coordinates, threshold);
|
|
3222
|
+
}
|
|
3223
|
+
function isWGS84(crs) {
|
|
3224
|
+
if (typeof crs === "string") {
|
|
3225
|
+
const identifier = normalizeCRSIdentifier(crs);
|
|
3226
|
+
return identifier === "EPSG:4326" || identifier === "OGC:CRS84";
|
|
3227
|
+
}
|
|
3228
|
+
if (!crs || typeof crs !== "object" || !("id" in crs))
|
|
3229
|
+
return false;
|
|
3230
|
+
const { id } = crs;
|
|
3231
|
+
return Boolean(id && typeof id === "object" && "authority" in id && "code" in id && isWGS84(String(id.authority) + ":" + String(id.code)));
|
|
3232
|
+
}
|
|
3233
|
+
function validateWGS84(crs, name) {
|
|
3234
|
+
if (!isWGS84(crs))
|
|
3235
|
+
throw new Error(`${name} requires WGS84 CRS metadata (EPSG:4326 or OGC:CRS84)`);
|
|
885
3236
|
}
|
|
886
|
-
|
|
3237
|
+
var proximityKinds = [...pointSetKinds, ...lineKinds];
|
|
3238
|
+
var ST_GEODESICDISTANCE = /* @__PURE__ */ spatialFunction(
|
|
3239
|
+
"ST_GeodesicDistance",
|
|
3240
|
+
[proximityKinds, proximityKinds],
|
|
3241
|
+
/* @__PURE__ */ new import_apache_arrow2.Float64(),
|
|
3242
|
+
([a, b]) => proximityDistance(a, b),
|
|
3243
|
+
0,
|
|
3244
|
+
true,
|
|
3245
|
+
false,
|
|
3246
|
+
validateWGS84
|
|
3247
|
+
);
|
|
3248
|
+
var ST_GEODESICLENGTH = /* @__PURE__ */ spatialFunction(
|
|
3249
|
+
"ST_GeodesicLength",
|
|
3250
|
+
[lineKinds],
|
|
3251
|
+
/* @__PURE__ */ new import_apache_arrow2.Float64(),
|
|
3252
|
+
([line]) => lineLength(line),
|
|
3253
|
+
0,
|
|
3254
|
+
true,
|
|
3255
|
+
false,
|
|
3256
|
+
validateWGS84
|
|
3257
|
+
);
|
|
3258
|
+
var ST_GEODESICDWITHIN = /* @__PURE__ */ spatialFunction(
|
|
3259
|
+
"ST_GeodesicDWithin",
|
|
3260
|
+
[proximityKinds, proximityKinds],
|
|
3261
|
+
/* @__PURE__ */ new import_apache_arrow2.Bool(),
|
|
3262
|
+
([a, b], radius) => {
|
|
3263
|
+
if (!Number.isFinite(radius) || radius < 0)
|
|
3264
|
+
throw new Error("ST_GeodesicDWithin requires a finite nonnegative radius in meters");
|
|
3265
|
+
const limit = isPointSet(a) && isPointSet(b) ? radius : radius + SEARCH_TOLERANCE;
|
|
3266
|
+
const distance = proximityDistance(a, b, limit);
|
|
3267
|
+
return distance !== null && distance <= limit;
|
|
3268
|
+
},
|
|
3269
|
+
1,
|
|
3270
|
+
true,
|
|
3271
|
+
false,
|
|
3272
|
+
validateWGS84
|
|
3273
|
+
);
|
|
3274
|
+
function ellipsoidalRouteSegment(a, b) {
|
|
3275
|
+
const solver = getKernel();
|
|
3276
|
+
const { s12: length, azi1 } = solver.inverse(a[1], a[0], b[1], b[0]);
|
|
3277
|
+
let line;
|
|
887
3278
|
return {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
if (fields.length !== signatures.length + numericArguments)
|
|
895
|
-
return void 0;
|
|
896
|
-
const geometryFields = fields.slice(0, signatures.length);
|
|
897
|
-
const numberFields = fields.slice(signatures.length).map((field) => {
|
|
898
|
-
if (field && !import_apache_arrow.DataType.isInt(field.type) && !import_apache_arrow.DataType.isFloat(field.type))
|
|
899
|
-
throw new Error(`${name} requires numeric arguments`);
|
|
900
|
-
return field ?? new import_apache_arrow.Field("number", new import_apache_arrow.Float64(), true);
|
|
901
|
-
});
|
|
902
|
-
const extensions = geometryFields.map((field, index) => {
|
|
903
|
-
if (!field)
|
|
904
|
-
return void 0;
|
|
905
|
-
const extension = (0, import_arrow3.getGeoArrowFieldInfo)(field);
|
|
906
|
-
const encoding = extension == null ? void 0 : extension.encoding;
|
|
907
|
-
const kinds = signatures[index];
|
|
908
|
-
if (encoding === "geoarrow.wkb" && (import_apache_arrow.DataType.isBinary(field.type) || import_apache_arrow.DataType.isLargeBinary(field.type))) {
|
|
909
|
-
} else if (kinds.some((kind) => encoding === "geoarrow." + kind.toLowerCase())) {
|
|
910
|
-
if (!allDimensions && (extension == null ? void 0 : extension.dimension) !== "xy")
|
|
911
|
-
throw new Error(`${name} requires 2D geometry`);
|
|
912
|
-
} else {
|
|
913
|
-
throw new Error(`${name} argument ${index + 1} requires GeoArrow ${kinds.join(" or ")}`);
|
|
914
|
-
}
|
|
915
|
-
if (name.startsWith("ST_") && name !== "ST_SRID" && name !== "ST_SetSRID" && (extension == null ? void 0 : extension.metadata["edges"]) === "spherical")
|
|
916
|
-
throw new Error(`${name} requires planar geometry`);
|
|
917
|
-
return extension;
|
|
918
|
-
});
|
|
919
|
-
const crsValues = extensions.map((extension) => extension == null ? void 0 : extension.metadata["crs"]).filter((crs) => crs !== void 0 && crs !== null);
|
|
920
|
-
if (name.startsWith("ST_") && crsValues.some((crs) => JSON.stringify(crs) !== JSON.stringify(crsValues[0]))) {
|
|
921
|
-
throw new Error(`${name} requires arguments in the same CRS`);
|
|
922
|
-
}
|
|
923
|
-
const metadata = /* @__PURE__ */ new Map();
|
|
924
|
-
if (import_apache_arrow.DataType.isBinary(type)) {
|
|
925
|
-
metadata.set(EXTENSION_NAME, "geoarrow.wkb");
|
|
926
|
-
const inputMetadata = (_a = geometryFields.find((field) => field == null ? void 0 : field.metadata.has(EXTENSION_METADATA))) == null ? void 0 : _a.metadata.get(EXTENSION_METADATA);
|
|
927
|
-
if (inputMetadata)
|
|
928
|
-
metadata.set(EXTENSION_METADATA, inputMetadata);
|
|
929
|
-
}
|
|
930
|
-
const arguments_ = [
|
|
931
|
-
...geometryFields.map((field) => field ?? new import_apache_arrow.Field("geometry", new import_apache_arrow.Binary(), true)),
|
|
932
|
-
...numberFields
|
|
933
|
-
];
|
|
934
|
-
return {
|
|
935
|
-
arguments: arguments_,
|
|
936
|
-
nullHandling: skipNullGeometries ? "call" : "propagate",
|
|
937
|
-
result: new import_apache_arrow.Field(name, type, true, metadata),
|
|
938
|
-
/** Evaluates active rows and retains their positions in the output batch. */
|
|
939
|
-
evaluate(vectors, { activeRows, length: rowCount }) {
|
|
940
|
-
const numbers = vectors.slice(signatures.length);
|
|
941
|
-
const readers = vectors.slice(0, signatures.length).map((vector, index) => readGeometryValue(vector, arguments_[index], activeRows, allDimensions ? (g, dimension, members) => ({ ...g, dimension, members }) : planarGeometry, name === "ST_GeometryN"));
|
|
942
|
-
const values = new Array(rowCount).fill(null);
|
|
943
|
-
for (let row = 0; row < rowCount; row++) {
|
|
944
|
-
if (!activeRows[row])
|
|
945
|
-
continue;
|
|
946
|
-
const geometries = [];
|
|
947
|
-
for (let index = 0; index < readers.length; index++) {
|
|
948
|
-
if (skipNullGeometries && !vectors[index].isValid(row))
|
|
949
|
-
continue;
|
|
950
|
-
const geometry = readers[index](row);
|
|
951
|
-
if (!signatures[index].includes(geometry.type))
|
|
952
|
-
throw new Error(`${name} argument ${index + 1} does not support ${geometry.type} at row ${row}`);
|
|
953
|
-
geometries.push(geometry);
|
|
954
|
-
}
|
|
955
|
-
values[row] = evaluate(geometries, ...numbers.map((vector) => Number(vector.get(row))));
|
|
956
|
-
}
|
|
957
|
-
return (0, import_apache_arrow.vectorFromArray)(values, type);
|
|
958
|
-
}
|
|
959
|
-
};
|
|
3279
|
+
length,
|
|
3280
|
+
/** Samples the geodesic at a fraction of its total length. */
|
|
3281
|
+
interpolate(fraction) {
|
|
3282
|
+
line ?? (line = solver.line(a[1], a[0], azi1));
|
|
3283
|
+
const { lon2, lat2 } = line.position(length * fraction);
|
|
3284
|
+
return [lon2, lat2];
|
|
960
3285
|
}
|
|
961
3286
|
};
|
|
962
3287
|
}
|
|
963
|
-
|
|
964
|
-
|
|
3288
|
+
var ST_GEODESICSEGMENTIZE = /* @__PURE__ */ segmentizeFunction("ST_GeodesicSegmentize", ellipsoidalRouteSegment, validateWGS84);
|
|
3289
|
+
var GEODESIC_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
3290
|
+
ST_GEODESICDISTANCE,
|
|
3291
|
+
ST_GEODESICLENGTH,
|
|
3292
|
+
ST_GEODESICDWITHIN,
|
|
3293
|
+
ST_GEODESICSEGMENTIZE
|
|
3294
|
+
]);
|
|
3295
|
+
|
|
3296
|
+
// dist/st-coverage-functions.js
|
|
3297
|
+
var import_apache_arrow3 = require("apache-arrow");
|
|
3298
|
+
var import_arrow6 = require("@math.gl/core/arrow");
|
|
3299
|
+
|
|
3300
|
+
// dist/coverage-simplification.js
|
|
3301
|
+
var import_spatial_index2 = require("@math.gl/geometry/spatial-index");
|
|
3302
|
+
var import_robust_predicates2 = require("robust-predicates");
|
|
3303
|
+
function key(point2) {
|
|
3304
|
+
return `${point2[0]}/${point2[1]}`;
|
|
965
3305
|
}
|
|
966
|
-
function
|
|
967
|
-
return
|
|
3306
|
+
function same(a, b) {
|
|
3307
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
968
3308
|
}
|
|
969
|
-
function
|
|
970
|
-
|
|
3309
|
+
function bounds(points2) {
|
|
3310
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
3311
|
+
for (const [x, y] of points2) {
|
|
3312
|
+
x0 = Math.min(x0, x);
|
|
3313
|
+
y0 = Math.min(y0, y);
|
|
3314
|
+
x1 = Math.max(x1, x);
|
|
3315
|
+
y1 = Math.max(y1, y);
|
|
3316
|
+
}
|
|
3317
|
+
return [x0, y0, x1, y1];
|
|
971
3318
|
}
|
|
972
|
-
function
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
3319
|
+
function search(index, points2) {
|
|
3320
|
+
const [x0, y0, x1, y1] = bounds(points2);
|
|
3321
|
+
return index.search([x0, y0], [x1, y1]);
|
|
3322
|
+
}
|
|
3323
|
+
function side(a, b, c) {
|
|
3324
|
+
return Math.sign((0, import_robust_predicates2.orient2d)(a[0], a[1], b[0], b[1], c[0], c[1]));
|
|
3325
|
+
}
|
|
3326
|
+
function strictlyInside(p, [a, b, c]) {
|
|
3327
|
+
const x = side(a, b, p);
|
|
3328
|
+
return x !== 0 && x === side(b, c, p) && x === side(c, a, p);
|
|
3329
|
+
}
|
|
3330
|
+
function conflicts([a, b], [c, d]) {
|
|
3331
|
+
if (!(0, import_polygon2.segmentsMeet)(a, b, c, d))
|
|
3332
|
+
return false;
|
|
3333
|
+
if (!(same(a, c) || same(a, d) || same(b, c) || same(b, d)))
|
|
3334
|
+
return true;
|
|
3335
|
+
return !same(a, c) && !same(a, d) && (0, import_polygon2.pointOnSegment)(a, c, d) || !same(b, c) && !same(b, d) && (0, import_polygon2.pointOnSegment)(b, c, d) || !same(c, a) && !same(c, b) && (0, import_polygon2.pointOnSegment)(c, a, b) || !same(d, a) && !same(d, b) && (0, import_polygon2.pointOnSegment)(d, a, b) || same(a, c) && same(b, d) || same(a, d) && same(b, c);
|
|
3336
|
+
}
|
|
3337
|
+
function obstructs(edge, triangle) {
|
|
3338
|
+
const [a, b, c] = triangle;
|
|
3339
|
+
const [x, y] = edge;
|
|
3340
|
+
if (same(x, b) && (same(y, a) || same(y, c)) || same(y, b) && (same(x, a) || same(x, c)))
|
|
3341
|
+
return false;
|
|
3342
|
+
return strictlyInside(x, triangle) || strictlyInside(y, triangle) || conflicts(edge, [a, b]) || conflicts(edge, [b, c]) || conflicts(edge, [a, c]);
|
|
3343
|
+
}
|
|
3344
|
+
function neighbor({ ring, index }, delta) {
|
|
3345
|
+
return ring.points[(index + delta + ring.points.length) % ring.points.length];
|
|
3346
|
+
}
|
|
3347
|
+
function candidate(owners, tolerance) {
|
|
3348
|
+
if (owners.length !== 2)
|
|
3349
|
+
return void 0;
|
|
3350
|
+
const [left, right] = owners;
|
|
3351
|
+
if (left.ring.row === right.ring.row || left.ring.points.length <= 3 || right.ring.points.length <= 3)
|
|
3352
|
+
return void 0;
|
|
3353
|
+
const a = neighbor(left, -1);
|
|
3354
|
+
const b = neighbor(left, 0);
|
|
3355
|
+
const c = neighbor(left, 1);
|
|
3356
|
+
const x = neighbor(right, -1);
|
|
3357
|
+
const y = neighbor(right, 1);
|
|
3358
|
+
if (same(a, c) || !(same(a, x) && same(c, y) || same(a, y) && same(c, x)))
|
|
3359
|
+
return void 0;
|
|
3360
|
+
if (!(distanceToPlanarSegment(b, a, c) <= tolerance))
|
|
3361
|
+
return void 0;
|
|
3362
|
+
return { triangle: [a, b, c], pair: [left, right] };
|
|
3363
|
+
}
|
|
3364
|
+
function simplifyCoverage(rows2, tolerance, signal) {
|
|
3365
|
+
if (!tolerance)
|
|
3366
|
+
return rows2;
|
|
3367
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
3368
|
+
const boundaries = [];
|
|
3369
|
+
const shapes = rows2.map((geometry, row) => {
|
|
3370
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3371
|
+
if (!geometry)
|
|
3372
|
+
return null;
|
|
3373
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
3374
|
+
return polygons3.map((polygon) => polygon.map((closed) => {
|
|
3375
|
+
if (closed.length < 4 || !same(closed[0], closed[closed.length - 1]))
|
|
3376
|
+
throw new Error("ST_CoverageSimplify requires closed polygon rings");
|
|
3377
|
+
const points2 = closed.slice(0, -1);
|
|
3378
|
+
const ring = { row, points: points2, removed: /* @__PURE__ */ new Set() };
|
|
3379
|
+
points2.forEach((point2, index) => {
|
|
3380
|
+
if (!Number.isFinite(point2[0]) || !Number.isFinite(point2[1]))
|
|
3381
|
+
throw new Error("ST_CoverageSimplify requires finite coordinates");
|
|
3382
|
+
const id = key(point2);
|
|
3383
|
+
const previous = occurrences.get(id);
|
|
3384
|
+
const owner = { ring, index };
|
|
3385
|
+
if (previous)
|
|
3386
|
+
previous.push(owner);
|
|
3387
|
+
else
|
|
3388
|
+
occurrences.set(id, [owner]);
|
|
3389
|
+
boundaries.push([point2, points2[(index + 1) % points2.length]]);
|
|
3390
|
+
});
|
|
3391
|
+
return ring;
|
|
3392
|
+
}));
|
|
3393
|
+
});
|
|
3394
|
+
const candidates = [...occurrences.values()].flatMap((owners) => {
|
|
3395
|
+
const edit = candidate(owners, tolerance);
|
|
3396
|
+
return edit ? [edit] : [];
|
|
3397
|
+
});
|
|
3398
|
+
if (!candidates.length)
|
|
3399
|
+
return rows2;
|
|
3400
|
+
const original = new import_spatial_index2.BoxIndex({ dimension: 2, bounds: boundaries.flatMap(bounds) });
|
|
3401
|
+
const edits = new import_spatial_index2.BoxIndex({
|
|
3402
|
+
dimension: 2,
|
|
3403
|
+
bounds: candidates.flatMap((edit) => bounds(edit.triangle))
|
|
3404
|
+
});
|
|
3405
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
3406
|
+
const protectedVertices = /* @__PURE__ */ new Set();
|
|
3407
|
+
candidates.forEach(({ triangle, pair }, index) => {
|
|
3408
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3409
|
+
const [a, b, c] = triangle;
|
|
3410
|
+
if (protectedVertices.has(key(b)) || pair.some(({ ring }) => ring.points.length - ring.removed.size <= 3))
|
|
3411
|
+
return;
|
|
3412
|
+
if (search(original, triangle).some((hit) => obstructs(boundaries[hit], triangle)))
|
|
3413
|
+
return;
|
|
3414
|
+
if (search(edits, triangle).some((hit) => accepted.has(hit)))
|
|
3415
|
+
return;
|
|
3416
|
+
accepted.add(index);
|
|
3417
|
+
protectedVertices.add(key(a));
|
|
3418
|
+
protectedVertices.add(key(c));
|
|
3419
|
+
for (const { ring, index: position } of pair)
|
|
3420
|
+
ring.removed.add(position);
|
|
3421
|
+
});
|
|
3422
|
+
if (!accepted.size)
|
|
3423
|
+
return rows2;
|
|
3424
|
+
return shapes.map((shape, row) => {
|
|
3425
|
+
const geometry = rows2[row];
|
|
3426
|
+
if (!geometry || !shape)
|
|
3427
|
+
return null;
|
|
3428
|
+
const coordinates = shape.map((polygon) => polygon.map(({ points: points2, removed }) => {
|
|
3429
|
+
const path = points2.filter((_, index) => !removed.has(index));
|
|
3430
|
+
return [...path, path[0]];
|
|
3431
|
+
}));
|
|
3432
|
+
return geometry.type === "Polygon" ? { type: "Polygon", coordinates: coordinates[0] } : { type: "MultiPolygon", coordinates };
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
|
|
3436
|
+
// dist/st-coverage-functions.js
|
|
3437
|
+
function createSTCoverageSimplify({ geometry, tolerance }) {
|
|
3438
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
3439
|
+
throw new Error("ST_CoverageSimplify requires a finite nonnegative tolerance");
|
|
3440
|
+
return {
|
|
3441
|
+
kind: "table",
|
|
3442
|
+
name: "ST_CoverageSimplify",
|
|
3443
|
+
/** Binds one native 2D polygon field and a stable output schema. */
|
|
3444
|
+
bind(inputSchema) {
|
|
3445
|
+
const index = inputSchema.fields.findIndex((field2) => field2.name === geometry);
|
|
3446
|
+
const field = inputSchema.fields[index];
|
|
3447
|
+
const info = field && (0, import_arrow6.getGeoArrowFieldInfo)(field);
|
|
3448
|
+
const encoding = info == null ? void 0 : info.encoding;
|
|
3449
|
+
if (!field || encoding !== "geoarrow.polygon" && encoding !== "geoarrow.multipolygon" || info.dimension !== "xy" || info.metadata["edges"] === "spherical")
|
|
3450
|
+
throw new Error("ST_CoverageSimplify requires a native planar XY Polygon or MultiPolygon column");
|
|
3451
|
+
const output = nativeGeometryResult(encoding);
|
|
3452
|
+
const fields = inputSchema.fields.slice();
|
|
3453
|
+
fields[index] = field.clone({ type: output.type });
|
|
3454
|
+
const outputSchema = new import_apache_arrow3.Schema(fields, inputSchema.metadata, void 0, inputSchema.metadataVersion);
|
|
3455
|
+
return {
|
|
3456
|
+
outputSchema,
|
|
3457
|
+
/** Simplifies shared boundaries across batches while preserving row alignment. */
|
|
3458
|
+
evaluate(input, { signal }) {
|
|
3459
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3460
|
+
if (!input.numRows)
|
|
3461
|
+
return new import_apache_arrow3.Table(outputSchema, []);
|
|
3462
|
+
const vector = input.getChildAt(index);
|
|
3463
|
+
const column2 = (0, import_arrow6.makeGeoArrowColumnFromArrowVector)(vector, { field });
|
|
3464
|
+
const rows2 = (0, import_arrow6.materializeGeoArrowRows)(column2);
|
|
3465
|
+
const result2 = simplifyCoverage(rows2, tolerance, signal);
|
|
3466
|
+
let first = 0;
|
|
3467
|
+
const type = new import_apache_arrow3.Struct(fields);
|
|
3468
|
+
const batches = input.batches.map((batch) => {
|
|
3469
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3470
|
+
const children = batch.data.children.slice();
|
|
3471
|
+
children[index] = output.build(result2.slice(first, first + batch.numRows)).data[0];
|
|
3472
|
+
first += batch.numRows;
|
|
3473
|
+
const data = new import_apache_arrow3.Data(type, 0, batch.numRows, 0, void 0, children);
|
|
3474
|
+
return (0, import_arrow6.createRecordBatchWithMetadata)(outputSchema, data, (0, import_arrow6.getRecordBatchMetadata)(batch));
|
|
3475
|
+
});
|
|
3476
|
+
return new import_apache_arrow3.Table(outputSchema, batches);
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
};
|
|
977
3481
|
}
|
|
978
3482
|
|
|
979
3483
|
// dist/st-functions.js
|
|
@@ -981,34 +3485,43 @@ var ST_MAKEPOINT = {
|
|
|
981
3485
|
kind: "scalar",
|
|
982
3486
|
name: "ST_MakePoint",
|
|
983
3487
|
prototypes: [],
|
|
984
|
-
/** Binds two to four numeric
|
|
3488
|
+
/** Binds two to four numeric ordinates to a native GeoArrow point. */
|
|
985
3489
|
resolvePrototype(fields) {
|
|
986
3490
|
if (fields.length < 2 || fields.length > 4)
|
|
987
3491
|
return void 0;
|
|
988
3492
|
const arguments_ = fields.map((field) => {
|
|
989
|
-
if (field && !
|
|
3493
|
+
if (field && !import_apache_arrow4.DataType.isInt(field.type) && !import_apache_arrow4.DataType.isFloat(field.type))
|
|
990
3494
|
throw new Error("ST_MakePoint requires numeric coordinates");
|
|
991
|
-
return field ?? new
|
|
3495
|
+
return field ?? new import_apache_arrow4.Field("coordinate", new import_apache_arrow4.Float64(), true);
|
|
992
3496
|
});
|
|
993
|
-
const
|
|
3497
|
+
const dimension = fields.length === 2 ? "xy" : fields.length === 3 ? "xyz" : "xyzm";
|
|
3498
|
+
const coordinateType = new import_apache_arrow4.Float64();
|
|
3499
|
+
const size = fields.length;
|
|
3500
|
+
const type = new import_apache_arrow4.FixedSizeList(size, new import_apache_arrow4.Field(dimension, coordinateType, true));
|
|
994
3501
|
return {
|
|
995
3502
|
arguments: arguments_,
|
|
996
|
-
result: new
|
|
997
|
-
/** Writes
|
|
3503
|
+
result: new import_apache_arrow4.Field("ST_MakePoint", type, true, /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.point"]])),
|
|
3504
|
+
/** Writes active rows directly to the interleaved coordinate buffer. */
|
|
998
3505
|
evaluate(vectors, { activeRows, length }) {
|
|
999
|
-
const
|
|
3506
|
+
const data = new Float64Array(length * size);
|
|
3507
|
+
const nullBitmap = new Uint8Array(Math.ceil(length / 8));
|
|
3508
|
+
let nullCount = 0;
|
|
1000
3509
|
for (let row = 0; row < length; row++) {
|
|
1001
|
-
if (activeRows[row]) {
|
|
1002
|
-
|
|
1003
|
-
|
|
3510
|
+
if (!activeRows[row]) {
|
|
3511
|
+
nullCount++;
|
|
3512
|
+
continue;
|
|
3513
|
+
}
|
|
3514
|
+
nullBitmap[row >> 3] |= 1 << (row & 7);
|
|
3515
|
+
for (let coordinate = 0; coordinate < size; coordinate++) {
|
|
3516
|
+
data[row * size + coordinate] = Number(vectors[coordinate].get(row));
|
|
1004
3517
|
}
|
|
1005
3518
|
}
|
|
1006
|
-
return (
|
|
3519
|
+
return nativePointVector(type, data, nullBitmap, nullCount);
|
|
1007
3520
|
}
|
|
1008
3521
|
};
|
|
1009
3522
|
}
|
|
1010
3523
|
};
|
|
1011
|
-
function tileEnvelope(zoom, x, y,
|
|
3524
|
+
function tileEnvelope(zoom, x, y, bounds2, margin) {
|
|
1012
3525
|
if (!Number.isInteger(zoom) || zoom < 0 || zoom > 31)
|
|
1013
3526
|
throw new Error("ST_TileEnvelope zoom must be an integer in [0,31]");
|
|
1014
3527
|
const count = 2 ** zoom;
|
|
@@ -1016,7 +3529,7 @@ function tileEnvelope(zoom, x, y, bounds, margin) {
|
|
|
1016
3529
|
throw new Error("ST_TileEnvelope tile index outside zoom level");
|
|
1017
3530
|
if (!Number.isFinite(margin) || margin < -0.5)
|
|
1018
3531
|
throw new Error("Invalid ST_TileEnvelope margin");
|
|
1019
|
-
const [west, south, east, north] =
|
|
3532
|
+
const [west, south, east, north] = bounds2;
|
|
1020
3533
|
const width = (east - west) / count, height = (north - south) / count;
|
|
1021
3534
|
if (!(width > 0 && height > 0 && Number.isFinite(width) && Number.isFinite(height)))
|
|
1022
3535
|
throw new Error("ST_TileEnvelope requires nondegenerate bounds");
|
|
@@ -1025,7 +3538,7 @@ function tileEnvelope(zoom, x, y, bounds, margin) {
|
|
|
1025
3538
|
const right = fullWidth ? east : Math.min(east, west + (x + 1 + margin) * width);
|
|
1026
3539
|
const bottom = Math.max(south, north - (y + 1 + margin) * height);
|
|
1027
3540
|
const top = Math.min(north, north - (y - margin) * height);
|
|
1028
|
-
return (0,
|
|
3541
|
+
return (0, import_arrow7.writeWKB)({
|
|
1029
3542
|
type: "Polygon",
|
|
1030
3543
|
coordinates: [
|
|
1031
3544
|
[
|
|
@@ -1052,21 +3565,21 @@ var ST_TILEENVELOPE = {
|
|
|
1052
3565
|
ST_ENVELOPE.resolvePrototype([root]);
|
|
1053
3566
|
const args = fields.map((field, i) => {
|
|
1054
3567
|
if (i === 3)
|
|
1055
|
-
return field ?? new
|
|
1056
|
-
if (field && !
|
|
3568
|
+
return field ?? new import_apache_arrow4.Field("bounds", new import_apache_arrow4.Binary(), true);
|
|
3569
|
+
if (field && !import_apache_arrow4.DataType.isInt(field.type) && !import_apache_arrow4.DataType.isFloat(field.type))
|
|
1057
3570
|
throw new Error("ST_TileEnvelope requires numeric indices and margin");
|
|
1058
|
-
return field ?? new
|
|
3571
|
+
return field ?? new import_apache_arrow4.Field("number", new import_apache_arrow4.Float64(), true);
|
|
1059
3572
|
});
|
|
1060
3573
|
const metadata = /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.wkb"]]);
|
|
1061
3574
|
const crs = custom ? root == null ? void 0 : root.metadata.get(EXTENSION_METADATA) : '{"crs_type":"authority_code","crs":"EPSG:3857"}';
|
|
1062
3575
|
if (crs)
|
|
1063
3576
|
metadata.set(EXTENSION_METADATA, crs);
|
|
1064
|
-
const type = new
|
|
3577
|
+
const type = new import_apache_arrow4.Binary();
|
|
1065
3578
|
const r = EPSG3857_HALF_CIRCUMFERENCE;
|
|
1066
3579
|
const world = [-r, -r, r, r];
|
|
1067
3580
|
return {
|
|
1068
3581
|
arguments: args,
|
|
1069
|
-
result: new
|
|
3582
|
+
result: new import_apache_arrow4.Field("ST_TileEnvelope", type, true, metadata),
|
|
1070
3583
|
/** Computes bounds for active rows using the top-left XYZ origin. */
|
|
1071
3584
|
evaluate(vectors, { activeRows, length }) {
|
|
1072
3585
|
const values = new Array(length).fill(null);
|
|
@@ -1074,12 +3587,12 @@ var ST_TILEENVELOPE = {
|
|
|
1074
3587
|
for (let row = 0; row < length; row++) {
|
|
1075
3588
|
if (!activeRows[row])
|
|
1076
3589
|
continue;
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
3590
|
+
const bounds2 = read ? planarBounds(read(row)) : world;
|
|
3591
|
+
if (!bounds2)
|
|
1079
3592
|
throw new Error("ST_TileEnvelope requires nonempty bounds");
|
|
1080
|
-
values[row] = tileEnvelope(Number(vectors[0].get(row)), Number(vectors[1].get(row)), Number(vectors[2].get(row)),
|
|
3593
|
+
values[row] = tileEnvelope(Number(vectors[0].get(row)), Number(vectors[1].get(row)), Number(vectors[2].get(row)), bounds2, vectors[4] ? Number(vectors[4].get(row)) : 0);
|
|
1081
3594
|
}
|
|
1082
|
-
return (0,
|
|
3595
|
+
return (0, import_apache_arrow4.vectorFromArray)(values, type);
|
|
1083
3596
|
}
|
|
1084
3597
|
};
|
|
1085
3598
|
}
|
|
@@ -1094,17 +3607,17 @@ function pointOrdinate(ordinate) {
|
|
|
1094
3607
|
resolvePrototype(fields) {
|
|
1095
3608
|
if (fields.length !== 1)
|
|
1096
3609
|
return void 0;
|
|
1097
|
-
const field = fields[0] ?? new
|
|
1098
|
-
const extension = (0,
|
|
3610
|
+
const field = fields[0] ?? new import_apache_arrow4.Field("point", new import_apache_arrow4.Binary(), true, /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.wkb"]]));
|
|
3611
|
+
const extension = (0, import_arrow7.getGeoArrowFieldInfo)(field);
|
|
1099
3612
|
if ((extension == null ? void 0 : extension.metadata["edges"]) === "spherical")
|
|
1100
3613
|
throw new Error(`${name} requires planar geometry`);
|
|
1101
3614
|
const encoding = extension == null ? void 0 : extension.encoding;
|
|
1102
|
-
if (encoding !== "geoarrow.point" && !(encoding === "geoarrow.wkb" && (
|
|
3615
|
+
if (encoding !== "geoarrow.point" && !(encoding === "geoarrow.wkb" && (import_apache_arrow4.DataType.isBinary(field.type) || import_apache_arrow4.DataType.isLargeBinary(field.type))))
|
|
1103
3616
|
throw new Error(`${name} requires a GeoArrow Point`);
|
|
1104
|
-
const type = new
|
|
3617
|
+
const type = new import_apache_arrow4.Float64();
|
|
1105
3618
|
return {
|
|
1106
3619
|
arguments: [field],
|
|
1107
|
-
result: new
|
|
3620
|
+
result: new import_apache_arrow4.Field(name, type, true),
|
|
1108
3621
|
/** Extracts ordinates using the WKB row or native field dimension. */
|
|
1109
3622
|
evaluate([vector], { length, activeRows }) {
|
|
1110
3623
|
if (encoding === "geoarrow.point") {
|
|
@@ -1112,14 +3625,14 @@ function pointOrdinate(ordinate) {
|
|
|
1112
3625
|
const result2 = new Array(length).fill(null);
|
|
1113
3626
|
const index = column2.dimension.indexOf(ordinate);
|
|
1114
3627
|
if (index >= 0) {
|
|
1115
|
-
(0,
|
|
3628
|
+
(0, import_arrow7.visitGeoArrowCoordinates)(column2, (coordinate, row) => {
|
|
1116
3629
|
if (Number.isFinite(coordinate[0]) && Number.isFinite(coordinate[1])) {
|
|
1117
3630
|
result2[row] = coordinate[index] ?? null;
|
|
1118
3631
|
}
|
|
1119
3632
|
return coordinate;
|
|
1120
3633
|
});
|
|
1121
3634
|
}
|
|
1122
|
-
return (0,
|
|
3635
|
+
return (0, import_apache_arrow4.vectorFromArray)(result2, type);
|
|
1123
3636
|
}
|
|
1124
3637
|
const read = readGeometryValue(vector, field, activeRows, (geometry, dimension) => {
|
|
1125
3638
|
var _a;
|
|
@@ -1127,7 +3640,7 @@ function pointOrdinate(ordinate) {
|
|
|
1127
3640
|
throw new Error(`${name} requires a Point`);
|
|
1128
3641
|
return ((_a = pointCoordinates(geometry)) == null ? void 0 : _a[dimension.indexOf(ordinate)]) ?? null;
|
|
1129
3642
|
});
|
|
1130
|
-
return (0,
|
|
3643
|
+
return (0, import_apache_arrow4.vectorFromArray)(Array.from({ length }, (_, i) => activeRows[i] ? read(i) : null), type);
|
|
1131
3644
|
}
|
|
1132
3645
|
};
|
|
1133
3646
|
}
|
|
@@ -1140,51 +3653,51 @@ var ST_M = /* @__PURE__ */ pointOrdinate("m");
|
|
|
1140
3653
|
var ST_STARTPOINT = /* @__PURE__ */ spatialFunction(
|
|
1141
3654
|
"ST_StartPoint",
|
|
1142
3655
|
[["LineString"]],
|
|
1143
|
-
/* @__PURE__ */ new
|
|
3656
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
1144
3657
|
([line]) => {
|
|
1145
3658
|
if ((line == null ? void 0 : line.type) !== "LineString" || !line.coordinates.length)
|
|
1146
3659
|
return null;
|
|
1147
|
-
return (0,
|
|
3660
|
+
return (0, import_arrow7.writeWKB)({ type: "Point", coordinates: line.coordinates[0] }, "xy");
|
|
1148
3661
|
}
|
|
1149
3662
|
);
|
|
1150
3663
|
var ST_ENDPOINT = /* @__PURE__ */ spatialFunction(
|
|
1151
3664
|
"ST_EndPoint",
|
|
1152
3665
|
[["LineString"]],
|
|
1153
|
-
/* @__PURE__ */ new
|
|
3666
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
1154
3667
|
([line]) => {
|
|
1155
3668
|
if ((line == null ? void 0 : line.type) !== "LineString" || !line.coordinates.length)
|
|
1156
3669
|
return null;
|
|
1157
|
-
return (0,
|
|
3670
|
+
return (0, import_arrow7.writeWKB)({ type: "Point", coordinates: line.coordinates[line.coordinates.length - 1] }, "xy");
|
|
1158
3671
|
}
|
|
1159
3672
|
);
|
|
1160
3673
|
var ST_CONTAINS = /* @__PURE__ */ spatialFunction(
|
|
1161
3674
|
"ST_Contains",
|
|
1162
3675
|
[polygonKinds, pointKinds],
|
|
1163
|
-
/* @__PURE__ */ new
|
|
3676
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1164
3677
|
([polygon, point2]) => pointInPolygon(point2, polygon, true) ?? false
|
|
1165
3678
|
);
|
|
1166
3679
|
var ST_COVERS = /* @__PURE__ */ spatialFunction(
|
|
1167
3680
|
"ST_Covers",
|
|
1168
3681
|
[polygonKinds, pointKinds],
|
|
1169
|
-
/* @__PURE__ */ new
|
|
3682
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1170
3683
|
([polygon, point2]) => pointInPolygon(point2, polygon) ?? false
|
|
1171
3684
|
);
|
|
1172
3685
|
var ST_WITHIN = /* @__PURE__ */ spatialFunction(
|
|
1173
3686
|
"ST_Within",
|
|
1174
3687
|
[pointKinds, polygonKinds],
|
|
1175
|
-
/* @__PURE__ */ new
|
|
3688
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1176
3689
|
([p, polygon]) => pointInPolygon(p, polygon, true) ?? false
|
|
1177
3690
|
);
|
|
1178
3691
|
var ST_COVEREDBY = /* @__PURE__ */ spatialFunction(
|
|
1179
3692
|
"ST_CoveredBy",
|
|
1180
3693
|
[pointKinds, polygonKinds],
|
|
1181
|
-
/* @__PURE__ */ new
|
|
3694
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1182
3695
|
([p, polygon]) => pointInPolygon(p, polygon) ?? false
|
|
1183
3696
|
);
|
|
1184
3697
|
var ST_POINTN = /* @__PURE__ */ spatialFunction(
|
|
1185
3698
|
"ST_PointN",
|
|
1186
3699
|
[["LineString"]],
|
|
1187
|
-
/* @__PURE__ */ new
|
|
3700
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
1188
3701
|
([line], position) => {
|
|
1189
3702
|
if (!Number.isInteger(position))
|
|
1190
3703
|
throw new Error("ST_PointN requires an integer position");
|
|
@@ -1192,15 +3705,15 @@ var ST_POINTN = /* @__PURE__ */ spatialFunction(
|
|
|
1192
3705
|
return null;
|
|
1193
3706
|
const index = position > 0 ? position - 1 : line.coordinates.length + position;
|
|
1194
3707
|
const coordinates = line.coordinates[index];
|
|
1195
|
-
return coordinates ? (0,
|
|
3708
|
+
return coordinates ? (0, import_arrow7.writeWKB)({ type: "Point", coordinates }, "xy") : null;
|
|
1196
3709
|
},
|
|
1197
3710
|
1
|
|
1198
3711
|
);
|
|
1199
3712
|
var ST_MAKEENVELOPE = /* @__PURE__ */ spatialFunction(
|
|
1200
3713
|
"ST_MakeEnvelope",
|
|
1201
3714
|
[],
|
|
1202
|
-
/* @__PURE__ */ new
|
|
1203
|
-
(_, xmin, ymin, xmax, ymax) => (0,
|
|
3715
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
3716
|
+
(_, xmin, ymin, xmax, ymax) => (0, import_arrow7.writeWKB)({
|
|
1204
3717
|
type: "Polygon",
|
|
1205
3718
|
coordinates: [
|
|
1206
3719
|
[
|
|
@@ -1217,58 +3730,162 @@ var ST_MAKEENVELOPE = /* @__PURE__ */ spatialFunction(
|
|
|
1217
3730
|
var ST_DISTANCE = /* @__PURE__ */ spatialFunction(
|
|
1218
3731
|
"ST_Distance",
|
|
1219
3732
|
[pointKinds, pointKinds],
|
|
1220
|
-
/* @__PURE__ */ new
|
|
3733
|
+
/* @__PURE__ */ new import_apache_arrow4.Float64(),
|
|
1221
3734
|
([a, b]) => {
|
|
1222
3735
|
const p = pointCoordinates(a);
|
|
1223
3736
|
const q = pointCoordinates(b);
|
|
1224
3737
|
return p && q ? Math.hypot(q[0] - p[0], q[1] - p[1]) : null;
|
|
1225
3738
|
}
|
|
1226
3739
|
);
|
|
1227
|
-
var
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
3740
|
+
var routePointKinds = ["Point", "LineString"];
|
|
3741
|
+
function closestPair(a, b) {
|
|
3742
|
+
if (a.type === "LineString" && b.type === "LineString") {
|
|
3743
|
+
throw new Error("Route snapping requires at least one Point");
|
|
3744
|
+
}
|
|
3745
|
+
if (a.type === "LineString" || b.type === "LineString") {
|
|
3746
|
+
const lineFirst = a.type === "LineString";
|
|
3747
|
+
const point2 = lineFirst ? b : a;
|
|
3748
|
+
const xy = pointCoordinates(point2);
|
|
3749
|
+
const projection = projectPointToLine(lineFirst ? a : b, point2);
|
|
3750
|
+
if (!xy || !projection)
|
|
3751
|
+
return null;
|
|
3752
|
+
const { coordinate, distance } = projection;
|
|
3753
|
+
return { start: lineFirst ? coordinate : xy, end: lineFirst ? xy : coordinate, distance };
|
|
3754
|
+
}
|
|
3755
|
+
const start = pointCoordinates(a);
|
|
3756
|
+
const end = pointCoordinates(b);
|
|
3757
|
+
return start && end ? { start, end, distance: Math.hypot(end[0] - start[0], end[1] - start[1]) } : null;
|
|
3758
|
+
}
|
|
3759
|
+
var ST_CLOSESTPOINT = /* @__PURE__ */ spatialFunction(
|
|
3760
|
+
"ST_ClosestPoint",
|
|
3761
|
+
[routePointKinds, routePointKinds],
|
|
3762
|
+
/* @__PURE__ */ nativeGeometryResult("geoarrow.point"),
|
|
3763
|
+
([a, b]) => {
|
|
3764
|
+
const pair = closestPair(a, b);
|
|
3765
|
+
return pair ? { type: "Point", coordinates: pair.start } : null;
|
|
3766
|
+
}
|
|
3767
|
+
);
|
|
3768
|
+
var ST_SHORTESTLINE = /* @__PURE__ */ spatialFunction(
|
|
3769
|
+
"ST_ShortestLine",
|
|
3770
|
+
[routePointKinds, routePointKinds],
|
|
3771
|
+
/* @__PURE__ */ nativeGeometryResult("geoarrow.linestring"),
|
|
3772
|
+
([a, b]) => {
|
|
3773
|
+
const pair = closestPair(a, b);
|
|
3774
|
+
return pair ? { type: "LineString", coordinates: [pair.start, pair.end] } : null;
|
|
3775
|
+
}
|
|
1239
3776
|
);
|
|
3777
|
+
var proximityKinds2 = [...pointKinds, ...lineKinds, ...polygonKinds];
|
|
3778
|
+
function withinDistance(a, b, radius) {
|
|
3779
|
+
if (radius < 0)
|
|
3780
|
+
throw new Error("ST_DWithin distance must be nonnegative");
|
|
3781
|
+
if (Number.isNaN(radius))
|
|
3782
|
+
return false;
|
|
3783
|
+
if (a.type === "Point" && (b.type === "Polygon" || b.type === "MultiPolygon"))
|
|
3784
|
+
return pointWithinPolygonDistance(a, b, radius);
|
|
3785
|
+
if (b.type === "Point" && (a.type === "Polygon" || a.type === "MultiPolygon"))
|
|
3786
|
+
return pointWithinPolygonDistance(b, a, radius);
|
|
3787
|
+
if ((a.type === "LineString" || a.type === "MultiLineString") && (b.type === "LineString" || b.type === "MultiLineString"))
|
|
3788
|
+
return linesWithinDistance(a, b, radius);
|
|
3789
|
+
if (a.type === "Point" && (b.type === "Point" || b.type === "LineString") || b.type === "Point" && a.type === "LineString") {
|
|
3790
|
+
const pair = closestPair(a, b);
|
|
3791
|
+
return pair !== null && pair.distance <= radius;
|
|
3792
|
+
}
|
|
3793
|
+
throw new Error(`ST_DWithin does not support ${a.type} and ${b.type}`);
|
|
3794
|
+
}
|
|
3795
|
+
function makeDWithin() {
|
|
3796
|
+
const spatial = spatialFunction("ST_DWithin", [proximityKinds2, proximityKinds2], new import_apache_arrow4.Bool(), ([a, b], radius) => withinDistance(a, b, radius), 1);
|
|
3797
|
+
return {
|
|
3798
|
+
...spatial,
|
|
3799
|
+
/** Checks concrete native pairs at binding; WKB pairs are checked per row. */
|
|
3800
|
+
resolvePrototype(fields) {
|
|
3801
|
+
var _a, _b;
|
|
3802
|
+
const result2 = spatial.resolvePrototype(fields);
|
|
3803
|
+
const a = (_a = fields[0]) == null ? void 0 : _a.metadata.get(EXTENSION_NAME);
|
|
3804
|
+
const b = (_b = fields[1]) == null ? void 0 : _b.metadata.get(EXTENSION_NAME);
|
|
3805
|
+
if (result2 && a && b && a !== "geoarrow.wkb" && b !== "geoarrow.wkb") {
|
|
3806
|
+
const linear = (encoding) => encoding === "geoarrow.linestring" || encoding === "geoarrow.multilinestring";
|
|
3807
|
+
const pointPair = a === "geoarrow.point" && b !== "geoarrow.multilinestring" || b === "geoarrow.point" && a !== "geoarrow.multilinestring";
|
|
3808
|
+
if (!pointPair && !(linear(a) && linear(b)))
|
|
3809
|
+
throw new Error(`ST_DWithin does not support ${a} and ${b}`);
|
|
3810
|
+
}
|
|
3811
|
+
return result2;
|
|
3812
|
+
}
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
var ST_DWITHIN = /* @__PURE__ */ makeDWithin();
|
|
1240
3816
|
var ST_INTERSECTS = /* @__PURE__ */ spatialFunction(
|
|
1241
3817
|
"ST_Intersects",
|
|
1242
3818
|
[
|
|
1243
3819
|
[...geometryTypes, "GeometryCollection"],
|
|
1244
3820
|
[...geometryTypes, "GeometryCollection"]
|
|
1245
3821
|
],
|
|
1246
|
-
/* @__PURE__ */ new
|
|
3822
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1247
3823
|
([a, b]) => planarIntersects(a, b)
|
|
1248
3824
|
);
|
|
3825
|
+
var ST_TOUCHES = /* @__PURE__ */ spatialFunction(
|
|
3826
|
+
"ST_Touches",
|
|
3827
|
+
[geometryTypes, geometryTypes],
|
|
3828
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
3829
|
+
([a, b]) => planarTouches(a, b)
|
|
3830
|
+
);
|
|
3831
|
+
var ST_LINEMERGE = /* @__PURE__ */ routeEditingFunction("ST_LineMerge", false, mergeRoute);
|
|
3832
|
+
var ST_SEGMENTIZE = /* @__PURE__ */ segmentizeFunction("ST_Segmentize");
|
|
1249
3833
|
var ST_LINEINTERPOLATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
1250
3834
|
"ST_LineInterpolatePoint",
|
|
1251
3835
|
[["LineString"]],
|
|
1252
|
-
/* @__PURE__ */ new
|
|
1253
|
-
([line], fraction) => (0,
|
|
3836
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
3837
|
+
([line], fraction) => (0, import_arrow7.writeWKB)(lineSubstring(line, fraction, fraction) ?? { type: "Point", coordinates: [] }, "xy"),
|
|
1254
3838
|
1
|
|
1255
3839
|
);
|
|
1256
3840
|
var ST_LINELOCATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
1257
3841
|
"ST_LineLocatePoint",
|
|
1258
3842
|
[["LineString"], pointKinds],
|
|
1259
|
-
/* @__PURE__ */ new
|
|
3843
|
+
/* @__PURE__ */ new import_apache_arrow4.Float64(),
|
|
1260
3844
|
([line, point2]) => lineLocatePoint(line, point2)
|
|
1261
3845
|
);
|
|
1262
3846
|
var ST_LINESUBSTRING = /* @__PURE__ */ spatialFunction(
|
|
1263
3847
|
"ST_LineSubstring",
|
|
1264
3848
|
[["LineString"]],
|
|
1265
|
-
/* @__PURE__ */ new
|
|
3849
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
1266
3850
|
([line], start, end) => {
|
|
1267
3851
|
const result2 = lineSubstring(line, start, end);
|
|
1268
|
-
return result2 ? (0,
|
|
3852
|
+
return result2 ? (0, import_arrow7.writeWKB)(result2, "xy") : null;
|
|
1269
3853
|
},
|
|
1270
3854
|
2
|
|
1271
3855
|
);
|
|
3856
|
+
var ST_ADDMEASURE = /* @__PURE__ */ spatialFunction(
|
|
3857
|
+
"ST_AddMeasure",
|
|
3858
|
+
[lineKinds],
|
|
3859
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
3860
|
+
([line], start, end) => {
|
|
3861
|
+
const result2 = addMeasure(line, line.dimension, start, end);
|
|
3862
|
+
return (0, import_arrow7.writeWKB)(result2.geometry, result2.dimension);
|
|
3863
|
+
},
|
|
3864
|
+
2,
|
|
3865
|
+
true
|
|
3866
|
+
);
|
|
3867
|
+
var ST_LOCATEALONG = /* @__PURE__ */ spatialFunction(
|
|
3868
|
+
"ST_LocateAlong",
|
|
3869
|
+
[lineKinds],
|
|
3870
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
3871
|
+
([line], measure) => {
|
|
3872
|
+
const dimension = measuredDimension(line.dimension);
|
|
3873
|
+
return (0, import_arrow7.writeWKB)(locateAlong(line, dimension, measure), dimension);
|
|
3874
|
+
},
|
|
3875
|
+
1,
|
|
3876
|
+
true
|
|
3877
|
+
);
|
|
3878
|
+
var ST_LOCATEBETWEEN = /* @__PURE__ */ spatialFunction(
|
|
3879
|
+
"ST_LocateBetween",
|
|
3880
|
+
[lineKinds],
|
|
3881
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
3882
|
+
([line], start, end) => {
|
|
3883
|
+
const dimension = measuredDimension(line.dimension);
|
|
3884
|
+
return (0, import_arrow7.writeWKB)(locateBetween(line, dimension, start, end), dimension);
|
|
3885
|
+
},
|
|
3886
|
+
2,
|
|
3887
|
+
true
|
|
3888
|
+
);
|
|
1272
3889
|
function geometrySRID(crs) {
|
|
1273
3890
|
let identifier = typeof crs === "string" ? normalizeCRSIdentifier(crs) : "";
|
|
1274
3891
|
if (crs && typeof crs === "object" && "id" in crs) {
|
|
@@ -1316,18 +3933,18 @@ function crsFunction(name) {
|
|
|
1316
3933
|
var _a;
|
|
1317
3934
|
if (fields.length !== (read ? 1 : 2))
|
|
1318
3935
|
return void 0;
|
|
1319
|
-
const metadata = fields[0] && ((_a = (0,
|
|
3936
|
+
const metadata = fields[0] && ((_a = (0, import_arrow7.getGeoArrowFieldInfo)(fields[0])) == null ? void 0 : _a.metadata);
|
|
1320
3937
|
const source = geometrySRID(metadata == null ? void 0 : metadata["crs"]);
|
|
1321
3938
|
const target = (literals == null ? void 0 : literals[1]) ?? 0;
|
|
1322
3939
|
if (!read && ((literals == null ? void 0 : literals[1]) === void 0 || !Number.isSafeInteger(target) || target < 0 || target > 998999))
|
|
1323
3940
|
throw new Error(name + " requires a constant integer SRID between 0 and 998999");
|
|
1324
3941
|
if (name === "ST_Transform" && (![4326, 3857].includes(source) || ![4326, 3857].includes(target)))
|
|
1325
3942
|
throw new Error("ST_Transform supports EPSG:4326 and EPSG:3857 source and target CRS");
|
|
1326
|
-
const implementation = spatialFunction(name, [[...geometryTypes, "GeometryCollection"]], read ? new
|
|
3943
|
+
const implementation = spatialFunction(name, [[...geometryTypes, "GeometryCollection"]], read ? new import_apache_arrow4.Int32() : new import_apache_arrow4.Binary(), ([geometry]) => {
|
|
1327
3944
|
if (read)
|
|
1328
3945
|
return source;
|
|
1329
3946
|
const output = name === "ST_Transform" && source !== target ? projectGeometry(geometry, (p) => target === 3857 ? EPSG4326ToEPSG3857([...p], { clampLatitude: false }) : EPSG3857ToLngLat([...p])) : geometry;
|
|
1330
|
-
return (0,
|
|
3947
|
+
return (0, import_arrow7.writeWKB)(output, "xy");
|
|
1331
3948
|
}, read ? 0 : 1).resolvePrototype(fields);
|
|
1332
3949
|
if (!read) {
|
|
1333
3950
|
const crsMetadata = { ...metadata };
|
|
@@ -1341,6 +3958,65 @@ function crsFunction(name) {
|
|
|
1341
3958
|
}
|
|
1342
3959
|
};
|
|
1343
3960
|
}
|
|
3961
|
+
function createSTTransform(engine) {
|
|
3962
|
+
return {
|
|
3963
|
+
kind: "scalar",
|
|
3964
|
+
name: "ST_Transform",
|
|
3965
|
+
prototypes: [],
|
|
3966
|
+
/** Resolves one source and target CRS for the entire projection. */
|
|
3967
|
+
resolvePrototype(fields, literals) {
|
|
3968
|
+
if (fields.length !== 2 || !fields[0])
|
|
3969
|
+
return void 0;
|
|
3970
|
+
const field = fields[0];
|
|
3971
|
+
const target = literals == null ? void 0 : literals[1];
|
|
3972
|
+
if (target === void 0 || !Number.isSafeInteger(target) || target <= 0 || target > 998999)
|
|
3973
|
+
throw new Error("ST_Transform requires a constant positive integer EPSG code");
|
|
3974
|
+
const info = (0, import_arrow7.getGeoArrowFieldInfo)(field);
|
|
3975
|
+
if (!info)
|
|
3976
|
+
throw new Error("ST_Transform requires a GeoArrow geometry column");
|
|
3977
|
+
if (info.metadata["edges"] === "spherical")
|
|
3978
|
+
throw new Error("ST_Transform requires planar geometry");
|
|
3979
|
+
const source = info.metadata["crs"];
|
|
3980
|
+
if (!(typeof source === "string" ? source.trim() : source && typeof source === "object" && !Array.isArray(source)))
|
|
3981
|
+
throw new Error("ST_Transform requires source CRS metadata");
|
|
3982
|
+
const to = "EPSG:" + target;
|
|
3983
|
+
const transform = engine.createProjection({
|
|
3984
|
+
from: source,
|
|
3985
|
+
to,
|
|
3986
|
+
enforceAxis: false
|
|
3987
|
+
});
|
|
3988
|
+
const metadata = JSON.stringify({ ...info.metadata, crs: to, crs_type: "authority_code" });
|
|
3989
|
+
const targetField = fields[1] ?? new import_apache_arrow4.Field("srid", new import_apache_arrow4.Int32(), false);
|
|
3990
|
+
if (!import_apache_arrow4.DataType.isInt(targetField.type) && !import_apache_arrow4.DataType.isFloat(targetField.type))
|
|
3991
|
+
throw new Error("ST_Transform requires a numeric SRID");
|
|
3992
|
+
const project = (coordinate) => {
|
|
3993
|
+
if (coordinate.every(Number.isNaN))
|
|
3994
|
+
return [...coordinate];
|
|
3995
|
+
const [x, y] = transform.projectSync([coordinate[0], coordinate[1]]);
|
|
3996
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
3997
|
+
throw new Error("ST_Transform produced nonfinite coordinates");
|
|
3998
|
+
return [x, y, ...coordinate.slice(2)];
|
|
3999
|
+
};
|
|
4000
|
+
if (info.encoding === "geoarrow.wkb") {
|
|
4001
|
+
const prototype = spatialFunction("ST_Transform", [[...geometryTypes, "GeometryCollection"]], new import_apache_arrow4.Binary(), ([geometry]) => (0, import_arrow7.writeWKB)(projectGeometry(geometry, project), "xy"), 1).resolvePrototype(fields);
|
|
4002
|
+
prototype.result.metadata.set(EXTENSION_METADATA, metadata);
|
|
4003
|
+
return prototype;
|
|
4004
|
+
}
|
|
4005
|
+
if (!geometryTypes.some((kind) => "geoarrow." + kind.toLowerCase() === info.encoding))
|
|
4006
|
+
throw new Error("ST_Transform requires WKB or a specialized native GeoArrow encoding");
|
|
4007
|
+
const outputMetadata = new Map(field.metadata);
|
|
4008
|
+
outputMetadata.set(EXTENSION_METADATA, metadata);
|
|
4009
|
+
return {
|
|
4010
|
+
arguments: [field, targetField],
|
|
4011
|
+
result: new import_apache_arrow4.Field("ST_Transform", field.type, field.nullable, outputMetadata),
|
|
4012
|
+
/** Maps native coordinate buffers directly, retaining topology and null rows. */
|
|
4013
|
+
evaluate([vector], { activeRows }) {
|
|
4014
|
+
return (0, import_arrow7.mapGeoArrowVectorCoordinates)(vector, (coordinate, row) => activeRows[row] ? project(coordinate) : coordinate, { field });
|
|
4015
|
+
}
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
};
|
|
4019
|
+
}
|
|
1344
4020
|
var ST_SRID = /* @__PURE__ */ crsFunction("ST_SRID");
|
|
1345
4021
|
var ST_SETSRID = /* @__PURE__ */ crsFunction("ST_SetSRID");
|
|
1346
4022
|
var ST_TRANSFORM = /* @__PURE__ */ crsFunction("ST_Transform");
|
|
@@ -1352,19 +4028,34 @@ function lineReduction(name, mode) {
|
|
|
1352
4028
|
/** Binds the geometry and any supplied numeric tolerance. */
|
|
1353
4029
|
resolvePrototype(fields) {
|
|
1354
4030
|
const numericArguments = mode === "removeRepeated" && fields.length === 1 ? 0 : 1;
|
|
1355
|
-
return spatialFunction(name, [lineKinds], new
|
|
4031
|
+
return spatialFunction(name, [lineKinds], new import_apache_arrow4.Binary(), ([line], tolerance = 0) => {
|
|
1356
4032
|
const result2 = reduceLineVertices(line, tolerance, mode);
|
|
1357
|
-
return result2 ? (0,
|
|
4033
|
+
return result2 ? (0, import_arrow7.writeWKB)(result2, "xy") : null;
|
|
1358
4034
|
}, numericArguments).resolvePrototype(fields);
|
|
1359
4035
|
}
|
|
1360
4036
|
};
|
|
1361
4037
|
}
|
|
1362
4038
|
var ST_REMOVEREPEATEDPOINTS = /* @__PURE__ */ lineReduction("ST_RemoveRepeatedPoints", "removeRepeated");
|
|
1363
4039
|
var ST_SIMPLIFY = /* @__PURE__ */ lineReduction("ST_Simplify", "simplify");
|
|
4040
|
+
var ST_SIMPLIFYPRESERVETOPOLOGY = {
|
|
4041
|
+
kind: "scalar",
|
|
4042
|
+
name: "ST_SimplifyPreserveTopology",
|
|
4043
|
+
prototypes: [],
|
|
4044
|
+
/** Preserves specialized native storage where the input schema identifies its family. */
|
|
4045
|
+
resolvePrototype(fields) {
|
|
4046
|
+
var _a;
|
|
4047
|
+
const encoding = (_a = fields[0]) == null ? void 0 : _a.metadata.get(EXTENSION_NAME);
|
|
4048
|
+
const native2 = encoding === "geoarrow.polygon" || encoding === "geoarrow.multipolygon";
|
|
4049
|
+
return spatialFunction("ST_SimplifyPreserveTopology", [polygonKinds], native2 ? nativeGeometryResult(encoding) : new import_apache_arrow4.Binary(), ([geometry], tolerance) => {
|
|
4050
|
+
const result2 = simplifyPolygonTopology(geometry, tolerance);
|
|
4051
|
+
return native2 ? result2 : (0, import_arrow7.writeWKB)(result2, "xy");
|
|
4052
|
+
}, 1).resolvePrototype(fields);
|
|
4053
|
+
}
|
|
4054
|
+
};
|
|
1364
4055
|
var ST_AZIMUTH = /* @__PURE__ */ spatialFunction(
|
|
1365
4056
|
"ST_Azimuth",
|
|
1366
4057
|
[pointKinds, pointKinds],
|
|
1367
|
-
/* @__PURE__ */ new
|
|
4058
|
+
/* @__PURE__ */ new import_apache_arrow4.Float64(),
|
|
1368
4059
|
([a, b]) => {
|
|
1369
4060
|
const p = pointCoordinates(a);
|
|
1370
4061
|
const q = pointCoordinates(b);
|
|
@@ -1381,26 +4072,26 @@ var ST_AZIMUTH = /* @__PURE__ */ spatialFunction(
|
|
|
1381
4072
|
var ST_AREA = /* @__PURE__ */ spatialFunction(
|
|
1382
4073
|
"ST_Area",
|
|
1383
4074
|
[geometryTypes],
|
|
1384
|
-
/* @__PURE__ */ new
|
|
4075
|
+
/* @__PURE__ */ new import_apache_arrow4.Float64(),
|
|
1385
4076
|
([geometry]) => planarArea(geometry)
|
|
1386
4077
|
);
|
|
1387
4078
|
var ST_LENGTH = /* @__PURE__ */ spatialFunction(
|
|
1388
4079
|
"ST_Length",
|
|
1389
|
-
[geometryTypes],
|
|
1390
|
-
/* @__PURE__ */ new
|
|
4080
|
+
[[...geometryTypes, "GeometryCollection"]],
|
|
4081
|
+
/* @__PURE__ */ new import_apache_arrow4.Float64(),
|
|
1391
4082
|
([geometry]) => planarLength(geometry)
|
|
1392
4083
|
);
|
|
1393
4084
|
var ST_CENTROID = /* @__PURE__ */ spatialFunction(
|
|
1394
4085
|
"ST_Centroid",
|
|
1395
4086
|
[geometryTypes],
|
|
1396
|
-
/* @__PURE__ */ new
|
|
1397
|
-
([geometry]) => (0,
|
|
4087
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
4088
|
+
([geometry]) => (0, import_arrow7.writeWKB)(planarCentroid(geometry), "xy")
|
|
1398
4089
|
);
|
|
1399
4090
|
var inspectionKinds = [[...geometryTypes, "GeometryCollection"]];
|
|
1400
4091
|
var ST_NPOINTS = /* @__PURE__ */ spatialFunction(
|
|
1401
4092
|
"ST_NPoints",
|
|
1402
4093
|
inspectionKinds,
|
|
1403
|
-
/* @__PURE__ */ new
|
|
4094
|
+
/* @__PURE__ */ new import_apache_arrow4.Int32(),
|
|
1404
4095
|
([g]) => vertexCount(g),
|
|
1405
4096
|
0,
|
|
1406
4097
|
true
|
|
@@ -1408,7 +4099,7 @@ var ST_NPOINTS = /* @__PURE__ */ spatialFunction(
|
|
|
1408
4099
|
var ST_NUMGEOMETRIES = /* @__PURE__ */ spatialFunction(
|
|
1409
4100
|
"ST_NumGeometries",
|
|
1410
4101
|
inspectionKinds,
|
|
1411
|
-
/* @__PURE__ */ new
|
|
4102
|
+
/* @__PURE__ */ new import_apache_arrow4.Int32(),
|
|
1412
4103
|
([g]) => memberCount(g),
|
|
1413
4104
|
0,
|
|
1414
4105
|
true
|
|
@@ -1416,7 +4107,7 @@ var ST_NUMGEOMETRIES = /* @__PURE__ */ spatialFunction(
|
|
|
1416
4107
|
var ST_ISEMPTY = /* @__PURE__ */ spatialFunction(
|
|
1417
4108
|
"ST_IsEmpty",
|
|
1418
4109
|
inspectionKinds,
|
|
1419
|
-
/* @__PURE__ */ new
|
|
4110
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
1420
4111
|
([g]) => !vertexCount(g),
|
|
1421
4112
|
0,
|
|
1422
4113
|
true
|
|
@@ -1424,7 +4115,7 @@ var ST_ISEMPTY = /* @__PURE__ */ spatialFunction(
|
|
|
1424
4115
|
var ST_GEOMETRYTYPE = /* @__PURE__ */ spatialFunction(
|
|
1425
4116
|
"ST_GeometryType",
|
|
1426
4117
|
inspectionKinds,
|
|
1427
|
-
/* @__PURE__ */ new
|
|
4118
|
+
/* @__PURE__ */ new import_apache_arrow4.Utf8(),
|
|
1428
4119
|
([g]) => "ST_" + g.type,
|
|
1429
4120
|
0,
|
|
1430
4121
|
true
|
|
@@ -1432,19 +4123,19 @@ var ST_GEOMETRYTYPE = /* @__PURE__ */ spatialFunction(
|
|
|
1432
4123
|
var ST_FORCE2D = /* @__PURE__ */ spatialFunction(
|
|
1433
4124
|
"ST_Force2D",
|
|
1434
4125
|
inspectionKinds,
|
|
1435
|
-
/* @__PURE__ */ new
|
|
1436
|
-
([g]) => (0,
|
|
4126
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
4127
|
+
([g]) => (0, import_arrow7.writeWKB)(g, "xy"),
|
|
1437
4128
|
0,
|
|
1438
4129
|
true
|
|
1439
4130
|
);
|
|
1440
4131
|
var ST_GEOMETRYN = /* @__PURE__ */ spatialFunction(
|
|
1441
4132
|
"ST_GeometryN",
|
|
1442
4133
|
inspectionKinds,
|
|
1443
|
-
/* @__PURE__ */ new
|
|
4134
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
1444
4135
|
([g], position) => {
|
|
1445
4136
|
var _a;
|
|
1446
4137
|
const part = geometryMember(g, position);
|
|
1447
|
-
return part ? ((_a = g.members) == null ? void 0 : _a[position - 1]) ?? (0,
|
|
4138
|
+
return part ? ((_a = g.members) == null ? void 0 : _a[position - 1]) ?? (0, import_arrow7.writeWKB)(part, g.dimension ?? "xy") : null;
|
|
1448
4139
|
},
|
|
1449
4140
|
1,
|
|
1450
4141
|
true
|
|
@@ -1455,8 +4146,8 @@ var ST_MAKELINE = /* @__PURE__ */ spatialFunction(
|
|
|
1455
4146
|
["Point", "MultiPoint", "LineString"],
|
|
1456
4147
|
["Point", "MultiPoint", "LineString"]
|
|
1457
4148
|
],
|
|
1458
|
-
/* @__PURE__ */ new
|
|
1459
|
-
(geometries) => (0,
|
|
4149
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
4150
|
+
(geometries) => (0, import_arrow7.writeWKB)(makeLine(geometries), "xy")
|
|
1460
4151
|
);
|
|
1461
4152
|
var ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
1462
4153
|
"ST_Collect",
|
|
@@ -1464,24 +4155,47 @@ var ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
|
1464
4155
|
[...geometryTypes, "GeometryCollection"],
|
|
1465
4156
|
[...geometryTypes, "GeometryCollection"]
|
|
1466
4157
|
],
|
|
1467
|
-
/* @__PURE__ */ new
|
|
1468
|
-
([a, b]) => a ? (0,
|
|
4158
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
4159
|
+
([a, b]) => a ? (0, import_arrow7.writeWKB)(b ? collectPair(a, b) : a, "xy") : null,
|
|
1469
4160
|
0,
|
|
1470
4161
|
false,
|
|
1471
4162
|
true
|
|
1472
4163
|
);
|
|
4164
|
+
function polygonValidityReason(geometry) {
|
|
4165
|
+
if (geometry.type === "Polygon")
|
|
4166
|
+
return (0, import_polygon5.getPolygonValidityReason)([geometry.coordinates]);
|
|
4167
|
+
if (geometry.type === "MultiPolygon")
|
|
4168
|
+
return (0, import_polygon5.getPolygonValidityReason)(geometry.coordinates);
|
|
4169
|
+
throw new Error("Expected polygonal geometry");
|
|
4170
|
+
}
|
|
4171
|
+
var ST_ISVALID = /* @__PURE__ */ spatialFunction(
|
|
4172
|
+
"ST_IsValid",
|
|
4173
|
+
[polygonKinds],
|
|
4174
|
+
/* @__PURE__ */ new import_apache_arrow4.Bool(),
|
|
4175
|
+
([polygon]) => polygonValidityReason(polygon) === void 0,
|
|
4176
|
+
0,
|
|
4177
|
+
true
|
|
4178
|
+
);
|
|
4179
|
+
var ST_ISVALIDREASON = /* @__PURE__ */ spatialFunction(
|
|
4180
|
+
"ST_IsValidReason",
|
|
4181
|
+
[polygonKinds],
|
|
4182
|
+
/* @__PURE__ */ new import_apache_arrow4.Utf8(),
|
|
4183
|
+
([polygon]) => polygonValidityReason(polygon) ?? "Valid Geometry",
|
|
4184
|
+
0,
|
|
4185
|
+
true
|
|
4186
|
+
);
|
|
1473
4187
|
var ST_POINTONSURFACE = /* @__PURE__ */ spatialFunction(
|
|
1474
4188
|
"ST_PointOnSurface",
|
|
1475
4189
|
[polygonKinds],
|
|
1476
|
-
/* @__PURE__ */
|
|
1477
|
-
([polygon]) =>
|
|
4190
|
+
/* @__PURE__ */ nativeGeometryResult("geoarrow.point"),
|
|
4191
|
+
([polygon]) => planarPolygonPointOnSurface(polygon)
|
|
1478
4192
|
);
|
|
1479
4193
|
function makeEnvelopeFunction() {
|
|
1480
4194
|
const envelopeFunction = spatialFunction(
|
|
1481
4195
|
"ST_Envelope",
|
|
1482
4196
|
[[...geometryTypes, "GeometryCollection"]],
|
|
1483
|
-
/* @__PURE__ */ new
|
|
1484
|
-
([geometry]) => (0,
|
|
4197
|
+
/* @__PURE__ */ new import_apache_arrow4.Binary(),
|
|
4198
|
+
([geometry]) => (0, import_arrow7.writeWKB)(planarEnvelope(geometry), "xy")
|
|
1485
4199
|
);
|
|
1486
4200
|
return {
|
|
1487
4201
|
...envelopeFunction,
|
|
@@ -1489,7 +4203,7 @@ function makeEnvelopeFunction() {
|
|
|
1489
4203
|
resolvePrototype(fields) {
|
|
1490
4204
|
const prototype = envelopeFunction.resolvePrototype(fields);
|
|
1491
4205
|
const field = fields[0];
|
|
1492
|
-
if (!prototype || !field ||
|
|
4206
|
+
if (!prototype || !field || import_apache_arrow4.DataType.isBinary(field.type) || import_apache_arrow4.DataType.isLargeBinary(field.type)) {
|
|
1493
4207
|
return prototype;
|
|
1494
4208
|
}
|
|
1495
4209
|
return {
|
|
@@ -1497,17 +4211,17 @@ function makeEnvelopeFunction() {
|
|
|
1497
4211
|
/** Evaluates active rows and preserves the type of empty geometries. */
|
|
1498
4212
|
evaluate([vector], { activeRows, length }) {
|
|
1499
4213
|
const column2 = readActiveGeoArrowColumn(vector, field, activeRows);
|
|
1500
|
-
const
|
|
4214
|
+
const bounds2 = (0, import_arrow7.getGeoArrowRowBounds)(column2);
|
|
1501
4215
|
const values = Array.from({ length }, (_, row) => {
|
|
1502
4216
|
if (!activeRows[row])
|
|
1503
4217
|
return null;
|
|
1504
|
-
const box =
|
|
4218
|
+
const box = bounds2[row];
|
|
1505
4219
|
if (box)
|
|
1506
|
-
return (0,
|
|
1507
|
-
const [geometry] = (0,
|
|
1508
|
-
return geometry ? (0,
|
|
4220
|
+
return (0, import_arrow7.writeWKB)(envelopeFromBounds(box), "xy");
|
|
4221
|
+
const [geometry] = (0, import_arrow7.materializeGeoArrowRows)((0, import_arrow7.getGeoArrowColumnView)(column2, row, row + 1));
|
|
4222
|
+
return geometry ? (0, import_arrow7.writeWKB)(geometry, "xy") : null;
|
|
1509
4223
|
});
|
|
1510
|
-
return (0,
|
|
4224
|
+
return (0, import_apache_arrow4.vectorFromArray)(values, new import_apache_arrow4.Binary());
|
|
1511
4225
|
}
|
|
1512
4226
|
};
|
|
1513
4227
|
}
|
|
@@ -1524,26 +4238,26 @@ var ST_EXTENT = {
|
|
|
1524
4238
|
throw new Error("ST_Extent requires one geometry column");
|
|
1525
4239
|
ST_ENVELOPE.resolvePrototype([field]);
|
|
1526
4240
|
return {
|
|
1527
|
-
outputField: new
|
|
4241
|
+
outputField: new import_apache_arrow4.Field("ST_Extent", new import_apache_arrow4.FixedSizeList(4, new import_apache_arrow4.Field("value", new import_apache_arrow4.Float64(), false)), true),
|
|
1528
4242
|
/** Creates independent bounds for this group. */
|
|
1529
4243
|
createAccumulator() {
|
|
1530
|
-
let
|
|
4244
|
+
let bounds2 = null;
|
|
1531
4245
|
function include(box) {
|
|
1532
|
-
if (!
|
|
1533
|
-
|
|
4246
|
+
if (!bounds2)
|
|
4247
|
+
bounds2 = [...box];
|
|
1534
4248
|
else {
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
4249
|
+
bounds2[0] = Math.min(bounds2[0], box[0]);
|
|
4250
|
+
bounds2[1] = Math.min(bounds2[1], box[1]);
|
|
4251
|
+
bounds2[2] = Math.max(bounds2[2], box[2]);
|
|
4252
|
+
bounds2[3] = Math.max(bounds2[3], box[3]);
|
|
1539
4253
|
}
|
|
1540
4254
|
}
|
|
1541
4255
|
return {
|
|
1542
4256
|
/** Accumulates nonempty geometry bounds from one record batch. */
|
|
1543
4257
|
update([vector], { length }) {
|
|
1544
|
-
if (!
|
|
1545
|
-
const column2 = (0,
|
|
1546
|
-
const box = (0,
|
|
4258
|
+
if (!import_apache_arrow4.DataType.isBinary(field.type) && !import_apache_arrow4.DataType.isLargeBinary(field.type)) {
|
|
4259
|
+
const column2 = (0, import_arrow7.makeGeoArrowColumnFromArrowVector)(vector, { field });
|
|
4260
|
+
const box = (0, import_arrow7.getGeoArrowBounds)(column2);
|
|
1547
4261
|
if (box)
|
|
1548
4262
|
include(box);
|
|
1549
4263
|
return;
|
|
@@ -1565,7 +4279,7 @@ var ST_EXTENT = {
|
|
|
1565
4279
|
include(box);
|
|
1566
4280
|
},
|
|
1567
4281
|
/** Returns a detached snapshot, or null for a group without coordinates. */
|
|
1568
|
-
finalize: () =>
|
|
4282
|
+
finalize: () => bounds2 && [...bounds2]
|
|
1569
4283
|
};
|
|
1570
4284
|
}
|
|
1571
4285
|
};
|
|
@@ -1586,21 +4300,32 @@ var POSTGIS_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
|
1586
4300
|
ST_MAKEENVELOPE,
|
|
1587
4301
|
ST_DISTANCE,
|
|
1588
4302
|
ST_DWITHIN,
|
|
4303
|
+
ST_CLOSESTPOINT,
|
|
4304
|
+
ST_SHORTESTLINE,
|
|
1589
4305
|
ST_INTERSECTS,
|
|
4306
|
+
ST_TOUCHES,
|
|
1590
4307
|
ST_SRID,
|
|
1591
4308
|
ST_SETSRID,
|
|
1592
4309
|
ST_TRANSFORM,
|
|
1593
4310
|
ST_REMOVEREPEATEDPOINTS,
|
|
1594
4311
|
ST_SIMPLIFY,
|
|
4312
|
+
ST_SIMPLIFYPRESERVETOPOLOGY,
|
|
1595
4313
|
ST_AZIMUTH,
|
|
1596
4314
|
ST_MAKEPOINT,
|
|
1597
4315
|
ST_TILEENVELOPE,
|
|
1598
4316
|
ST_AREA,
|
|
1599
4317
|
ST_LENGTH,
|
|
4318
|
+
ST_LINEMERGE,
|
|
4319
|
+
ST_SEGMENTIZE,
|
|
1600
4320
|
ST_LINEINTERPOLATEPOINT,
|
|
1601
4321
|
ST_LINELOCATEPOINT,
|
|
1602
4322
|
ST_LINESUBSTRING,
|
|
4323
|
+
ST_ADDMEASURE,
|
|
4324
|
+
ST_LOCATEALONG,
|
|
4325
|
+
ST_LOCATEBETWEEN,
|
|
1603
4326
|
ST_POINTONSURFACE,
|
|
4327
|
+
ST_ISVALID,
|
|
4328
|
+
ST_ISVALIDREASON,
|
|
1604
4329
|
ST_CENTROID,
|
|
1605
4330
|
ST_NPOINTS,
|
|
1606
4331
|
ST_NUMGEOMETRIES,
|