@math.gl/geospatial 5.0.0 → 5.0.1
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/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 +13 -1
- package/dist/linear-referencing.d.ts.map +1 -1
- package/dist/linear-referencing.js +29 -9
- 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 +141 -0
- package/dist/polygon-simplification.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 +11 -0
- package/dist/spatial-planar-intersects.d.ts.map +1 -1
- package/dist/spatial-planar-intersects.js +20 -12
- 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 +13 -2
- package/dist/spatial-sql.d.ts.map +1 -1
- package/dist/spatial-sql.js +30 -12
- 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 +13 -0
- package/dist/spatial-touches.d.ts.map +1 -0
- package/dist/spatial-touches.js +192 -0
- package/dist/spatial-touches.js.map +1 -0
- package/dist/st-functions.cjs +2411 -112
- package/dist/st-functions.cjs.map +3 -3
- package/dist/st-functions.d.ts +67 -2
- package/dist/st-functions.d.ts.map +1 -1
- package/dist/st-functions.js +195 -12
- package/dist/st-functions.js.map +1 -1
- package/dist/st-geodesic-functions.d.ts +33 -0
- package/dist/st-geodesic-functions.d.ts.map +1 -0
- package/dist/st-geodesic-functions.js +84 -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 +621 -0
- package/dist/st-overlay-functions.cjs.map +6 -0
- package/dist/st-overlay-functions.d.ts +36 -0
- package/dist/st-overlay-functions.d.ts.map +1 -0
- package/dist/st-overlay-functions.js +183 -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 +21 -6
- package/src/line-simplification.ts +4 -16
- package/src/linear-referencing.ts +44 -16
- package/src/measure-referencing.ts +165 -0
- package/src/polygon-simplification.ts +185 -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 +147 -0
- package/src/spatial-planar-intersects.ts +21 -15
- package/src/spatial-planar.ts +20 -1
- package/src/spatial-polygon-overlay.ts +30 -0
- package/src/spatial-sql.ts +47 -12
- package/src/spatial-subdivision.ts +75 -0
- package/src/spatial-touches.ts +218 -0
- package/src/st-functions.ts +283 -15
- package/src/st-geodesic-functions.ts +121 -0
- package/src/st-hull-functions.ts +25 -0
- package/src/st-overlay-functions.ts +244 -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)
|
|
@@ -14,15 +16,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
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,6 +46,9 @@ __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,
|
|
36
52
|
ST_GEOMETRYN: () => ST_GEOMETRYN,
|
|
37
53
|
ST_GEOMETRYTYPE: () => ST_GEOMETRYTYPE,
|
|
38
54
|
ST_INTERSECTS: () => ST_INTERSECTS,
|
|
@@ -41,6 +57,8 @@ __export(st_functions_exports, {
|
|
|
41
57
|
ST_LINEINTERPOLATEPOINT: () => ST_LINEINTERPOLATEPOINT,
|
|
42
58
|
ST_LINELOCATEPOINT: () => ST_LINELOCATEPOINT,
|
|
43
59
|
ST_LINESUBSTRING: () => ST_LINESUBSTRING,
|
|
60
|
+
ST_LOCATEALONG: () => ST_LOCATEALONG,
|
|
61
|
+
ST_LOCATEBETWEEN: () => ST_LOCATEBETWEEN,
|
|
44
62
|
ST_M: () => ST_M,
|
|
45
63
|
ST_MAKEENVELOPE: () => ST_MAKEENVELOPE,
|
|
46
64
|
ST_MAKELINE: () => ST_MAKELINE,
|
|
@@ -51,24 +69,35 @@ __export(st_functions_exports, {
|
|
|
51
69
|
ST_POINTONSURFACE: () => ST_POINTONSURFACE,
|
|
52
70
|
ST_REMOVEREPEATEDPOINTS: () => ST_REMOVEREPEATEDPOINTS,
|
|
53
71
|
ST_SETSRID: () => ST_SETSRID,
|
|
72
|
+
ST_SHORTESTLINE: () => ST_SHORTESTLINE,
|
|
54
73
|
ST_SIMPLIFY: () => ST_SIMPLIFY,
|
|
74
|
+
ST_SIMPLIFYPRESERVETOPOLOGY: () => ST_SIMPLIFYPRESERVETOPOLOGY,
|
|
55
75
|
ST_SRID: () => ST_SRID,
|
|
56
76
|
ST_STARTPOINT: () => ST_STARTPOINT,
|
|
57
77
|
ST_TILEENVELOPE: () => ST_TILEENVELOPE,
|
|
78
|
+
ST_TOUCHES: () => ST_TOUCHES,
|
|
58
79
|
ST_TRANSFORM: () => ST_TRANSFORM,
|
|
59
80
|
ST_WITHIN: () => ST_WITHIN,
|
|
60
81
|
ST_X: () => ST_X,
|
|
61
82
|
ST_Y: () => ST_Y,
|
|
62
|
-
ST_Z: () => ST_Z
|
|
83
|
+
ST_Z: () => ST_Z,
|
|
84
|
+
createSTTransform: () => createSTTransform
|
|
63
85
|
});
|
|
64
86
|
module.exports = __toCommonJS(st_functions_exports);
|
|
65
|
-
var
|
|
87
|
+
var import_apache_arrow3 = require("apache-arrow");
|
|
66
88
|
var import_arrow4 = require("@math.gl/core/arrow");
|
|
67
89
|
|
|
68
90
|
// dist/spatial-planar-intersects.js
|
|
69
91
|
var import_robust_predicates = require("robust-predicates");
|
|
70
92
|
|
|
71
93
|
// dist/spatial-planar.js
|
|
94
|
+
function distanceToPlanarSegment(p, a, b) {
|
|
95
|
+
const dx = b[0] - a[0], dy = b[1] - a[1];
|
|
96
|
+
const length = Math.hypot(dx, dy);
|
|
97
|
+
const px = p[0] - a[0], py = p[1] - a[1];
|
|
98
|
+
const t = length ? Math.max(0, Math.min(1, (px * (dx / length) + py * (dy / length)) / length)) : 0;
|
|
99
|
+
return Math.hypot(px - t * dx, py - t * dy);
|
|
100
|
+
}
|
|
72
101
|
function visitSegments(path, closed, visit) {
|
|
73
102
|
for (let i = 1; i < path.length; i++)
|
|
74
103
|
visit(path[i - 1], path[i]);
|
|
@@ -130,13 +159,15 @@ function polygonMoments(rings, origin) {
|
|
|
130
159
|
return total;
|
|
131
160
|
}
|
|
132
161
|
function planarArea(geometry) {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
162
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : [];
|
|
163
|
+
return polygons3.reduce((total, rings) => {
|
|
135
164
|
var _a;
|
|
136
165
|
return total + polygonMoments(rings, ((_a = rings[0]) == null ? void 0 : _a[0]) ?? [0, 0]).weight;
|
|
137
166
|
}, 0);
|
|
138
167
|
}
|
|
139
168
|
function planarLength(geometry) {
|
|
169
|
+
if (geometry.type === "GeometryCollection")
|
|
170
|
+
return geometry.geometries.reduce((sum, part) => sum + planarLength(part), 0);
|
|
140
171
|
if (geometry.type !== "LineString" && geometry.type !== "MultiLineString")
|
|
141
172
|
return 0;
|
|
142
173
|
let length = 0;
|
|
@@ -148,7 +179,7 @@ function planarLength(geometry) {
|
|
|
148
179
|
return length;
|
|
149
180
|
}
|
|
150
181
|
function planarCentroid(geometry) {
|
|
151
|
-
const
|
|
182
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : [];
|
|
152
183
|
const points2 = { x: 0, y: 0, weight: 0 };
|
|
153
184
|
const lines = { x: 0, y: 0, weight: 0 };
|
|
154
185
|
const areas = { x: 0, y: 0, weight: 0 };
|
|
@@ -160,7 +191,7 @@ function planarCentroid(geometry) {
|
|
|
160
191
|
const ox = origin[0];
|
|
161
192
|
const oy = origin[1];
|
|
162
193
|
if (geometry.type !== "MultiPoint") {
|
|
163
|
-
visitSegments(path,
|
|
194
|
+
visitSegments(path, polygons3.length > 0, (a, b) => {
|
|
164
195
|
const weight2 = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
165
196
|
lines.x += (a[0] - ox + (b[0] - ox)) / 2 * weight2;
|
|
166
197
|
lines.y += (a[1] - oy + (b[1] - oy)) / 2 * weight2;
|
|
@@ -175,7 +206,7 @@ function planarCentroid(geometry) {
|
|
|
175
206
|
});
|
|
176
207
|
if (!origin)
|
|
177
208
|
return { type: "Point", coordinates: [] };
|
|
178
|
-
for (const polygon of
|
|
209
|
+
for (const polygon of polygons3) {
|
|
179
210
|
const part = polygonMoments(polygon, origin);
|
|
180
211
|
areas.x += part.x;
|
|
181
212
|
areas.y += part.y;
|
|
@@ -235,10 +266,10 @@ function envelopeFromBounds(bounds) {
|
|
|
235
266
|
};
|
|
236
267
|
}
|
|
237
268
|
function planarPolygonPointOnSurface(geometry) {
|
|
238
|
-
const
|
|
269
|
+
const polygons3 = geometry.type === "MultiPolygon" ? geometry.coordinates : geometry.type === "Polygon" ? [geometry.coordinates] : [];
|
|
239
270
|
let coordinates = [];
|
|
240
271
|
let widest = -1;
|
|
241
|
-
for (const rings of
|
|
272
|
+
for (const rings of polygons3) {
|
|
242
273
|
const shell = rings[0];
|
|
243
274
|
if (!(shell == null ? void 0 : shell.length))
|
|
244
275
|
continue;
|
|
@@ -324,15 +355,12 @@ function anyEdge(path, closed, match) {
|
|
|
324
355
|
}
|
|
325
356
|
return false;
|
|
326
357
|
}
|
|
327
|
-
function
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return point2[0] === geometry.coordinates[0] && point2[1] === geometry.coordinates[1];
|
|
332
|
-
if (geometry.type === "LineString")
|
|
333
|
-
return anyEdge(geometry.coordinates, false, (a, b) => inBounds(point2, a, b) && !side(a, b, point2));
|
|
358
|
+
function pointOnSegment(point2, a, b) {
|
|
359
|
+
return inBounds(point2, a, b) && side(a, b, point2) === 0;
|
|
360
|
+
}
|
|
361
|
+
function locatePointInPolygon(point2, rings) {
|
|
334
362
|
let inside = false;
|
|
335
|
-
for (const ring of
|
|
363
|
+
for (const ring of rings) {
|
|
336
364
|
if (anyEdge(ring, true, (a, b) => {
|
|
337
365
|
const orientation = side(a, b, point2);
|
|
338
366
|
if (!orientation && inBounds(point2, a, b))
|
|
@@ -341,9 +369,18 @@ function meetsPoint(point2, geometry) {
|
|
|
341
369
|
inside = !inside;
|
|
342
370
|
return false;
|
|
343
371
|
}))
|
|
344
|
-
return
|
|
372
|
+
return 0;
|
|
345
373
|
}
|
|
346
|
-
return inside;
|
|
374
|
+
return inside ? 1 : -1;
|
|
375
|
+
}
|
|
376
|
+
function meetsPoint(point2, geometry) {
|
|
377
|
+
if (!Number.isFinite(point2[0]) || !Number.isFinite(point2[1]))
|
|
378
|
+
return false;
|
|
379
|
+
if (geometry.type === "Point")
|
|
380
|
+
return point2[0] === geometry.coordinates[0] && point2[1] === geometry.coordinates[1];
|
|
381
|
+
if (geometry.type === "LineString")
|
|
382
|
+
return anyEdge(geometry.coordinates, false, (a, b) => pointOnSegment(point2, a, b));
|
|
383
|
+
return locatePointInPolygon(point2, geometry.coordinates) >= 0;
|
|
347
384
|
}
|
|
348
385
|
function primitivesMeet(a, b) {
|
|
349
386
|
if (a.type === "Point")
|
|
@@ -372,7 +409,283 @@ function planarIntersects(a, b) {
|
|
|
372
409
|
return false;
|
|
373
410
|
}
|
|
374
411
|
|
|
412
|
+
// dist/spatial-touches.js
|
|
413
|
+
var import_polygon_clipping = __toESM(require("polygon-clipping"), 1);
|
|
414
|
+
|
|
415
|
+
// dist/spatial-polygon-overlay.js
|
|
416
|
+
function polygonSet(geometry) {
|
|
417
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.type === "MultiPolygon" ? geometry.coordinates : void 0;
|
|
418
|
+
if (!polygons3)
|
|
419
|
+
throw new Error("Polygon overlay requires Polygon or MultiPolygon input");
|
|
420
|
+
return polygons3.filter((polygon) => {
|
|
421
|
+
var _a;
|
|
422
|
+
return (_a = polygon[0]) == null ? void 0 : _a.length;
|
|
423
|
+
}).map((polygon) => polygon.filter((ring) => ring.length).map((ring) => ring.map(([x, y]) => {
|
|
424
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
425
|
+
throw new Error("Polygon overlay requires finite coordinates");
|
|
426
|
+
return [x, y];
|
|
427
|
+
})));
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// dist/spatial-touches.js
|
|
431
|
+
function isPointLike(geometry) {
|
|
432
|
+
return geometry.type === "Point" || geometry.type === "MultiPoint";
|
|
433
|
+
}
|
|
434
|
+
function isLinear(geometry) {
|
|
435
|
+
return geometry.type === "LineString" || geometry.type === "MultiLineString";
|
|
436
|
+
}
|
|
437
|
+
function isAreal(geometry) {
|
|
438
|
+
return geometry.type === "Polygon" || geometry.type === "MultiPolygon";
|
|
439
|
+
}
|
|
440
|
+
function paths(geometry) {
|
|
441
|
+
return geometry.type === "LineString" ? [geometry.coordinates] : geometry.coordinates;
|
|
442
|
+
}
|
|
443
|
+
function polygons(geometry) {
|
|
444
|
+
return geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
445
|
+
}
|
|
446
|
+
function samePoint(a, b) {
|
|
447
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
448
|
+
}
|
|
449
|
+
function pointKey(point2) {
|
|
450
|
+
return `${point2[0]}/${point2[1]}`;
|
|
451
|
+
}
|
|
452
|
+
function* edges(components, closed = false) {
|
|
453
|
+
for (const path of components) {
|
|
454
|
+
for (let i = closed ? 0 : 1; i < path.length; i++) {
|
|
455
|
+
const a = path[i ? i - 1 : path.length - 1];
|
|
456
|
+
const b = path[i];
|
|
457
|
+
if (!samePoint(a, b))
|
|
458
|
+
yield [a, b];
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function lineBoundary(components) {
|
|
463
|
+
const boundary = /* @__PURE__ */ new Map();
|
|
464
|
+
for (const component of components) {
|
|
465
|
+
if (!component.length)
|
|
466
|
+
continue;
|
|
467
|
+
for (const point2 of [component[0], component[component.length - 1]]) {
|
|
468
|
+
const key = pointKey(point2);
|
|
469
|
+
if (!boundary.delete(key))
|
|
470
|
+
boundary.set(key, point2);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return boundary;
|
|
474
|
+
}
|
|
475
|
+
function endpointContacts(a, b) {
|
|
476
|
+
const contacts = [];
|
|
477
|
+
for (const [endpoints, other] of [
|
|
478
|
+
[a, b],
|
|
479
|
+
[b, a]
|
|
480
|
+
]) {
|
|
481
|
+
for (const point2 of endpoints) {
|
|
482
|
+
if (pointOnSegment(point2, ...other) && !contacts.some((value) => samePoint(value, point2)))
|
|
483
|
+
contacts.push(point2);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return contacts;
|
|
487
|
+
}
|
|
488
|
+
function hasBoundaryCrossing(boundary, a, b) {
|
|
489
|
+
for (const point2 of boundary.values()) {
|
|
490
|
+
if (pointOnSegment(point2, ...a) && pointOnSegment(point2, ...b))
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
function lineInteriorsMeet(a, b) {
|
|
496
|
+
const aPaths = paths(a);
|
|
497
|
+
const bPaths = paths(b);
|
|
498
|
+
const aBoundary = lineBoundary(aPaths);
|
|
499
|
+
const bBoundary = lineBoundary(bPaths);
|
|
500
|
+
const bEdges = [...edges(bPaths)];
|
|
501
|
+
for (const left of edges(aPaths)) {
|
|
502
|
+
for (const right of bEdges) {
|
|
503
|
+
if (!segmentsMeet(...left, ...right))
|
|
504
|
+
continue;
|
|
505
|
+
const contacts = endpointContacts(left, right);
|
|
506
|
+
if (contacts.length > 1)
|
|
507
|
+
return true;
|
|
508
|
+
if (contacts.length) {
|
|
509
|
+
const key = pointKey(contacts[0]);
|
|
510
|
+
if (!aBoundary.has(key) && !bBoundary.has(key))
|
|
511
|
+
return true;
|
|
512
|
+
} else if (!hasBoundaryCrossing(aBoundary, left, right) && !hasBoundaryCrossing(bBoundary, left, right)) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
function insideArea(point2, areas) {
|
|
520
|
+
return areas.some((rings) => locatePointInPolygon(point2, rings) === 1);
|
|
521
|
+
}
|
|
522
|
+
function parameter(point2, [a, b]) {
|
|
523
|
+
const dx = b[0] - a[0];
|
|
524
|
+
const dy = b[1] - a[1];
|
|
525
|
+
return Math.abs(dx) >= Math.abs(dy) ? (point2[0] - a[0]) / dx : (point2[1] - a[1]) / dy;
|
|
526
|
+
}
|
|
527
|
+
function segmentEntersArea(edge, boundaries, areas) {
|
|
528
|
+
const [a, b] = edge;
|
|
529
|
+
if (insideArea(a, areas) || insideArea(b, areas))
|
|
530
|
+
return true;
|
|
531
|
+
const cuts = /* @__PURE__ */ new Set([0, 1]);
|
|
532
|
+
const coincident = [];
|
|
533
|
+
for (const boundary of boundaries) {
|
|
534
|
+
if (!segmentsMeet(...edge, ...boundary))
|
|
535
|
+
continue;
|
|
536
|
+
const contacts = endpointContacts(edge, boundary).map((point2) => parameter(point2, edge));
|
|
537
|
+
if (!contacts.length)
|
|
538
|
+
return true;
|
|
539
|
+
for (const contact of contacts)
|
|
540
|
+
cuts.add(contact);
|
|
541
|
+
if (contacts.length === 2)
|
|
542
|
+
coincident.push([Math.min(...contacts), Math.max(...contacts)]);
|
|
543
|
+
}
|
|
544
|
+
const sorted = [...cuts].sort((left, right) => left - right);
|
|
545
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
546
|
+
const from = sorted[i - 1];
|
|
547
|
+
const to = sorted[i];
|
|
548
|
+
if (coincident.some(([start, end]) => start <= from && to <= end))
|
|
549
|
+
continue;
|
|
550
|
+
const t = (from + to) / 2;
|
|
551
|
+
if (insideArea([(1 - t) * a[0] + t * b[0], (1 - t) * a[1] + t * b[1]], areas))
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
function lineEntersArea(line, area) {
|
|
557
|
+
const areas = polygons(area);
|
|
558
|
+
const boundaries = [...edges(areas.flat(), true)];
|
|
559
|
+
for (const edge of edges(paths(line))) {
|
|
560
|
+
if (segmentEntersArea(edge, boundaries, areas))
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
function pointsMeetInterior(points2, other) {
|
|
566
|
+
const positions = points2.type === "Point" ? [points2.coordinates] : points2.coordinates;
|
|
567
|
+
if (isAreal(other)) {
|
|
568
|
+
const areas = polygons(other);
|
|
569
|
+
return positions.some((point2) => Number.isFinite(point2[0]) && Number.isFinite(point2[1]) && insideArea(point2, areas));
|
|
570
|
+
}
|
|
571
|
+
const linePaths = paths(other);
|
|
572
|
+
const boundary = lineBoundary(linePaths);
|
|
573
|
+
const segments = [...edges(linePaths)];
|
|
574
|
+
return positions.some((point2) => !boundary.has(pointKey(point2)) && segments.some((edge) => pointOnSegment(point2, ...edge)));
|
|
575
|
+
}
|
|
576
|
+
function planarTouches(a, b) {
|
|
577
|
+
if (!isPointLike(a) && !isLinear(a) && !isAreal(a) || !isPointLike(b) && !isLinear(b) && !isAreal(b))
|
|
578
|
+
throw new Error("ST_Touches requires point, line or polygon geometry");
|
|
579
|
+
if (isPointLike(a) && isPointLike(b))
|
|
580
|
+
return false;
|
|
581
|
+
if (!planarIntersects(a, b))
|
|
582
|
+
return false;
|
|
583
|
+
if (isPointLike(a) && !isPointLike(b))
|
|
584
|
+
return !pointsMeetInterior(a, b);
|
|
585
|
+
if (isPointLike(b) && !isPointLike(a))
|
|
586
|
+
return !pointsMeetInterior(b, a);
|
|
587
|
+
if (isLinear(a) && isLinear(b))
|
|
588
|
+
return !lineInteriorsMeet(a, b);
|
|
589
|
+
if (isLinear(a) && isAreal(b))
|
|
590
|
+
return !lineEntersArea(a, b);
|
|
591
|
+
if (isAreal(a) && isLinear(b))
|
|
592
|
+
return !lineEntersArea(b, a);
|
|
593
|
+
return !import_polygon_clipping.default.intersection(polygonSet(a), polygonSet(b)).length;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// dist/spatial-dwithin.js
|
|
597
|
+
var import_spatial_index = require("@math.gl/geometry/spatial-index");
|
|
598
|
+
var directPairLimit = 1024;
|
|
599
|
+
function pointWithinPolygonDistance(point2, polygon, radius) {
|
|
600
|
+
const [x, y] = point2.coordinates;
|
|
601
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
602
|
+
return false;
|
|
603
|
+
const bounds = planarBounds(polygon);
|
|
604
|
+
if (!bounds || !boxesWithin([x, y, x, y], bounds, radius))
|
|
605
|
+
return false;
|
|
606
|
+
if (planarIntersects(point2, polygon))
|
|
607
|
+
return true;
|
|
608
|
+
if (radius === 0)
|
|
609
|
+
return false;
|
|
610
|
+
const areas = polygon.type === "Polygon" ? [polygon.coordinates] : polygon.coordinates;
|
|
611
|
+
for (const area of areas) {
|
|
612
|
+
for (const ring of area) {
|
|
613
|
+
for (let i = 0; i < ring.length; i++) {
|
|
614
|
+
const a = ring[i === 0 ? ring.length - 1 : i - 1];
|
|
615
|
+
const b = ring[i];
|
|
616
|
+
if (distanceToPlanarSegment(point2.coordinates, a, b) <= radius)
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
function lineSegments(geometry) {
|
|
624
|
+
const paths2 = geometry.type === "LineString" ? [geometry.coordinates] : geometry.coordinates;
|
|
625
|
+
const segments = [];
|
|
626
|
+
for (const path of paths2) {
|
|
627
|
+
if (path.some((point2) => !Number.isFinite(point2[0]) || !Number.isFinite(point2[1])))
|
|
628
|
+
throw new Error("ST_DWithin requires finite line coordinates");
|
|
629
|
+
if (!path.length)
|
|
630
|
+
continue;
|
|
631
|
+
for (let i = 0; i < Math.max(1, path.length - 1); i++) {
|
|
632
|
+
const a = path[i];
|
|
633
|
+
const b = path[i + 1] ?? a;
|
|
634
|
+
segments.push({
|
|
635
|
+
a,
|
|
636
|
+
b,
|
|
637
|
+
bounds: [
|
|
638
|
+
Math.min(a[0], b[0]),
|
|
639
|
+
Math.min(a[1], b[1]),
|
|
640
|
+
Math.max(a[0], b[0]),
|
|
641
|
+
Math.max(a[1], b[1])
|
|
642
|
+
]
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return segments;
|
|
647
|
+
}
|
|
648
|
+
function boxesWithin(a, b, radius) {
|
|
649
|
+
return Math.max(a[0] - b[2], b[0] - a[2], a[1] - b[3], b[1] - a[3]) <= radius;
|
|
650
|
+
}
|
|
651
|
+
function segmentsWithin(left, right, radius) {
|
|
652
|
+
if (!boxesWithin(left.bounds, right.bounds, radius))
|
|
653
|
+
return false;
|
|
654
|
+
const { a, b } = left;
|
|
655
|
+
const { a: c, b: d } = right;
|
|
656
|
+
return 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);
|
|
657
|
+
}
|
|
658
|
+
function expandBound(value, radius, direction) {
|
|
659
|
+
const padding = Math.max(Math.abs(value), radius) * Number.EPSILON;
|
|
660
|
+
return Math.max(-Number.MAX_VALUE, Math.min(Number.MAX_VALUE, value + direction * (radius + padding)));
|
|
661
|
+
}
|
|
662
|
+
function linesWithinDistance(left, right, radius) {
|
|
663
|
+
const leftBounds = planarBounds(left);
|
|
664
|
+
const rightBounds = planarBounds(right);
|
|
665
|
+
if (!leftBounds || !rightBounds || !boxesWithin(leftBounds, rightBounds, radius))
|
|
666
|
+
return false;
|
|
667
|
+
const a = lineSegments(left);
|
|
668
|
+
const b = lineSegments(right);
|
|
669
|
+
if (!a.length || !b.length)
|
|
670
|
+
return false;
|
|
671
|
+
if (radius === Infinity)
|
|
672
|
+
return true;
|
|
673
|
+
if (a.length * b.length <= directPairLimit || Math.min(a.length, b.length) < 8) {
|
|
674
|
+
return a.some((segment) => b.some((candidate) => segmentsWithin(segment, candidate, radius)));
|
|
675
|
+
}
|
|
676
|
+
const [indexed, queries] = a.length <= b.length ? [a, b] : [b, a];
|
|
677
|
+
const index = new import_spatial_index.BoxIndex({ dimension: 2, bounds: indexed.flatMap((segment) => segment.bounds) });
|
|
678
|
+
for (const segment of queries) {
|
|
679
|
+
const [x0, y0, x1, y1] = segment.bounds;
|
|
680
|
+
const { result: result2 } = index.searchQuery([expandBound(x0, radius, -1), expandBound(y0, radius, -1)], [expandBound(x1, radius, 1), expandBound(y1, radius, 1)], { filter: (candidate) => segmentsWithin(segment, indexed[candidate], radius), maxResults: 1 });
|
|
681
|
+
if (result2.length)
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
|
|
375
687
|
// dist/linear-referencing.js
|
|
688
|
+
var import_robust_predicates2 = require("robust-predicates");
|
|
376
689
|
function cumulativeDistances(path) {
|
|
377
690
|
const distances = [0];
|
|
378
691
|
for (let i = 1; i < path.length; i++) {
|
|
@@ -413,27 +726,170 @@ function lineSubstring(line, start, end) {
|
|
|
413
726
|
coordinates.push(coordinateAt(path, distances, to));
|
|
414
727
|
return { type: "LineString", coordinates };
|
|
415
728
|
}
|
|
416
|
-
function
|
|
729
|
+
function projectPointToLine(line, point2) {
|
|
417
730
|
if (line.type !== "LineString" || !line.coordinates.length || point2.type !== "Point" || !Number.isFinite(point2.coordinates[0]) || !Number.isFinite(point2.coordinates[1]))
|
|
418
731
|
return null;
|
|
419
|
-
const path = line.coordinates
|
|
420
|
-
|
|
732
|
+
const path = line.coordinates;
|
|
733
|
+
const x = point2.coordinates[0];
|
|
734
|
+
const y = point2.coordinates[1];
|
|
735
|
+
let coordinate = path[0];
|
|
736
|
+
let nearest = Math.hypot(x - coordinate[0], y - coordinate[1]);
|
|
737
|
+
let total = 0;
|
|
738
|
+
let position = 0;
|
|
421
739
|
for (let i = 1; i < path.length; i++) {
|
|
422
|
-
const a = path[i - 1]
|
|
423
|
-
const
|
|
740
|
+
const a = path[i - 1];
|
|
741
|
+
const b = path[i];
|
|
742
|
+
const dx = b[0] - a[0];
|
|
743
|
+
const dy = b[1] - a[1];
|
|
424
744
|
const length = Math.hypot(dx, dy);
|
|
425
745
|
if (!length)
|
|
426
746
|
continue;
|
|
427
|
-
const ux = dx / length
|
|
747
|
+
const ux = dx / length;
|
|
748
|
+
const uy = dy / length;
|
|
428
749
|
const along = Math.max(0, Math.min(length, (x - a[0]) * ux + (y - a[1]) * uy));
|
|
429
|
-
|
|
750
|
+
let px = along === length ? b[0] : a[0] + along * ux;
|
|
751
|
+
let py = along === length ? b[1] : a[1] + along * uy;
|
|
752
|
+
if (along > 0 && along < length && (0, import_robust_predicates2.orient2d)(a[0], a[1], b[0], b[1], x, y) === 0) {
|
|
753
|
+
px = x;
|
|
754
|
+
py = y;
|
|
755
|
+
}
|
|
756
|
+
const distance = Math.hypot(x - px, y - py);
|
|
430
757
|
if (distance < nearest) {
|
|
431
758
|
nearest = distance;
|
|
759
|
+
coordinate = [px, py];
|
|
432
760
|
position = total + along;
|
|
433
761
|
}
|
|
434
762
|
total += length;
|
|
435
763
|
}
|
|
436
|
-
return total ? position / total : 0;
|
|
764
|
+
return { coordinate, distance: nearest, fraction: total ? position / total : 0 };
|
|
765
|
+
}
|
|
766
|
+
function lineLocatePoint(line, point2) {
|
|
767
|
+
var _a;
|
|
768
|
+
return ((_a = projectPointToLine(line, point2)) == null ? void 0 : _a.fraction) ?? null;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// dist/measure-referencing.js
|
|
772
|
+
function pathsOf(geometry) {
|
|
773
|
+
if (geometry.type === "LineString")
|
|
774
|
+
return [geometry.coordinates];
|
|
775
|
+
if (geometry.type === "MultiLineString")
|
|
776
|
+
return geometry.coordinates;
|
|
777
|
+
throw new Error("Measured routes require a LineString or MultiLineString");
|
|
778
|
+
}
|
|
779
|
+
function measuredDimension(dimension) {
|
|
780
|
+
if (dimension === "xym" || dimension === "xyzm")
|
|
781
|
+
return dimension;
|
|
782
|
+
throw new Error("Input geometry requires a measure (M) ordinate");
|
|
783
|
+
}
|
|
784
|
+
function addMeasure(geometry, dimension, start, end) {
|
|
785
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
786
|
+
throw new Error("Expected finite measures");
|
|
787
|
+
const paths2 = pathsOf(geometry);
|
|
788
|
+
let total = 0;
|
|
789
|
+
const distances = paths2.map((path) => path.map((point2, i) => {
|
|
790
|
+
if (i > 0) {
|
|
791
|
+
const previous = path[i - 1];
|
|
792
|
+
total += Math.hypot(point2[0] - previous[0], point2[1] - previous[1]);
|
|
793
|
+
}
|
|
794
|
+
return total;
|
|
795
|
+
}));
|
|
796
|
+
if (!Number.isFinite(total))
|
|
797
|
+
throw new Error("Expected finite route length");
|
|
798
|
+
const spatialSize = dimension.includes("z") ? 3 : 2;
|
|
799
|
+
const coordinates = paths2.map((path, part) => path.map((point2, i) => {
|
|
800
|
+
const fraction = total ? distances[part][i] / total : 0;
|
|
801
|
+
return [...point2.slice(0, spatialSize), (1 - fraction) * start + fraction * end];
|
|
802
|
+
}));
|
|
803
|
+
return {
|
|
804
|
+
geometry: geometry.type === "LineString" ? { type: "LineString", coordinates: coordinates[0] } : { type: "MultiLineString", coordinates },
|
|
805
|
+
dimension: spatialSize === 3 ? "xyzm" : "xym"
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
function samePosition(a, b) {
|
|
809
|
+
return a.every((value, i) => value === b[i]);
|
|
810
|
+
}
|
|
811
|
+
function atMeasure(a, b, index, measure) {
|
|
812
|
+
const from = a[index];
|
|
813
|
+
const to = b[index];
|
|
814
|
+
if (from !== to) {
|
|
815
|
+
if (measure === from)
|
|
816
|
+
return a;
|
|
817
|
+
if (measure === to)
|
|
818
|
+
return b;
|
|
819
|
+
}
|
|
820
|
+
const span = to - from;
|
|
821
|
+
const fraction = span === 0 ? 0.5 : Number.isFinite(span) ? (measure - from) / span : (measure / 2 - from / 2) / (to / 2 - from / 2);
|
|
822
|
+
return a.map((value, i) => i === index ? measure : (1 - fraction) * value + fraction * b[i]);
|
|
823
|
+
}
|
|
824
|
+
function measureAt(position, index) {
|
|
825
|
+
const value = position[index];
|
|
826
|
+
if (!Number.isFinite(value))
|
|
827
|
+
throw new Error("Expected finite route measures");
|
|
828
|
+
return value;
|
|
829
|
+
}
|
|
830
|
+
function locateAlong(geometry, dimension, measure) {
|
|
831
|
+
if (!Number.isFinite(measure))
|
|
832
|
+
throw new Error("Expected a finite measure");
|
|
833
|
+
const index = dimension.indexOf("m");
|
|
834
|
+
const coordinates = [];
|
|
835
|
+
for (const path of pathsOf(geometry)) {
|
|
836
|
+
let previousEndsAtVertex = false;
|
|
837
|
+
for (let i = 1; i < path.length; i++) {
|
|
838
|
+
const a = path[i - 1];
|
|
839
|
+
const b = path[i];
|
|
840
|
+
const from = measureAt(a, index);
|
|
841
|
+
const to = measureAt(b, index);
|
|
842
|
+
if (measure < Math.min(from, to) || measure > Math.max(from, to)) {
|
|
843
|
+
previousEndsAtVertex = false;
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
const startsAtVertex = from !== to && measure === from;
|
|
847
|
+
if (!previousEndsAtVertex || !startsAtVertex) {
|
|
848
|
+
coordinates.push(atMeasure(a, b, index, measure));
|
|
849
|
+
}
|
|
850
|
+
previousEndsAtVertex = from !== to && measure === to;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return { type: "MultiPoint", coordinates };
|
|
854
|
+
}
|
|
855
|
+
function appendPortion(parts, path) {
|
|
856
|
+
if (path.length === 1)
|
|
857
|
+
parts.push({ type: "Point", coordinates: path[0] });
|
|
858
|
+
else if (path.length > 1)
|
|
859
|
+
parts.push({ type: "LineString", coordinates: path });
|
|
860
|
+
}
|
|
861
|
+
function locateBetween(geometry, dimension, start, end) {
|
|
862
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
863
|
+
throw new Error("Expected finite measures");
|
|
864
|
+
const low = Math.min(start, end);
|
|
865
|
+
const high = Math.max(start, end);
|
|
866
|
+
const index = dimension.indexOf("m");
|
|
867
|
+
const parts = [];
|
|
868
|
+
for (const path of pathsOf(geometry)) {
|
|
869
|
+
let portion = [];
|
|
870
|
+
for (let i = 1; i < path.length; i++) {
|
|
871
|
+
const a = path[i - 1];
|
|
872
|
+
const b = path[i];
|
|
873
|
+
const from = measureAt(a, index);
|
|
874
|
+
const to = measureAt(b, index);
|
|
875
|
+
const begin = Math.max(low, Math.min(from, to));
|
|
876
|
+
const finish = Math.min(high, Math.max(from, to));
|
|
877
|
+
if (begin > finish)
|
|
878
|
+
continue;
|
|
879
|
+
const first = from === to ? a : atMeasure(a, b, index, from <= to ? begin : finish);
|
|
880
|
+
const last = from === to ? b : atMeasure(a, b, index, from <= to ? finish : begin);
|
|
881
|
+
if (!portion.length)
|
|
882
|
+
portion.push(first);
|
|
883
|
+
if (!samePosition(portion[portion.length - 1], last))
|
|
884
|
+
portion.push(last);
|
|
885
|
+
if (to < low || to > high) {
|
|
886
|
+
appendPortion(parts, portion);
|
|
887
|
+
portion = [];
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
appendPortion(parts, portion);
|
|
891
|
+
}
|
|
892
|
+
return parts.every((part) => part.type === "LineString") ? { type: "MultiLineString", coordinates: parts.map((part) => part.coordinates) } : { type: "GeometryCollection", geometries: parts };
|
|
437
893
|
}
|
|
438
894
|
|
|
439
895
|
// dist/crs/crs-identifier.js
|
|
@@ -594,14 +1050,7 @@ function removeRepeated(path, tolerance) {
|
|
|
594
1050
|
}
|
|
595
1051
|
return kept;
|
|
596
1052
|
}
|
|
597
|
-
function
|
|
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) {
|
|
1053
|
+
function simplifyLine(path, tolerance) {
|
|
605
1054
|
if (!path.length)
|
|
606
1055
|
return path;
|
|
607
1056
|
const last = path.length - 1;
|
|
@@ -612,7 +1061,7 @@ function simplify(path, tolerance) {
|
|
|
612
1061
|
const end = spans.pop(), start = spans.pop();
|
|
613
1062
|
let split = start, maximum = tolerance;
|
|
614
1063
|
for (let i = start + 1; i < end; i++) {
|
|
615
|
-
const distance =
|
|
1064
|
+
const distance = distanceToPlanarSegment(path[i], path[start], path[end]);
|
|
616
1065
|
if (distance > maximum) {
|
|
617
1066
|
maximum = distance;
|
|
618
1067
|
split = i;
|
|
@@ -633,7 +1082,7 @@ function reduceLineVertices(geometry, tolerance, mode) {
|
|
|
633
1082
|
throw new Error("Expected a finite nonnegative tolerance");
|
|
634
1083
|
if ((geometry.type === "LineString" || geometry.type === "MultiLineString") && (!geometry.coordinates.length || geometry.type === "MultiLineString" && geometry.coordinates.every((path) => !path.length)))
|
|
635
1084
|
return geometry;
|
|
636
|
-
const reduce = mode === "simplify" ?
|
|
1085
|
+
const reduce = mode === "simplify" ? simplifyLine : removeRepeated;
|
|
637
1086
|
if (geometry.type === "LineString") {
|
|
638
1087
|
const coordinates2 = reduce(geometry.coordinates, tolerance);
|
|
639
1088
|
return coordinates2.length || mode === "removeRepeated" ? { type: "LineString", coordinates: coordinates2 } : null;
|
|
@@ -647,6 +1096,120 @@ function reduceLineVertices(geometry, tolerance, mode) {
|
|
|
647
1096
|
return coordinates.length ? { type: "MultiLineString", coordinates } : null;
|
|
648
1097
|
}
|
|
649
1098
|
|
|
1099
|
+
// dist/polygon-simplification.js
|
|
1100
|
+
var import_robust_predicates3 = require("robust-predicates");
|
|
1101
|
+
function intervalDensity(items, axis) {
|
|
1102
|
+
let minimum = Infinity;
|
|
1103
|
+
let maximum = -Infinity;
|
|
1104
|
+
let length = 0;
|
|
1105
|
+
for (const { bounds } of items) {
|
|
1106
|
+
const low = bounds[axis];
|
|
1107
|
+
const high = bounds[axis + 2];
|
|
1108
|
+
minimum = Math.min(minimum, low);
|
|
1109
|
+
maximum = Math.max(maximum, high);
|
|
1110
|
+
length += high - low;
|
|
1111
|
+
}
|
|
1112
|
+
return maximum > minimum ? length / (maximum - minimum) : Infinity;
|
|
1113
|
+
}
|
|
1114
|
+
function anyOverlap(items, reject) {
|
|
1115
|
+
const axis = intervalDensity(items, 0) > intervalDensity(items, 1) ? 1 : 0;
|
|
1116
|
+
const other = 1 - axis;
|
|
1117
|
+
items.sort((a, b) => a.bounds[axis] - b.bounds[axis]);
|
|
1118
|
+
for (let i = 0; i < items.length; i++) {
|
|
1119
|
+
const a = items[i];
|
|
1120
|
+
for (let j = i + 1; j < items.length && items[j].bounds[axis] <= a.bounds[axis + 2]; j++) {
|
|
1121
|
+
const b = items[j];
|
|
1122
|
+
if (b.bounds[other] <= a.bounds[other + 2] && a.bounds[other] <= b.bounds[other + 2] && reject(a, b))
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
function samePoint2(a, b) {
|
|
1129
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
1130
|
+
}
|
|
1131
|
+
function signedArea(ring) {
|
|
1132
|
+
const [x, y] = ring[0];
|
|
1133
|
+
let area = 0;
|
|
1134
|
+
for (let i = 1; i + 1 < ring.length; i++) {
|
|
1135
|
+
const a = ring[i];
|
|
1136
|
+
const b = ring[i + 1];
|
|
1137
|
+
area += (a[0] - x) * (b[1] - y) - (a[1] - y) * (b[0] - x);
|
|
1138
|
+
}
|
|
1139
|
+
return area;
|
|
1140
|
+
}
|
|
1141
|
+
function separatedBoundaries(rings) {
|
|
1142
|
+
const edges2 = [];
|
|
1143
|
+
for (const ring of rings) {
|
|
1144
|
+
const size = ring.length - 1;
|
|
1145
|
+
if (size < 3 || !samePoint2(ring[0], ring[size]))
|
|
1146
|
+
return false;
|
|
1147
|
+
for (let i = 0; i < size; i++) {
|
|
1148
|
+
const a = ring[i];
|
|
1149
|
+
const b = ring[i + 1];
|
|
1150
|
+
const c = ring[(i + 2) % size];
|
|
1151
|
+
if (!Number.isFinite(a[0]) || !Number.isFinite(a[1]) || samePoint2(a, b))
|
|
1152
|
+
return false;
|
|
1153
|
+
if ((0, import_robust_predicates3.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)
|
|
1154
|
+
return false;
|
|
1155
|
+
edges2.push({
|
|
1156
|
+
a,
|
|
1157
|
+
b,
|
|
1158
|
+
ring,
|
|
1159
|
+
index: i,
|
|
1160
|
+
bounds: [
|
|
1161
|
+
Math.min(a[0], b[0]),
|
|
1162
|
+
Math.min(a[1], b[1]),
|
|
1163
|
+
Math.max(a[0], b[0]),
|
|
1164
|
+
Math.max(a[1], b[1])
|
|
1165
|
+
]
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return !anyOverlap(edges2, (a, b) => {
|
|
1170
|
+
if (a.ring === b.ring) {
|
|
1171
|
+
const gap = Math.abs(a.index - b.index);
|
|
1172
|
+
if (gap === 1 || gap === a.ring.length - 2)
|
|
1173
|
+
return false;
|
|
1174
|
+
}
|
|
1175
|
+
return segmentsMeet(a.a, a.b, b.a, b.b);
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
function contains(outer, inner) {
|
|
1179
|
+
return planarIntersects({ type: "Polygon", coordinates: [outer] }, { type: "Point", coordinates: inner[0] });
|
|
1180
|
+
}
|
|
1181
|
+
function preservesNesting(before, after) {
|
|
1182
|
+
const rings = before.map((original, index) => ({
|
|
1183
|
+
original,
|
|
1184
|
+
simplified: after[index],
|
|
1185
|
+
bounds: planarBounds({ type: "LineString", coordinates: original })
|
|
1186
|
+
}));
|
|
1187
|
+
return !anyOverlap(rings, (a, b) => contains(a.original, b.original) !== contains(a.simplified, b.simplified) || contains(b.original, a.original) !== contains(b.simplified, a.simplified));
|
|
1188
|
+
}
|
|
1189
|
+
function simplifyRing(ring, tolerance) {
|
|
1190
|
+
const reduced = simplifyLine(ring, tolerance);
|
|
1191
|
+
if (reduced.length < 4 || reduced.length === ring.length)
|
|
1192
|
+
return ring;
|
|
1193
|
+
const before = signedArea(ring);
|
|
1194
|
+
const after = signedArea(reduced);
|
|
1195
|
+
return Number.isFinite(before) && Number.isFinite(after) && after && Math.sign(before) === Math.sign(after) ? reduced : ring;
|
|
1196
|
+
}
|
|
1197
|
+
function simplifyPolygonTopology(geometry, tolerance) {
|
|
1198
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
1199
|
+
throw new Error("Expected a finite nonnegative tolerance");
|
|
1200
|
+
if (!tolerance)
|
|
1201
|
+
return geometry;
|
|
1202
|
+
const polygons3 = geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates;
|
|
1203
|
+
const before = polygons3.flat();
|
|
1204
|
+
const reduced = polygons3.map((polygon) => polygon.map((ring) => simplifyRing(ring, tolerance)));
|
|
1205
|
+
const after = reduced.flat();
|
|
1206
|
+
if (before.every((ring, index) => ring === after[index]))
|
|
1207
|
+
return geometry;
|
|
1208
|
+
if (!separatedBoundaries(before) || !separatedBoundaries(after) || !preservesNesting(before, after))
|
|
1209
|
+
return geometry;
|
|
1210
|
+
return geometry.type === "Polygon" ? { type: "Polygon", coordinates: reduced[0] } : { type: "MultiPolygon", coordinates: reduced };
|
|
1211
|
+
}
|
|
1212
|
+
|
|
650
1213
|
// dist/geometry-constructors.js
|
|
651
1214
|
function collectPair(a, b) {
|
|
652
1215
|
if (a.type === "Point" && b.type === "Point")
|
|
@@ -755,7 +1318,7 @@ function paired(a, b) {
|
|
|
755
1318
|
}
|
|
756
1319
|
var native = Object.keys(depths);
|
|
757
1320
|
var points = ["geoarrow.point"];
|
|
758
|
-
var
|
|
1321
|
+
var polygons2 = ["geoarrow.polygon", "geoarrow.multipolygon"];
|
|
759
1322
|
function ringContains(array, a, b, p) {
|
|
760
1323
|
let inside = false;
|
|
761
1324
|
for (let i = a, j = b - 1; i < b; j = i++) {
|
|
@@ -791,7 +1354,7 @@ function polygonContains(array, index, p) {
|
|
|
791
1354
|
return a === b ? -1 : 1;
|
|
792
1355
|
}
|
|
793
1356
|
function booleanPointInPolygon(pointColumn, polygonColumn, options = {}) {
|
|
794
|
-
const a = rows(pointColumn, points), b = rows(polygonColumn,
|
|
1357
|
+
const a = rows(pointColumn, points), b = rows(polygonColumn, polygons2), n = paired(a, b), out = result(n, true);
|
|
795
1358
|
for (let i = 0; i < n; i++) {
|
|
796
1359
|
const x = a[a.length === 1 ? 0 : i], y = b[b.length === 1 ? 0 : i];
|
|
797
1360
|
if (!x.valid || !y.valid)
|
|
@@ -822,7 +1385,7 @@ function booleanPointInPolygon(pointColumn, polygonColumn, options = {}) {
|
|
|
822
1385
|
}
|
|
823
1386
|
return out;
|
|
824
1387
|
}
|
|
825
|
-
var lineFamilies = ["geoarrow.linestring", "geoarrow.multilinestring", ...
|
|
1388
|
+
var lineFamilies = ["geoarrow.linestring", "geoarrow.multilinestring", ...polygons2];
|
|
826
1389
|
|
|
827
1390
|
// dist/spatial-sql.js
|
|
828
1391
|
var EXTENSION_NAME = "ARROW:extension:name";
|
|
@@ -838,6 +1401,11 @@ var geometryTypes = [
|
|
|
838
1401
|
var pointKinds = ["Point"];
|
|
839
1402
|
var lineKinds = ["LineString", "MultiLineString"];
|
|
840
1403
|
var polygonKinds = ["Polygon", "MultiPolygon"];
|
|
1404
|
+
function nativePolygonResult(encoding) {
|
|
1405
|
+
const options = { encoding, dimension: "xy", coordinateLayout: "interleaved" };
|
|
1406
|
+
const build = (rows2) => (0, import_arrow3.makeArrowVectorFromGeoArrowColumn)(import_arrow3.GeoArrowBuilder.build(rows2, options));
|
|
1407
|
+
return { encoding, type: build([]).type, build };
|
|
1408
|
+
}
|
|
841
1409
|
function readGeometryValue(vector, field, active, value, captureMembers = false) {
|
|
842
1410
|
if (import_apache_arrow.DataType.isBinary(field.type) || import_apache_arrow.DataType.isLargeBinary(field.type)) {
|
|
843
1411
|
return (row) => {
|
|
@@ -883,7 +1451,8 @@ function planarGeometry(geometry, dimension) {
|
|
|
883
1451
|
throw new Error("Spatial SQL functions require 2D geometry");
|
|
884
1452
|
return geometry;
|
|
885
1453
|
}
|
|
886
|
-
function spatialFunction(name, signatures,
|
|
1454
|
+
function spatialFunction(name, signatures, output, evaluate, numericArguments = 0, allDimensions = false, skipNullGeometries = false, validateCRS) {
|
|
1455
|
+
const type = "encoding" in output ? output.type : output;
|
|
887
1456
|
return {
|
|
888
1457
|
kind: "scalar",
|
|
889
1458
|
name,
|
|
@@ -906,26 +1475,32 @@ function spatialFunction(name, signatures, type, evaluate, numericArguments = 0,
|
|
|
906
1475
|
const encoding = extension == null ? void 0 : extension.encoding;
|
|
907
1476
|
const kinds = signatures[index];
|
|
908
1477
|
if (encoding === "geoarrow.wkb" && (import_apache_arrow.DataType.isBinary(field.type) || import_apache_arrow.DataType.isLargeBinary(field.type))) {
|
|
1478
|
+
} else if (encoding === "geoarrow.geometry" && extension.dimension === "xy") {
|
|
909
1479
|
} else if (kinds.some((kind) => encoding === "geoarrow." + kind.toLowerCase())) {
|
|
910
1480
|
if (!allDimensions && (extension == null ? void 0 : extension.dimension) !== "xy")
|
|
911
1481
|
throw new Error(`${name} requires 2D geometry`);
|
|
912
1482
|
} else {
|
|
913
1483
|
throw new Error(`${name} argument ${index + 1} requires GeoArrow ${kinds.join(" or ")}`);
|
|
914
1484
|
}
|
|
915
|
-
|
|
1485
|
+
validateCRS == null ? void 0 : validateCRS(extension == null ? void 0 : extension.metadata["crs"], name);
|
|
1486
|
+
if (!validateCRS && name.startsWith("ST_") && name !== "ST_SRID" && name !== "ST_SetSRID" && (extension == null ? void 0 : extension.metadata["edges"]) === "spherical")
|
|
916
1487
|
throw new Error(`${name} requires planar geometry`);
|
|
917
1488
|
return extension;
|
|
918
1489
|
});
|
|
919
1490
|
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]))) {
|
|
1491
|
+
if (!validateCRS && name.startsWith("ST_") && crsValues.some((crs) => JSON.stringify(crs) !== JSON.stringify(crsValues[0]))) {
|
|
921
1492
|
throw new Error(`${name} requires arguments in the same CRS`);
|
|
922
1493
|
}
|
|
923
1494
|
const metadata = /* @__PURE__ */ new Map();
|
|
924
|
-
if (import_apache_arrow.DataType.isBinary(type)) {
|
|
925
|
-
metadata.set(EXTENSION_NAME, "geoarrow.wkb");
|
|
926
|
-
const inputMetadata = (_a =
|
|
927
|
-
|
|
928
|
-
|
|
1495
|
+
if ("encoding" in output || import_apache_arrow.DataType.isBinary(type)) {
|
|
1496
|
+
metadata.set(EXTENSION_NAME, "encoding" in output ? output.encoding : "geoarrow.wkb");
|
|
1497
|
+
const inputMetadata = (_a = extensions[0]) == null ? void 0 : _a.metadata;
|
|
1498
|
+
const crs = inputMetadata == null ? void 0 : inputMetadata["crs"];
|
|
1499
|
+
const crsType = crs === void 0 ? void 0 : inputMetadata == null ? void 0 : inputMetadata["crs_type"];
|
|
1500
|
+
const edges2 = inputMetadata == null ? void 0 : inputMetadata["edges"];
|
|
1501
|
+
if (crs !== void 0 || edges2 !== void 0) {
|
|
1502
|
+
metadata.set(EXTENSION_METADATA, JSON.stringify({ crs, crs_type: crsType, edges: edges2 }));
|
|
1503
|
+
}
|
|
929
1504
|
}
|
|
930
1505
|
const arguments_ = [
|
|
931
1506
|
...geometryFields.map((field) => field ?? new import_apache_arrow.Field("geometry", new import_apache_arrow.Binary(), true)),
|
|
@@ -954,7 +1529,7 @@ function spatialFunction(name, signatures, type, evaluate, numericArguments = 0,
|
|
|
954
1529
|
}
|
|
955
1530
|
values[row] = evaluate(geometries, ...numbers.map((vector) => Number(vector.get(row))));
|
|
956
1531
|
}
|
|
957
|
-
return (0, import_apache_arrow.vectorFromArray)(values,
|
|
1532
|
+
return "encoding" in output ? output.build(values) : (0, import_apache_arrow.vectorFromArray)(values, output);
|
|
958
1533
|
}
|
|
959
1534
|
};
|
|
960
1535
|
}
|
|
@@ -976,6 +1551,1547 @@ function pointInPolygon(point2, polygon, ignoreBoundary = false) {
|
|
|
976
1551
|
return value === null ? null : value === 1;
|
|
977
1552
|
}
|
|
978
1553
|
|
|
1554
|
+
// dist/st-geodesic-functions.js
|
|
1555
|
+
var import_apache_arrow2 = require("apache-arrow");
|
|
1556
|
+
|
|
1557
|
+
// dist/constants.js
|
|
1558
|
+
var WGS84_RADIUS_X = 6378137;
|
|
1559
|
+
var WGS84_RADIUS_Y = 6378137;
|
|
1560
|
+
var WGS84_RADIUS_Z = 6356752314245179e-9;
|
|
1561
|
+
var WGS84_CONSTANTS = {
|
|
1562
|
+
radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
|
|
1563
|
+
radiiSquared: [
|
|
1564
|
+
WGS84_RADIUS_X * WGS84_RADIUS_X,
|
|
1565
|
+
WGS84_RADIUS_Y * WGS84_RADIUS_Y,
|
|
1566
|
+
WGS84_RADIUS_Z * WGS84_RADIUS_Z
|
|
1567
|
+
],
|
|
1568
|
+
oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
|
|
1569
|
+
oneOverRadiiSquared: [
|
|
1570
|
+
1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
|
|
1571
|
+
1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
|
|
1572
|
+
1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
|
|
1573
|
+
],
|
|
1574
|
+
maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
|
|
1575
|
+
centerToleranceSquared: 0.1
|
|
1576
|
+
// EPSILON1;
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1579
|
+
// dist/vendor/geographiclib-geodesic/runtime.js
|
|
1580
|
+
var geodesic = {};
|
|
1581
|
+
geodesic.Constants = {};
|
|
1582
|
+
geodesic.Math = {};
|
|
1583
|
+
geodesic.Accumulator = {};
|
|
1584
|
+
(function(c) {
|
|
1585
|
+
"use strict";
|
|
1586
|
+
c.WGS84 = { a: 6378137, f: 1 / 298.257223563 };
|
|
1587
|
+
c.version = {
|
|
1588
|
+
major: 2,
|
|
1589
|
+
minor: 2,
|
|
1590
|
+
patch: 0
|
|
1591
|
+
};
|
|
1592
|
+
c.version_string = "2.2.0";
|
|
1593
|
+
})(geodesic.Constants);
|
|
1594
|
+
(function(m) {
|
|
1595
|
+
"use strict";
|
|
1596
|
+
m.digits = 53;
|
|
1597
|
+
m.epsilon = Math.pow(0.5, m.digits - 1);
|
|
1598
|
+
m.degree = Math.PI / 180;
|
|
1599
|
+
m.sq = function(x) {
|
|
1600
|
+
return x * x;
|
|
1601
|
+
};
|
|
1602
|
+
m.hypot = function(x, y) {
|
|
1603
|
+
return Math.sqrt(x * x + y * y);
|
|
1604
|
+
};
|
|
1605
|
+
m.cbrt = Math.cbrt || function(x) {
|
|
1606
|
+
var y = Math.pow(Math.abs(x), 1 / 3);
|
|
1607
|
+
return x > 0 ? y : x < 0 ? -y : x;
|
|
1608
|
+
};
|
|
1609
|
+
m.log1p = Math.log1p || function(x) {
|
|
1610
|
+
var y = 1 + x, z = y - 1;
|
|
1611
|
+
return z === 0 ? x : x * Math.log(y) / z;
|
|
1612
|
+
};
|
|
1613
|
+
m.atanh = Math.atanh || function(x) {
|
|
1614
|
+
var y = Math.abs(x);
|
|
1615
|
+
y = m.log1p(2 * y / (1 - y)) / 2;
|
|
1616
|
+
return x > 0 ? y : x < 0 ? -y : x;
|
|
1617
|
+
};
|
|
1618
|
+
m.copysign = function(x, y) {
|
|
1619
|
+
return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
|
|
1620
|
+
};
|
|
1621
|
+
m.sum = function(u, v) {
|
|
1622
|
+
var s = u + v, up = s - v, vpp = s - up, t;
|
|
1623
|
+
up -= u;
|
|
1624
|
+
vpp -= v;
|
|
1625
|
+
t = s ? 0 - (up + vpp) : s;
|
|
1626
|
+
return { s, t };
|
|
1627
|
+
};
|
|
1628
|
+
m.polyval = function(N, p, s, x) {
|
|
1629
|
+
var y = N < 0 ? 0 : p[s++];
|
|
1630
|
+
while (--N >= 0)
|
|
1631
|
+
y = y * x + p[s++];
|
|
1632
|
+
return y;
|
|
1633
|
+
};
|
|
1634
|
+
m.AngRound = function(x) {
|
|
1635
|
+
var z = 1 / 16, y = Math.abs(x);
|
|
1636
|
+
y = y < z ? z - (z - y) : y;
|
|
1637
|
+
return m.copysign(y, x);
|
|
1638
|
+
};
|
|
1639
|
+
m.remainder = function(x, y) {
|
|
1640
|
+
x %= y;
|
|
1641
|
+
return x < -y / 2 ? x + y : x < y / 2 ? x : x - y;
|
|
1642
|
+
};
|
|
1643
|
+
m.AngNormalize = function(x) {
|
|
1644
|
+
var y = m.remainder(x, 360);
|
|
1645
|
+
return Math.abs(y) === 180 ? m.copysign(180, x) : y;
|
|
1646
|
+
};
|
|
1647
|
+
m.LatFix = function(x) {
|
|
1648
|
+
return Math.abs(x) > 90 ? NaN : x;
|
|
1649
|
+
};
|
|
1650
|
+
m.AngDiff = function(x, y) {
|
|
1651
|
+
var r = m.sum(m.remainder(-x, 360), m.remainder(y, 360)), d, e;
|
|
1652
|
+
r = m.sum(m.remainder(r.s, 360), r.t);
|
|
1653
|
+
d = r.s;
|
|
1654
|
+
e = r.t;
|
|
1655
|
+
if (d === 0 || Math.abs(d) === 180)
|
|
1656
|
+
d = m.copysign(d, e === 0 ? y - x : -e);
|
|
1657
|
+
return { d, e };
|
|
1658
|
+
};
|
|
1659
|
+
m.sincosd = function(x) {
|
|
1660
|
+
var d, r, q, s, c, sinx, cosx;
|
|
1661
|
+
d = x % 360;
|
|
1662
|
+
q = Math.round(d / 90);
|
|
1663
|
+
d -= 90 * q;
|
|
1664
|
+
r = d * this.degree;
|
|
1665
|
+
s = Math.sin(r);
|
|
1666
|
+
c = Math.cos(r);
|
|
1667
|
+
if (Math.abs(d) === 45) {
|
|
1668
|
+
c = Math.sqrt(0.5);
|
|
1669
|
+
s = m.copysign(c, r);
|
|
1670
|
+
} else if (Math.abs(d) === 30) {
|
|
1671
|
+
c = Math.sqrt(0.75);
|
|
1672
|
+
s = m.copysign(0.5, r);
|
|
1673
|
+
}
|
|
1674
|
+
switch (q & 3) {
|
|
1675
|
+
case 0:
|
|
1676
|
+
sinx = s;
|
|
1677
|
+
cosx = c;
|
|
1678
|
+
break;
|
|
1679
|
+
case 1:
|
|
1680
|
+
sinx = c;
|
|
1681
|
+
cosx = -s;
|
|
1682
|
+
break;
|
|
1683
|
+
case 2:
|
|
1684
|
+
sinx = -s;
|
|
1685
|
+
cosx = -c;
|
|
1686
|
+
break;
|
|
1687
|
+
default:
|
|
1688
|
+
sinx = -c;
|
|
1689
|
+
cosx = s;
|
|
1690
|
+
break;
|
|
1691
|
+
}
|
|
1692
|
+
cosx += 0;
|
|
1693
|
+
if (sinx === 0)
|
|
1694
|
+
sinx = m.copysign(sinx, x);
|
|
1695
|
+
return { s: sinx, c: cosx };
|
|
1696
|
+
};
|
|
1697
|
+
m.sincosde = function(x, t) {
|
|
1698
|
+
var d, r, q, s, c, sinx, cosx;
|
|
1699
|
+
d = x % 360;
|
|
1700
|
+
q = Math.round(d / 90);
|
|
1701
|
+
d = m.AngRound(d - 90 * q + t);
|
|
1702
|
+
r = d * this.degree;
|
|
1703
|
+
s = Math.sin(r);
|
|
1704
|
+
c = Math.cos(r);
|
|
1705
|
+
if (Math.abs(d) === 45) {
|
|
1706
|
+
c = Math.sqrt(0.5);
|
|
1707
|
+
s = m.copysign(c, r);
|
|
1708
|
+
} else if (Math.abs(d) === 30) {
|
|
1709
|
+
c = Math.sqrt(0.75);
|
|
1710
|
+
s = m.copysign(0.5, r);
|
|
1711
|
+
}
|
|
1712
|
+
switch (q & 3) {
|
|
1713
|
+
case 0:
|
|
1714
|
+
sinx = s;
|
|
1715
|
+
cosx = c;
|
|
1716
|
+
break;
|
|
1717
|
+
case 1:
|
|
1718
|
+
sinx = c;
|
|
1719
|
+
cosx = -s;
|
|
1720
|
+
break;
|
|
1721
|
+
case 2:
|
|
1722
|
+
sinx = -s;
|
|
1723
|
+
cosx = -c;
|
|
1724
|
+
break;
|
|
1725
|
+
default:
|
|
1726
|
+
sinx = -c;
|
|
1727
|
+
cosx = s;
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
cosx += 0;
|
|
1731
|
+
if (sinx === 0)
|
|
1732
|
+
sinx = m.copysign(sinx, x + t);
|
|
1733
|
+
return { s: sinx, c: cosx };
|
|
1734
|
+
};
|
|
1735
|
+
m.atan2d = function(y, x) {
|
|
1736
|
+
var q = 0, ang;
|
|
1737
|
+
if (Math.abs(y) > Math.abs(x)) {
|
|
1738
|
+
[y, x] = [x, y];
|
|
1739
|
+
q = 2;
|
|
1740
|
+
}
|
|
1741
|
+
if (m.copysign(1, x) < 0) {
|
|
1742
|
+
x = -x;
|
|
1743
|
+
++q;
|
|
1744
|
+
}
|
|
1745
|
+
ang = Math.atan2(y, x) / this.degree;
|
|
1746
|
+
switch (q) {
|
|
1747
|
+
// Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
|
|
1748
|
+
// atan2d will not be called with y = -0. If need be, include
|
|
1749
|
+
//
|
|
1750
|
+
// case 0: ang = 0 + ang; break;
|
|
1751
|
+
//
|
|
1752
|
+
// and handle mpfr as in AngRound.
|
|
1753
|
+
case 1:
|
|
1754
|
+
ang = m.copysign(180, y) - ang;
|
|
1755
|
+
break;
|
|
1756
|
+
case 2:
|
|
1757
|
+
ang = 90 - ang;
|
|
1758
|
+
break;
|
|
1759
|
+
case 3:
|
|
1760
|
+
ang = -90 + ang;
|
|
1761
|
+
break;
|
|
1762
|
+
default:
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
return ang;
|
|
1766
|
+
};
|
|
1767
|
+
})(geodesic.Math);
|
|
1768
|
+
(function(a, m) {
|
|
1769
|
+
"use strict";
|
|
1770
|
+
a.Accumulator = function(y) {
|
|
1771
|
+
this.Set(y);
|
|
1772
|
+
};
|
|
1773
|
+
a.Accumulator.prototype.Set = function(y) {
|
|
1774
|
+
if (!y)
|
|
1775
|
+
y = 0;
|
|
1776
|
+
if (y.constructor === a.Accumulator) {
|
|
1777
|
+
this._s = y._s;
|
|
1778
|
+
this._t = y._t;
|
|
1779
|
+
} else {
|
|
1780
|
+
this._s = y;
|
|
1781
|
+
this._t = 0;
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
a.Accumulator.prototype.Add = function(y) {
|
|
1785
|
+
var u = m.sum(y, this._t), v = m.sum(u.s, this._s);
|
|
1786
|
+
u = u.t;
|
|
1787
|
+
this._s = v.s;
|
|
1788
|
+
this._t = v.t;
|
|
1789
|
+
if (this._s === 0)
|
|
1790
|
+
this._s = u;
|
|
1791
|
+
else
|
|
1792
|
+
this._t += u;
|
|
1793
|
+
};
|
|
1794
|
+
a.Accumulator.prototype.Sum = function(y) {
|
|
1795
|
+
var b;
|
|
1796
|
+
if (!y)
|
|
1797
|
+
return this._s;
|
|
1798
|
+
else {
|
|
1799
|
+
b = new a.Accumulator(this);
|
|
1800
|
+
b.Add(y);
|
|
1801
|
+
return b._s;
|
|
1802
|
+
}
|
|
1803
|
+
};
|
|
1804
|
+
a.Accumulator.prototype.Negate = function() {
|
|
1805
|
+
this._s *= -1;
|
|
1806
|
+
this._t *= -1;
|
|
1807
|
+
};
|
|
1808
|
+
a.Accumulator.prototype.Remainder = function(y) {
|
|
1809
|
+
this._s = m.remainder(this._s, y);
|
|
1810
|
+
this.Add(0);
|
|
1811
|
+
};
|
|
1812
|
+
})(geodesic.Accumulator, geodesic.Math);
|
|
1813
|
+
geodesic.Geodesic = {};
|
|
1814
|
+
geodesic.GeodesicLine = {};
|
|
1815
|
+
geodesic.PolygonArea = {};
|
|
1816
|
+
(function(g, l, p, m, c) {
|
|
1817
|
+
"use strict";
|
|
1818
|
+
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;
|
|
1819
|
+
g.tiny_ = Math.sqrt(Number.MIN_VALUE / Number.EPSILON);
|
|
1820
|
+
g.nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1821
|
+
g.nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1822
|
+
g.nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1823
|
+
g.nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1824
|
+
g.nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
1825
|
+
nC3x_ = g.nC3_ * (g.nC3_ - 1) / 2;
|
|
1826
|
+
nC4x_ = g.nC4_ * (g.nC4_ + 1) / 2;
|
|
1827
|
+
g.CAP_C1 = 1 << 0;
|
|
1828
|
+
g.CAP_C1p = 1 << 1;
|
|
1829
|
+
g.CAP_C2 = 1 << 2;
|
|
1830
|
+
g.CAP_C3 = 1 << 3;
|
|
1831
|
+
g.CAP_C4 = 1 << 4;
|
|
1832
|
+
g.NONE = 0;
|
|
1833
|
+
g.ARC = 1 << 6;
|
|
1834
|
+
g.LATITUDE = 1 << 7 | CAP_NONE;
|
|
1835
|
+
g.LONGITUDE = 1 << 8 | g.CAP_C3;
|
|
1836
|
+
g.AZIMUTH = 1 << 9 | CAP_NONE;
|
|
1837
|
+
g.DISTANCE = 1 << 10 | g.CAP_C1;
|
|
1838
|
+
g.STANDARD = g.LATITUDE | g.LONGITUDE | g.AZIMUTH | g.DISTANCE;
|
|
1839
|
+
g.DISTANCE_IN = 1 << 11 | g.CAP_C1 | g.CAP_C1p;
|
|
1840
|
+
g.REDUCEDLENGTH = 1 << 12 | g.CAP_C1 | g.CAP_C2;
|
|
1841
|
+
g.GEODESICSCALE = 1 << 13 | g.CAP_C1 | g.CAP_C2;
|
|
1842
|
+
g.AREA = 1 << 14 | g.CAP_C4;
|
|
1843
|
+
g.ALL = OUT_ALL | CAP_ALL;
|
|
1844
|
+
g.LONG_UNROLL = 1 << 15;
|
|
1845
|
+
g.OUT_MASK = OUT_ALL | g.LONG_UNROLL;
|
|
1846
|
+
g.SinCosSeries = function(sinp, sinx, cosx, c2, delta) {
|
|
1847
|
+
if (delta !== void 0) {
|
|
1848
|
+
var h = delta / 2, sh = Math.sin(h), ch = Math.cos(h);
|
|
1849
|
+
return -2 * g.SinCosSeries(false, cosx * ch - sinx * sh, sinx * ch + cosx * sh, c2.map(function(v, i) {
|
|
1850
|
+
return (i % 2 ? -v : v) * Math.sin((2 * i + 1) * h);
|
|
1851
|
+
}));
|
|
1852
|
+
}
|
|
1853
|
+
var k = c2.length, n = k - (sinp ? 1 : 0), ar = 2 * (cosx - sinx) * (cosx + sinx), y0 = n & 1 ? c2[--k] : 0, y1 = 0;
|
|
1854
|
+
n = Math.floor(n / 2);
|
|
1855
|
+
while (n--) {
|
|
1856
|
+
y1 = ar * y0 - y1 + c2[--k];
|
|
1857
|
+
y0 = ar * y1 - y0 + c2[--k];
|
|
1858
|
+
}
|
|
1859
|
+
return sinp ? 2 * sinx * cosx * y0 : (
|
|
1860
|
+
// sin(2 * x) * y0
|
|
1861
|
+
cosx * (y0 - y1)
|
|
1862
|
+
);
|
|
1863
|
+
};
|
|
1864
|
+
astroid = function(x, y) {
|
|
1865
|
+
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;
|
|
1866
|
+
if (!(q === 0 && r <= 0)) {
|
|
1867
|
+
S = p2 * q / 4;
|
|
1868
|
+
r2 = m.sq(r);
|
|
1869
|
+
r3 = r * r2;
|
|
1870
|
+
disc = S * (S + 2 * r3);
|
|
1871
|
+
u = r;
|
|
1872
|
+
if (disc >= 0) {
|
|
1873
|
+
T3 = S + r3;
|
|
1874
|
+
T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc);
|
|
1875
|
+
T = m.cbrt(T3);
|
|
1876
|
+
u += T + (T !== 0 ? r2 / T : 0);
|
|
1877
|
+
} else {
|
|
1878
|
+
ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
|
|
1879
|
+
u += 2 * r * Math.cos(ang / 3);
|
|
1880
|
+
}
|
|
1881
|
+
v = Math.sqrt(m.sq(u) + q);
|
|
1882
|
+
uv = u < 0 ? q / (v - u) : u + v;
|
|
1883
|
+
w = (uv - q) / (2 * v);
|
|
1884
|
+
k = uv / (Math.sqrt(uv + m.sq(w)) + w);
|
|
1885
|
+
} else {
|
|
1886
|
+
k = 0;
|
|
1887
|
+
}
|
|
1888
|
+
return k;
|
|
1889
|
+
};
|
|
1890
|
+
A1m1f_coeff = [
|
|
1891
|
+
// (1-eps)*A1-1, polynomial in eps2 of order 3
|
|
1892
|
+
1,
|
|
1893
|
+
4,
|
|
1894
|
+
64,
|
|
1895
|
+
0,
|
|
1896
|
+
256
|
|
1897
|
+
];
|
|
1898
|
+
g.A1m1f = function(eps) {
|
|
1899
|
+
var p2 = Math.floor(nA1_ / 2), t = m.polyval(p2, A1m1f_coeff, 0, m.sq(eps)) / A1m1f_coeff[p2 + 1];
|
|
1900
|
+
return (t + eps) / (1 - eps);
|
|
1901
|
+
};
|
|
1902
|
+
C1f_coeff = [
|
|
1903
|
+
// C1[1]/eps^1, polynomial in eps2 of order 2
|
|
1904
|
+
-1,
|
|
1905
|
+
6,
|
|
1906
|
+
-16,
|
|
1907
|
+
32,
|
|
1908
|
+
// C1[2]/eps^2, polynomial in eps2 of order 2
|
|
1909
|
+
-9,
|
|
1910
|
+
64,
|
|
1911
|
+
-128,
|
|
1912
|
+
2048,
|
|
1913
|
+
// C1[3]/eps^3, polynomial in eps2 of order 1
|
|
1914
|
+
9,
|
|
1915
|
+
-16,
|
|
1916
|
+
768,
|
|
1917
|
+
// C1[4]/eps^4, polynomial in eps2 of order 1
|
|
1918
|
+
3,
|
|
1919
|
+
-5,
|
|
1920
|
+
512,
|
|
1921
|
+
// C1[5]/eps^5, polynomial in eps2 of order 0
|
|
1922
|
+
-7,
|
|
1923
|
+
1280,
|
|
1924
|
+
// C1[6]/eps^6, polynomial in eps2 of order 0
|
|
1925
|
+
-7,
|
|
1926
|
+
2048
|
|
1927
|
+
];
|
|
1928
|
+
g.C1f = function(eps, c2) {
|
|
1929
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
1930
|
+
for (l2 = 1; l2 <= g.nC1_; ++l2) {
|
|
1931
|
+
p2 = Math.floor((g.nC1_ - l2) / 2);
|
|
1932
|
+
c2[l2] = d * m.polyval(p2, C1f_coeff, o, eps2) / C1f_coeff[o + p2 + 1];
|
|
1933
|
+
o += p2 + 2;
|
|
1934
|
+
d *= eps;
|
|
1935
|
+
}
|
|
1936
|
+
};
|
|
1937
|
+
C1pf_coeff = [
|
|
1938
|
+
// C1p[1]/eps^1, polynomial in eps2 of order 2
|
|
1939
|
+
205,
|
|
1940
|
+
-432,
|
|
1941
|
+
768,
|
|
1942
|
+
1536,
|
|
1943
|
+
// C1p[2]/eps^2, polynomial in eps2 of order 2
|
|
1944
|
+
4005,
|
|
1945
|
+
-4736,
|
|
1946
|
+
3840,
|
|
1947
|
+
12288,
|
|
1948
|
+
// C1p[3]/eps^3, polynomial in eps2 of order 1
|
|
1949
|
+
-225,
|
|
1950
|
+
116,
|
|
1951
|
+
384,
|
|
1952
|
+
// C1p[4]/eps^4, polynomial in eps2 of order 1
|
|
1953
|
+
-7173,
|
|
1954
|
+
2695,
|
|
1955
|
+
7680,
|
|
1956
|
+
// C1p[5]/eps^5, polynomial in eps2 of order 0
|
|
1957
|
+
3467,
|
|
1958
|
+
7680,
|
|
1959
|
+
// C1p[6]/eps^6, polynomial in eps2 of order 0
|
|
1960
|
+
38081,
|
|
1961
|
+
61440
|
|
1962
|
+
];
|
|
1963
|
+
g.C1pf = function(eps, c2) {
|
|
1964
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
1965
|
+
for (l2 = 1; l2 <= g.nC1p_; ++l2) {
|
|
1966
|
+
p2 = Math.floor((g.nC1p_ - l2) / 2);
|
|
1967
|
+
c2[l2] = d * m.polyval(p2, C1pf_coeff, o, eps2) / C1pf_coeff[o + p2 + 1];
|
|
1968
|
+
o += p2 + 2;
|
|
1969
|
+
d *= eps;
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
A2m1f_coeff = [
|
|
1973
|
+
// (eps+1)*A2-1, polynomial in eps2 of order 3
|
|
1974
|
+
-11,
|
|
1975
|
+
-28,
|
|
1976
|
+
-192,
|
|
1977
|
+
0,
|
|
1978
|
+
256
|
|
1979
|
+
];
|
|
1980
|
+
g.A2m1f = function(eps) {
|
|
1981
|
+
var p2 = Math.floor(nA2_ / 2), t = m.polyval(p2, A2m1f_coeff, 0, m.sq(eps)) / A2m1f_coeff[p2 + 1];
|
|
1982
|
+
return (t - eps) / (1 + eps);
|
|
1983
|
+
};
|
|
1984
|
+
C2f_coeff = [
|
|
1985
|
+
// C2[1]/eps^1, polynomial in eps2 of order 2
|
|
1986
|
+
1,
|
|
1987
|
+
2,
|
|
1988
|
+
16,
|
|
1989
|
+
32,
|
|
1990
|
+
// C2[2]/eps^2, polynomial in eps2 of order 2
|
|
1991
|
+
35,
|
|
1992
|
+
64,
|
|
1993
|
+
384,
|
|
1994
|
+
2048,
|
|
1995
|
+
// C2[3]/eps^3, polynomial in eps2 of order 1
|
|
1996
|
+
15,
|
|
1997
|
+
80,
|
|
1998
|
+
768,
|
|
1999
|
+
// C2[4]/eps^4, polynomial in eps2 of order 1
|
|
2000
|
+
7,
|
|
2001
|
+
35,
|
|
2002
|
+
512,
|
|
2003
|
+
// C2[5]/eps^5, polynomial in eps2 of order 0
|
|
2004
|
+
63,
|
|
2005
|
+
1280,
|
|
2006
|
+
// C2[6]/eps^6, polynomial in eps2 of order 0
|
|
2007
|
+
77,
|
|
2008
|
+
2048
|
|
2009
|
+
];
|
|
2010
|
+
g.C2f = function(eps, c2) {
|
|
2011
|
+
var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
|
|
2012
|
+
for (l2 = 1; l2 <= g.nC2_; ++l2) {
|
|
2013
|
+
p2 = Math.floor((g.nC2_ - l2) / 2);
|
|
2014
|
+
c2[l2] = d * m.polyval(p2, C2f_coeff, o, eps2) / C2f_coeff[o + p2 + 1];
|
|
2015
|
+
o += p2 + 2;
|
|
2016
|
+
d *= eps;
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
g.Geodesic = function(a, f) {
|
|
2020
|
+
this.a = a;
|
|
2021
|
+
this.f = f;
|
|
2022
|
+
this._f1 = 1 - this.f;
|
|
2023
|
+
this._e2 = this.f * (2 - this.f);
|
|
2024
|
+
this._ep2 = this._e2 / m.sq(this._f1);
|
|
2025
|
+
this._n = this.f / (2 - this.f);
|
|
2026
|
+
this._b = this.a * this._f1;
|
|
2027
|
+
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;
|
|
2028
|
+
this._etol2 = 0.1 * tol2_ / Math.sqrt(Math.max(1e-3, Math.abs(this.f)) * Math.min(1, 1 - this.f / 2) / 2);
|
|
2029
|
+
if (!(isFinite(this.a) && this.a > 0))
|
|
2030
|
+
throw new Error("Equatorial radius is not positive");
|
|
2031
|
+
if (!(isFinite(this._b) && this._b > 0))
|
|
2032
|
+
throw new Error("Polar semi-axis is not positive");
|
|
2033
|
+
this._A3x = new Array(nA3x_);
|
|
2034
|
+
this._C3x = new Array(nC3x_);
|
|
2035
|
+
this._C4x = new Array(nC4x_);
|
|
2036
|
+
this.A3coeff();
|
|
2037
|
+
this.C3coeff();
|
|
2038
|
+
this.C4coeff();
|
|
2039
|
+
};
|
|
2040
|
+
A3_coeff = [
|
|
2041
|
+
// A3, coeff of eps^5, polynomial in n of order 0
|
|
2042
|
+
-3,
|
|
2043
|
+
128,
|
|
2044
|
+
// A3, coeff of eps^4, polynomial in n of order 1
|
|
2045
|
+
-2,
|
|
2046
|
+
-3,
|
|
2047
|
+
64,
|
|
2048
|
+
// A3, coeff of eps^3, polynomial in n of order 2
|
|
2049
|
+
-1,
|
|
2050
|
+
-3,
|
|
2051
|
+
-1,
|
|
2052
|
+
16,
|
|
2053
|
+
// A3, coeff of eps^2, polynomial in n of order 2
|
|
2054
|
+
3,
|
|
2055
|
+
-1,
|
|
2056
|
+
-2,
|
|
2057
|
+
8,
|
|
2058
|
+
// A3, coeff of eps^1, polynomial in n of order 1
|
|
2059
|
+
1,
|
|
2060
|
+
-1,
|
|
2061
|
+
2,
|
|
2062
|
+
// A3, coeff of eps^0, polynomial in n of order 0
|
|
2063
|
+
1,
|
|
2064
|
+
1
|
|
2065
|
+
];
|
|
2066
|
+
g.Geodesic.prototype.A3coeff = function() {
|
|
2067
|
+
var o = 0, k = 0, j, p2;
|
|
2068
|
+
for (j = nA3_ - 1; j >= 0; --j) {
|
|
2069
|
+
p2 = Math.min(nA3_ - j - 1, j);
|
|
2070
|
+
this._A3x[k++] = m.polyval(p2, A3_coeff, o, this._n) / A3_coeff[o + p2 + 1];
|
|
2071
|
+
o += p2 + 2;
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
C3_coeff = [
|
|
2075
|
+
// C3[1], coeff of eps^5, polynomial in n of order 0
|
|
2076
|
+
3,
|
|
2077
|
+
128,
|
|
2078
|
+
// C3[1], coeff of eps^4, polynomial in n of order 1
|
|
2079
|
+
2,
|
|
2080
|
+
5,
|
|
2081
|
+
128,
|
|
2082
|
+
// C3[1], coeff of eps^3, polynomial in n of order 2
|
|
2083
|
+
-1,
|
|
2084
|
+
3,
|
|
2085
|
+
3,
|
|
2086
|
+
64,
|
|
2087
|
+
// C3[1], coeff of eps^2, polynomial in n of order 2
|
|
2088
|
+
-1,
|
|
2089
|
+
0,
|
|
2090
|
+
1,
|
|
2091
|
+
8,
|
|
2092
|
+
// C3[1], coeff of eps^1, polynomial in n of order 1
|
|
2093
|
+
-1,
|
|
2094
|
+
1,
|
|
2095
|
+
4,
|
|
2096
|
+
// C3[2], coeff of eps^5, polynomial in n of order 0
|
|
2097
|
+
5,
|
|
2098
|
+
256,
|
|
2099
|
+
// C3[2], coeff of eps^4, polynomial in n of order 1
|
|
2100
|
+
1,
|
|
2101
|
+
3,
|
|
2102
|
+
128,
|
|
2103
|
+
// C3[2], coeff of eps^3, polynomial in n of order 2
|
|
2104
|
+
-3,
|
|
2105
|
+
-2,
|
|
2106
|
+
3,
|
|
2107
|
+
64,
|
|
2108
|
+
// C3[2], coeff of eps^2, polynomial in n of order 2
|
|
2109
|
+
1,
|
|
2110
|
+
-3,
|
|
2111
|
+
2,
|
|
2112
|
+
32,
|
|
2113
|
+
// C3[3], coeff of eps^5, polynomial in n of order 0
|
|
2114
|
+
7,
|
|
2115
|
+
512,
|
|
2116
|
+
// C3[3], coeff of eps^4, polynomial in n of order 1
|
|
2117
|
+
-10,
|
|
2118
|
+
9,
|
|
2119
|
+
384,
|
|
2120
|
+
// C3[3], coeff of eps^3, polynomial in n of order 2
|
|
2121
|
+
5,
|
|
2122
|
+
-9,
|
|
2123
|
+
5,
|
|
2124
|
+
192,
|
|
2125
|
+
// C3[4], coeff of eps^5, polynomial in n of order 0
|
|
2126
|
+
7,
|
|
2127
|
+
512,
|
|
2128
|
+
// C3[4], coeff of eps^4, polynomial in n of order 1
|
|
2129
|
+
-14,
|
|
2130
|
+
7,
|
|
2131
|
+
512,
|
|
2132
|
+
// C3[5], coeff of eps^5, polynomial in n of order 0
|
|
2133
|
+
21,
|
|
2134
|
+
2560
|
|
2135
|
+
];
|
|
2136
|
+
g.Geodesic.prototype.C3coeff = function() {
|
|
2137
|
+
var o = 0, k = 0, l2, j, p2;
|
|
2138
|
+
for (l2 = 1; l2 < g.nC3_; ++l2) {
|
|
2139
|
+
for (j = g.nC3_ - 1; j >= l2; --j) {
|
|
2140
|
+
p2 = Math.min(g.nC3_ - j - 1, j);
|
|
2141
|
+
this._C3x[k++] = m.polyval(p2, C3_coeff, o, this._n) / C3_coeff[o + p2 + 1];
|
|
2142
|
+
o += p2 + 2;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
C4_coeff = [
|
|
2147
|
+
// C4[0], coeff of eps^5, polynomial in n of order 0
|
|
2148
|
+
97,
|
|
2149
|
+
15015,
|
|
2150
|
+
// C4[0], coeff of eps^4, polynomial in n of order 1
|
|
2151
|
+
1088,
|
|
2152
|
+
156,
|
|
2153
|
+
45045,
|
|
2154
|
+
// C4[0], coeff of eps^3, polynomial in n of order 2
|
|
2155
|
+
-224,
|
|
2156
|
+
-4784,
|
|
2157
|
+
1573,
|
|
2158
|
+
45045,
|
|
2159
|
+
// C4[0], coeff of eps^2, polynomial in n of order 3
|
|
2160
|
+
-10656,
|
|
2161
|
+
14144,
|
|
2162
|
+
-4576,
|
|
2163
|
+
-858,
|
|
2164
|
+
45045,
|
|
2165
|
+
// C4[0], coeff of eps^1, polynomial in n of order 4
|
|
2166
|
+
64,
|
|
2167
|
+
624,
|
|
2168
|
+
-4576,
|
|
2169
|
+
6864,
|
|
2170
|
+
-3003,
|
|
2171
|
+
15015,
|
|
2172
|
+
// C4[0], coeff of eps^0, polynomial in n of order 5
|
|
2173
|
+
100,
|
|
2174
|
+
208,
|
|
2175
|
+
572,
|
|
2176
|
+
3432,
|
|
2177
|
+
-12012,
|
|
2178
|
+
30030,
|
|
2179
|
+
45045,
|
|
2180
|
+
// C4[1], coeff of eps^5, polynomial in n of order 0
|
|
2181
|
+
1,
|
|
2182
|
+
9009,
|
|
2183
|
+
// C4[1], coeff of eps^4, polynomial in n of order 1
|
|
2184
|
+
-2944,
|
|
2185
|
+
468,
|
|
2186
|
+
135135,
|
|
2187
|
+
// C4[1], coeff of eps^3, polynomial in n of order 2
|
|
2188
|
+
5792,
|
|
2189
|
+
1040,
|
|
2190
|
+
-1287,
|
|
2191
|
+
135135,
|
|
2192
|
+
// C4[1], coeff of eps^2, polynomial in n of order 3
|
|
2193
|
+
5952,
|
|
2194
|
+
-11648,
|
|
2195
|
+
9152,
|
|
2196
|
+
-2574,
|
|
2197
|
+
135135,
|
|
2198
|
+
// C4[1], coeff of eps^1, polynomial in n of order 4
|
|
2199
|
+
-64,
|
|
2200
|
+
-624,
|
|
2201
|
+
4576,
|
|
2202
|
+
-6864,
|
|
2203
|
+
3003,
|
|
2204
|
+
135135,
|
|
2205
|
+
// C4[2], coeff of eps^5, polynomial in n of order 0
|
|
2206
|
+
8,
|
|
2207
|
+
10725,
|
|
2208
|
+
// C4[2], coeff of eps^4, polynomial in n of order 1
|
|
2209
|
+
1856,
|
|
2210
|
+
-936,
|
|
2211
|
+
225225,
|
|
2212
|
+
// C4[2], coeff of eps^3, polynomial in n of order 2
|
|
2213
|
+
-8448,
|
|
2214
|
+
4992,
|
|
2215
|
+
-1144,
|
|
2216
|
+
225225,
|
|
2217
|
+
// C4[2], coeff of eps^2, polynomial in n of order 3
|
|
2218
|
+
-1440,
|
|
2219
|
+
4160,
|
|
2220
|
+
-4576,
|
|
2221
|
+
1716,
|
|
2222
|
+
225225,
|
|
2223
|
+
// C4[3], coeff of eps^5, polynomial in n of order 0
|
|
2224
|
+
-136,
|
|
2225
|
+
63063,
|
|
2226
|
+
// C4[3], coeff of eps^4, polynomial in n of order 1
|
|
2227
|
+
1024,
|
|
2228
|
+
-208,
|
|
2229
|
+
105105,
|
|
2230
|
+
// C4[3], coeff of eps^3, polynomial in n of order 2
|
|
2231
|
+
3584,
|
|
2232
|
+
-3328,
|
|
2233
|
+
1144,
|
|
2234
|
+
315315,
|
|
2235
|
+
// C4[4], coeff of eps^5, polynomial in n of order 0
|
|
2236
|
+
-128,
|
|
2237
|
+
135135,
|
|
2238
|
+
// C4[4], coeff of eps^4, polynomial in n of order 1
|
|
2239
|
+
-2560,
|
|
2240
|
+
832,
|
|
2241
|
+
405405,
|
|
2242
|
+
// C4[5], coeff of eps^5, polynomial in n of order 0
|
|
2243
|
+
128,
|
|
2244
|
+
99099
|
|
2245
|
+
];
|
|
2246
|
+
g.Geodesic.prototype.C4coeff = function() {
|
|
2247
|
+
var o = 0, k = 0, l2, j, p2;
|
|
2248
|
+
for (l2 = 0; l2 < g.nC4_; ++l2) {
|
|
2249
|
+
for (j = g.nC4_ - 1; j >= l2; --j) {
|
|
2250
|
+
p2 = g.nC4_ - j - 1;
|
|
2251
|
+
this._C4x[k++] = m.polyval(p2, C4_coeff, o, this._n) / C4_coeff[o + p2 + 1];
|
|
2252
|
+
o += p2 + 2;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
g.Geodesic.prototype.A3f = function(eps) {
|
|
2257
|
+
return m.polyval(nA3x_ - 1, this._A3x, 0, eps);
|
|
2258
|
+
};
|
|
2259
|
+
g.Geodesic.prototype.C3f = function(eps, c2) {
|
|
2260
|
+
var mult = 1, o = 0, l2, p2;
|
|
2261
|
+
for (l2 = 1; l2 < g.nC3_; ++l2) {
|
|
2262
|
+
p2 = g.nC3_ - l2 - 1;
|
|
2263
|
+
mult *= eps;
|
|
2264
|
+
c2[l2] = mult * m.polyval(p2, this._C3x, o, eps);
|
|
2265
|
+
o += p2 + 1;
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
g.Geodesic.prototype.C4f = function(eps, c2) {
|
|
2269
|
+
var mult = 1, o = 0, l2, p2;
|
|
2270
|
+
for (l2 = 0; l2 < g.nC4_; ++l2) {
|
|
2271
|
+
p2 = g.nC4_ - l2 - 1;
|
|
2272
|
+
c2[l2] = mult * m.polyval(p2, this._C4x, o, eps);
|
|
2273
|
+
o += p2 + 1;
|
|
2274
|
+
mult *= eps;
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
g.Geodesic.prototype.Lengths = function(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask, C1a, C2a) {
|
|
2278
|
+
outmask &= g.OUT_MASK;
|
|
2279
|
+
var vals = {}, m0x = 0, J12 = 0, A1 = 0, A2 = 0, B1, B2, l2, csig12, t;
|
|
2280
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2281
|
+
A1 = g.A1m1f(eps);
|
|
2282
|
+
g.C1f(eps, C1a);
|
|
2283
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2284
|
+
A2 = g.A2m1f(eps);
|
|
2285
|
+
g.C2f(eps, C2a);
|
|
2286
|
+
m0x = A1 - A2;
|
|
2287
|
+
A2 = 1 + A2;
|
|
2288
|
+
}
|
|
2289
|
+
A1 = 1 + A1;
|
|
2290
|
+
}
|
|
2291
|
+
if (outmask & g.DISTANCE) {
|
|
2292
|
+
B1 = g.SinCosSeries(true, ssig2, csig2, C1a) - g.SinCosSeries(true, ssig1, csig1, C1a);
|
|
2293
|
+
vals.s12b = A1 * (sig12 + B1);
|
|
2294
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2295
|
+
B2 = g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a);
|
|
2296
|
+
J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
|
|
2297
|
+
}
|
|
2298
|
+
} else if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2299
|
+
for (l2 = 1; l2 <= g.nC2_; ++l2)
|
|
2300
|
+
C2a[l2] = A1 * C1a[l2] - A2 * C2a[l2];
|
|
2301
|
+
J12 = m0x * sig12 + (g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a));
|
|
2302
|
+
}
|
|
2303
|
+
if (outmask & g.REDUCEDLENGTH) {
|
|
2304
|
+
vals.m0 = m0x;
|
|
2305
|
+
vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12;
|
|
2306
|
+
} else
|
|
2307
|
+
vals.m12b = NaN;
|
|
2308
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2309
|
+
csig12 = csig1 * csig2 + ssig1 * ssig2;
|
|
2310
|
+
t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
|
|
2311
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
|
|
2312
|
+
vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
|
|
2313
|
+
}
|
|
2314
|
+
return vals;
|
|
2315
|
+
};
|
|
2316
|
+
g.Geodesic.prototype.InverseStart = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a) {
|
|
2317
|
+
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;
|
|
2318
|
+
vals.sig12 = -1;
|
|
2319
|
+
sbet12a = sbet2 * cbet1;
|
|
2320
|
+
sbet12a += cbet2 * sbet1;
|
|
2321
|
+
shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
|
|
2322
|
+
if (shortline) {
|
|
2323
|
+
sbetm2 = m.sq(sbet1 + sbet2);
|
|
2324
|
+
sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
|
|
2325
|
+
vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
|
|
2326
|
+
omg12 = lam12 / (this._f1 * vals.dnm);
|
|
2327
|
+
somg12 = Math.sin(omg12);
|
|
2328
|
+
comg12 = Math.cos(omg12);
|
|
2329
|
+
} else {
|
|
2330
|
+
somg12 = slam12;
|
|
2331
|
+
comg12 = clam12;
|
|
2332
|
+
}
|
|
2333
|
+
vals.salp1 = cbet2 * somg12;
|
|
2334
|
+
vals.calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * m.sq(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
|
2335
|
+
ssig12 = m.hypot(vals.salp1, vals.calp1);
|
|
2336
|
+
csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
|
|
2337
|
+
if (shortline && ssig12 < this._etol2) {
|
|
2338
|
+
vals.salp2 = cbet1 * somg12;
|
|
2339
|
+
vals.calp2 = sbet12 - cbet1 * sbet2 * (comg12 >= 0 ? m.sq(somg12) / (1 + comg12) : 1 - comg12);
|
|
2340
|
+
t = m.hypot(vals.salp2, vals.calp2);
|
|
2341
|
+
vals.salp2 /= t;
|
|
2342
|
+
vals.calp2 /= t;
|
|
2343
|
+
vals.sig12 = Math.atan2(ssig12, csig12);
|
|
2344
|
+
} else if (Math.abs(this._n) > 0.1 || // Skip astroid calc if too eccentric
|
|
2345
|
+
csig12 >= 0 || ssig12 >= 6 * Math.abs(this._n) * Math.PI * m.sq(cbet1)) {
|
|
2346
|
+
} else {
|
|
2347
|
+
lam12x = Math.atan2(-slam12, -clam12);
|
|
2348
|
+
if (this.f >= 0) {
|
|
2349
|
+
k2 = m.sq(sbet1) * this._ep2;
|
|
2350
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2351
|
+
lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
|
|
2352
|
+
betscale = lamscale * cbet1;
|
|
2353
|
+
x = lam12x / lamscale;
|
|
2354
|
+
y = sbet12a / betscale;
|
|
2355
|
+
} else {
|
|
2356
|
+
cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
|
|
2357
|
+
bet12a = Math.atan2(sbet12a, cbet12a);
|
|
2358
|
+
nvals = this.Lengths(this._n, Math.PI + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
|
2359
|
+
m12b = nvals.m12b;
|
|
2360
|
+
m0 = nvals.m0;
|
|
2361
|
+
x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
|
|
2362
|
+
betscale = x < -0.01 ? sbet12a / x : -this.f * m.sq(cbet1) * Math.PI;
|
|
2363
|
+
lamscale = betscale / cbet1;
|
|
2364
|
+
y = lam12 / lamscale;
|
|
2365
|
+
}
|
|
2366
|
+
if (y > -tol1_ && x > -1 - xthresh_) {
|
|
2367
|
+
if (this.f >= 0) {
|
|
2368
|
+
vals.salp1 = Math.min(1, -x);
|
|
2369
|
+
vals.calp1 = -Math.sqrt(1 - m.sq(vals.salp1));
|
|
2370
|
+
} else {
|
|
2371
|
+
vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
|
|
2372
|
+
vals.salp1 = Math.sqrt(1 - m.sq(vals.calp1));
|
|
2373
|
+
}
|
|
2374
|
+
} else {
|
|
2375
|
+
k = astroid(x, y);
|
|
2376
|
+
omg12a = lamscale * (this.f >= 0 ? -x * k / (1 + k) : -y * (1 + k) / k);
|
|
2377
|
+
somg12 = Math.sin(omg12a);
|
|
2378
|
+
comg12 = -Math.cos(omg12a);
|
|
2379
|
+
vals.salp1 = cbet2 * somg12;
|
|
2380
|
+
vals.calp1 = sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
if (!(vals.salp1 <= 0)) {
|
|
2384
|
+
t = m.hypot(vals.salp1, vals.calp1);
|
|
2385
|
+
vals.salp1 /= t;
|
|
2386
|
+
vals.calp1 /= t;
|
|
2387
|
+
} else {
|
|
2388
|
+
vals.salp1 = 1;
|
|
2389
|
+
vals.calp1 = 0;
|
|
2390
|
+
}
|
|
2391
|
+
return vals;
|
|
2392
|
+
};
|
|
2393
|
+
g.Geodesic.prototype.Lambda12 = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam120, clam120, diffp, C1a, C2a, C3a) {
|
|
2394
|
+
var vals = {}, t, salp0, calp0, somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
|
|
2395
|
+
if (sbet1 === 0 && calp1 === 0)
|
|
2396
|
+
calp1 = -g.tiny_;
|
|
2397
|
+
salp0 = salp1 * cbet1;
|
|
2398
|
+
calp0 = m.hypot(calp1, salp1 * sbet1);
|
|
2399
|
+
vals.ssig1 = sbet1;
|
|
2400
|
+
somg1 = salp0 * sbet1;
|
|
2401
|
+
vals.csig1 = comg1 = calp1 * cbet1;
|
|
2402
|
+
t = m.hypot(vals.ssig1, vals.csig1);
|
|
2403
|
+
vals.ssig1 /= t;
|
|
2404
|
+
vals.csig1 /= t;
|
|
2405
|
+
vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
|
|
2406
|
+
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);
|
|
2407
|
+
vals.ssig2 = sbet2;
|
|
2408
|
+
somg2 = salp0 * sbet2;
|
|
2409
|
+
vals.csig2 = comg2 = vals.calp2 * cbet2;
|
|
2410
|
+
t = m.hypot(vals.ssig2, vals.csig2);
|
|
2411
|
+
vals.ssig2 /= t;
|
|
2412
|
+
vals.csig2 /= t;
|
|
2413
|
+
vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 - vals.ssig1 * vals.csig2), vals.csig1 * vals.csig2 + vals.ssig1 * vals.ssig2);
|
|
2414
|
+
somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
|
|
2415
|
+
comg12 = comg1 * comg2 + somg1 * somg2;
|
|
2416
|
+
eta = Math.atan2(somg12 * clam120 - comg12 * slam120, comg12 * clam120 + somg12 * slam120);
|
|
2417
|
+
k2 = m.sq(calp0) * this._ep2;
|
|
2418
|
+
vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2419
|
+
this.C3f(vals.eps, C3a);
|
|
2420
|
+
B312 = g.SinCosSeries(true, vals.ssig2, vals.csig2, C3a) - g.SinCosSeries(true, vals.ssig1, vals.csig1, C3a);
|
|
2421
|
+
vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
|
|
2422
|
+
vals.lam12 = eta + vals.domg12;
|
|
2423
|
+
if (diffp) {
|
|
2424
|
+
if (vals.calp2 === 0)
|
|
2425
|
+
vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
|
|
2426
|
+
else {
|
|
2427
|
+
nvals = this.Lengths(vals.eps, vals.sig12, vals.ssig1, vals.csig1, dn1, vals.ssig2, vals.csig2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
|
|
2428
|
+
vals.dlam12 = nvals.m12b;
|
|
2429
|
+
vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
return vals;
|
|
2433
|
+
};
|
|
2434
|
+
g.Geodesic.prototype.Inverse = function(lat1, lon1, lat2, lon2, outmask) {
|
|
2435
|
+
var r, vals;
|
|
2436
|
+
if (!outmask)
|
|
2437
|
+
outmask = g.STANDARD;
|
|
2438
|
+
if (outmask === g.LONG_UNROLL)
|
|
2439
|
+
outmask |= g.STANDARD;
|
|
2440
|
+
outmask &= g.OUT_MASK;
|
|
2441
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
|
|
2442
|
+
vals = r.vals;
|
|
2443
|
+
if (outmask & g.AZIMUTH) {
|
|
2444
|
+
vals.azi1 = m.atan2d(r.salp1, r.calp1);
|
|
2445
|
+
vals.azi2 = m.atan2d(r.salp2, r.calp2);
|
|
2446
|
+
}
|
|
2447
|
+
return vals;
|
|
2448
|
+
};
|
|
2449
|
+
g.Geodesic.prototype.InverseInt = function(lat1, lon1, lat2, lon2, outmask) {
|
|
2450
|
+
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;
|
|
2451
|
+
vals.lat1 = lat1 = m.LatFix(lat1);
|
|
2452
|
+
vals.lat2 = lat2 = m.LatFix(lat2);
|
|
2453
|
+
lat1 = m.AngRound(lat1);
|
|
2454
|
+
lat2 = m.AngRound(lat2);
|
|
2455
|
+
lon12 = m.AngDiff(lon1, lon2);
|
|
2456
|
+
lon12s = lon12.e;
|
|
2457
|
+
lon12 = lon12.d;
|
|
2458
|
+
if (outmask & g.LONG_UNROLL) {
|
|
2459
|
+
vals.lon1 = lon1;
|
|
2460
|
+
vals.lon2 = lon1 + lon12 + lon12s;
|
|
2461
|
+
} else {
|
|
2462
|
+
vals.lon1 = m.AngNormalize(lon1);
|
|
2463
|
+
vals.lon2 = m.AngNormalize(lon2);
|
|
2464
|
+
}
|
|
2465
|
+
lonsign = m.copysign(1, lon12);
|
|
2466
|
+
lon12 *= lonsign;
|
|
2467
|
+
lon12s *= lonsign;
|
|
2468
|
+
lam12 = lon12 * m.degree;
|
|
2469
|
+
t = m.sincosde(lon12, lon12s);
|
|
2470
|
+
slam12 = t.s;
|
|
2471
|
+
clam12 = t.c;
|
|
2472
|
+
lon12s = 180 - lon12 - lon12s;
|
|
2473
|
+
swapp = Math.abs(lat1) < Math.abs(lat2) || isNaN(lat2) ? -1 : 1;
|
|
2474
|
+
if (swapp < 0) {
|
|
2475
|
+
lonsign *= -1;
|
|
2476
|
+
[lat2, lat1] = [lat1, lat2];
|
|
2477
|
+
}
|
|
2478
|
+
latsign = m.copysign(1, -lat1);
|
|
2479
|
+
lat1 *= latsign;
|
|
2480
|
+
lat2 *= latsign;
|
|
2481
|
+
t = m.sincosd(lat1);
|
|
2482
|
+
sbet1 = this._f1 * t.s;
|
|
2483
|
+
cbet1 = t.c;
|
|
2484
|
+
t = m.hypot(sbet1, cbet1);
|
|
2485
|
+
sbet1 /= t;
|
|
2486
|
+
cbet1 /= t;
|
|
2487
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
|
2488
|
+
t = m.sincosd(lat2);
|
|
2489
|
+
sbet2 = this._f1 * t.s;
|
|
2490
|
+
cbet2 = t.c;
|
|
2491
|
+
t = m.hypot(sbet2, cbet2);
|
|
2492
|
+
sbet2 /= t;
|
|
2493
|
+
cbet2 /= t;
|
|
2494
|
+
cbet2 = Math.max(g.tiny_, cbet2);
|
|
2495
|
+
if (cbet1 < -sbet1) {
|
|
2496
|
+
if (cbet2 === cbet1)
|
|
2497
|
+
sbet2 = m.copysign(sbet1, sbet2);
|
|
2498
|
+
} else {
|
|
2499
|
+
if (Math.abs(sbet2) === -sbet1)
|
|
2500
|
+
cbet2 = cbet1;
|
|
2501
|
+
}
|
|
2502
|
+
dn1 = Math.sqrt(1 + this._ep2 * m.sq(sbet1));
|
|
2503
|
+
dn2 = Math.sqrt(1 + this._ep2 * m.sq(sbet2));
|
|
2504
|
+
C1a = new Array(g.nC1_ + 1);
|
|
2505
|
+
C2a = new Array(g.nC2_ + 1);
|
|
2506
|
+
C3a = new Array(g.nC3_);
|
|
2507
|
+
meridian = lat1 === -90 || slam12 === 0;
|
|
2508
|
+
if (meridian) {
|
|
2509
|
+
calp1 = clam12;
|
|
2510
|
+
salp1 = slam12;
|
|
2511
|
+
calp2 = 1;
|
|
2512
|
+
salp2 = 0;
|
|
2513
|
+
ssig1 = sbet1;
|
|
2514
|
+
csig1 = calp1 * cbet1;
|
|
2515
|
+
ssig2 = sbet2;
|
|
2516
|
+
csig2 = calp2 * cbet2;
|
|
2517
|
+
sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2), csig1 * csig2 + ssig1 * ssig2);
|
|
2518
|
+
nvals = this.Lengths(this._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask | g.DISTANCE | g.REDUCEDLENGTH, C1a, C2a);
|
|
2519
|
+
s12x = nvals.s12b;
|
|
2520
|
+
m12x = nvals.m12b;
|
|
2521
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2522
|
+
vals.M12 = nvals.M12;
|
|
2523
|
+
vals.M21 = nvals.M21;
|
|
2524
|
+
}
|
|
2525
|
+
if (sig12 < tol2_ || m12x >= 0) {
|
|
2526
|
+
if (sig12 < 3 * g.tiny_ || // Prevent negative s12 or m12 for short lines
|
|
2527
|
+
sig12 < tol0_ && (s12x < 0 || m12x < 0))
|
|
2528
|
+
sig12 = m12x = s12x = 0;
|
|
2529
|
+
m12x *= this._b;
|
|
2530
|
+
s12x *= this._b;
|
|
2531
|
+
vals.a12 = sig12 / m.degree;
|
|
2532
|
+
} else
|
|
2533
|
+
meridian = false;
|
|
2534
|
+
}
|
|
2535
|
+
somg12 = 2;
|
|
2536
|
+
if (!meridian && sbet1 === 0 && // and sbet2 == 0
|
|
2537
|
+
(this.f <= 0 || lon12s >= this.f * 180)) {
|
|
2538
|
+
calp1 = calp2 = 0;
|
|
2539
|
+
salp1 = salp2 = 1;
|
|
2540
|
+
s12x = this.a * lam12;
|
|
2541
|
+
sig12 = omg12 = lam12 / this._f1;
|
|
2542
|
+
m12x = this._b * Math.sin(sig12);
|
|
2543
|
+
if (outmask & g.GEODESICSCALE)
|
|
2544
|
+
vals.M12 = vals.M21 = Math.cos(sig12);
|
|
2545
|
+
vals.a12 = lon12 / this._f1;
|
|
2546
|
+
} else if (!meridian) {
|
|
2547
|
+
nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a);
|
|
2548
|
+
sig12 = nvals.sig12;
|
|
2549
|
+
salp1 = nvals.salp1;
|
|
2550
|
+
calp1 = nvals.calp1;
|
|
2551
|
+
if (sig12 >= 0) {
|
|
2552
|
+
salp2 = nvals.salp2;
|
|
2553
|
+
calp2 = nvals.calp2;
|
|
2554
|
+
dnm = nvals.dnm;
|
|
2555
|
+
s12x = sig12 * this._b * dnm;
|
|
2556
|
+
m12x = m.sq(dnm) * this._b * Math.sin(sig12 / dnm);
|
|
2557
|
+
if (outmask & g.GEODESICSCALE)
|
|
2558
|
+
vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
|
|
2559
|
+
vals.a12 = sig12 / m.degree;
|
|
2560
|
+
omg12 = lam12 / (this._f1 * dnm);
|
|
2561
|
+
} else {
|
|
2562
|
+
numit = 0;
|
|
2563
|
+
salp1a = g.tiny_;
|
|
2564
|
+
calp1a = 1;
|
|
2565
|
+
salp1b = g.tiny_;
|
|
2566
|
+
calp1b = -1;
|
|
2567
|
+
for (tripn = false, tripb = false; ; ++numit) {
|
|
2568
|
+
nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
|
|
2569
|
+
v = nvals.lam12;
|
|
2570
|
+
salp2 = nvals.salp2;
|
|
2571
|
+
calp2 = nvals.calp2;
|
|
2572
|
+
sig12 = nvals.sig12;
|
|
2573
|
+
ssig1 = nvals.ssig1;
|
|
2574
|
+
csig1 = nvals.csig1;
|
|
2575
|
+
ssig2 = nvals.ssig2;
|
|
2576
|
+
csig2 = nvals.csig2;
|
|
2577
|
+
eps = nvals.eps;
|
|
2578
|
+
domg12 = nvals.domg12;
|
|
2579
|
+
dv = nvals.dlam12;
|
|
2580
|
+
if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_)
|
|
2581
|
+
break;
|
|
2582
|
+
if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
|
|
2583
|
+
salp1b = salp1;
|
|
2584
|
+
calp1b = calp1;
|
|
2585
|
+
} else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
|
|
2586
|
+
salp1a = salp1;
|
|
2587
|
+
calp1a = calp1;
|
|
2588
|
+
}
|
|
2589
|
+
if (numit < maxit1_ && dv > 0) {
|
|
2590
|
+
dalp1 = -v / dv;
|
|
2591
|
+
if (Math.abs(dalp1) < Math.PI) {
|
|
2592
|
+
sdalp1 = Math.sin(dalp1);
|
|
2593
|
+
cdalp1 = Math.cos(dalp1);
|
|
2594
|
+
nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
|
|
2595
|
+
if (nsalp1 > 0) {
|
|
2596
|
+
calp1 = calp1 * cdalp1 - salp1 * sdalp1;
|
|
2597
|
+
salp1 = nsalp1;
|
|
2598
|
+
t = m.hypot(salp1, calp1);
|
|
2599
|
+
salp1 /= t;
|
|
2600
|
+
calp1 /= t;
|
|
2601
|
+
tripn = Math.abs(v) <= 16 * tol0_;
|
|
2602
|
+
continue;
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
salp1 = (salp1a + salp1b) / 2;
|
|
2607
|
+
calp1 = (calp1a + calp1b) / 2;
|
|
2608
|
+
t = m.hypot(salp1, calp1);
|
|
2609
|
+
salp1 /= t;
|
|
2610
|
+
calp1 /= t;
|
|
2611
|
+
tripn = false;
|
|
2612
|
+
tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
|
|
2613
|
+
}
|
|
2614
|
+
lengthmask = outmask | (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ? g.DISTANCE : g.NONE);
|
|
2615
|
+
nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
|
|
2616
|
+
s12x = nvals.s12b;
|
|
2617
|
+
m12x = nvals.m12b;
|
|
2618
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2619
|
+
vals.M12 = nvals.M12;
|
|
2620
|
+
vals.M21 = nvals.M21;
|
|
2621
|
+
}
|
|
2622
|
+
m12x *= this._b;
|
|
2623
|
+
s12x *= this._b;
|
|
2624
|
+
vals.a12 = sig12 / m.degree;
|
|
2625
|
+
if (outmask & g.AREA) {
|
|
2626
|
+
sdomg12 = Math.sin(domg12);
|
|
2627
|
+
cdomg12 = Math.cos(domg12);
|
|
2628
|
+
somg12 = slam12 * cdomg12 - clam12 * sdomg12;
|
|
2629
|
+
comg12 = clam12 * cdomg12 + slam12 * sdomg12;
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
if (outmask & g.DISTANCE)
|
|
2634
|
+
vals.s12 = 0 + s12x;
|
|
2635
|
+
if (outmask & g.REDUCEDLENGTH)
|
|
2636
|
+
vals.m12 = 0 + m12x;
|
|
2637
|
+
if (outmask & g.AREA) {
|
|
2638
|
+
salp0 = salp1 * cbet1;
|
|
2639
|
+
calp0 = m.hypot(calp1, salp1 * sbet1);
|
|
2640
|
+
if (calp0 !== 0 && salp0 !== 0) {
|
|
2641
|
+
ssig1 = sbet1;
|
|
2642
|
+
csig1 = calp1 * cbet1;
|
|
2643
|
+
ssig2 = sbet2;
|
|
2644
|
+
csig2 = calp2 * cbet2;
|
|
2645
|
+
k2 = m.sq(calp0) * this._ep2;
|
|
2646
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
2647
|
+
A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
|
|
2648
|
+
t = m.hypot(ssig1, csig1);
|
|
2649
|
+
ssig1 /= t;
|
|
2650
|
+
csig1 /= t;
|
|
2651
|
+
t = m.hypot(ssig2, csig2);
|
|
2652
|
+
ssig2 /= t;
|
|
2653
|
+
csig2 /= t;
|
|
2654
|
+
C4a = new Array(g.nC4_);
|
|
2655
|
+
this.C4f(eps, C4a);
|
|
2656
|
+
B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
|
|
2657
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
|
|
2658
|
+
vals.S12 = A4 * (sig12 < 0.01 ? g.SinCosSeries(false, ssig1, csig1, C4a, sig12) : B42 - B41);
|
|
2659
|
+
} else
|
|
2660
|
+
vals.S12 = 0;
|
|
2661
|
+
if (!meridian && somg12 == 2) {
|
|
2662
|
+
somg12 = Math.sin(omg12);
|
|
2663
|
+
comg12 = Math.cos(omg12);
|
|
2664
|
+
}
|
|
2665
|
+
if (!meridian && comg12 > -0.7071 && // Long difference not too big
|
|
2666
|
+
sbet2 - sbet1 < 1.75) {
|
|
2667
|
+
domg12 = 1 + comg12;
|
|
2668
|
+
dbet1 = 1 + cbet1;
|
|
2669
|
+
dbet2 = 1 + cbet2;
|
|
2670
|
+
alp12 = 2 * Math.atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1), domg12 * (sbet1 * sbet2 + dbet1 * dbet2));
|
|
2671
|
+
} else {
|
|
2672
|
+
salp12 = salp2 * calp1 - calp2 * salp1;
|
|
2673
|
+
calp12 = calp2 * calp1 + salp2 * salp1;
|
|
2674
|
+
if (salp12 === 0 && calp12 < 0) {
|
|
2675
|
+
salp12 = g.tiny_ * calp1;
|
|
2676
|
+
calp12 = -1;
|
|
2677
|
+
}
|
|
2678
|
+
alp12 = Math.atan2(salp12, calp12);
|
|
2679
|
+
}
|
|
2680
|
+
vals.S12 += this._c2 * alp12;
|
|
2681
|
+
vals.S12 *= swapp * lonsign * latsign;
|
|
2682
|
+
vals.S12 += 0;
|
|
2683
|
+
}
|
|
2684
|
+
if (swapp < 0) {
|
|
2685
|
+
[salp2, salp1] = [salp1, salp2];
|
|
2686
|
+
[calp2, calp1] = [calp1, calp2];
|
|
2687
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2688
|
+
[vals.M21, vals.M12] = [vals.M12, vals.M21];
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
salp1 *= swapp * lonsign;
|
|
2692
|
+
calp1 *= swapp * latsign;
|
|
2693
|
+
salp2 *= swapp * lonsign;
|
|
2694
|
+
calp2 *= swapp * latsign;
|
|
2695
|
+
return {
|
|
2696
|
+
vals,
|
|
2697
|
+
salp1,
|
|
2698
|
+
calp1,
|
|
2699
|
+
salp2,
|
|
2700
|
+
calp2
|
|
2701
|
+
};
|
|
2702
|
+
};
|
|
2703
|
+
g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1, arcmode, s12_a12, outmask) {
|
|
2704
|
+
var line;
|
|
2705
|
+
if (!outmask)
|
|
2706
|
+
outmask = g.STANDARD;
|
|
2707
|
+
else if (outmask === g.LONG_UNROLL)
|
|
2708
|
+
outmask |= g.STANDARD;
|
|
2709
|
+
if (!arcmode)
|
|
2710
|
+
outmask |= g.DISTANCE_IN;
|
|
2711
|
+
line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
|
|
2712
|
+
return line.GenPosition(arcmode, s12_a12, outmask);
|
|
2713
|
+
};
|
|
2714
|
+
g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
|
|
2715
|
+
return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
|
|
2716
|
+
};
|
|
2717
|
+
g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
|
|
2718
|
+
return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
|
|
2719
|
+
};
|
|
2720
|
+
g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
|
|
2721
|
+
return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
2722
|
+
};
|
|
2723
|
+
g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
|
|
2724
|
+
return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
|
|
2725
|
+
};
|
|
2726
|
+
g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
|
|
2727
|
+
return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
|
|
2728
|
+
};
|
|
2729
|
+
g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1, arcmode, s12_a12, caps) {
|
|
2730
|
+
var t;
|
|
2731
|
+
if (!caps)
|
|
2732
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2733
|
+
if (!arcmode)
|
|
2734
|
+
caps |= g.DISTANCE_IN;
|
|
2735
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
2736
|
+
t.GenSetDistance(arcmode, s12_a12);
|
|
2737
|
+
return t;
|
|
2738
|
+
};
|
|
2739
|
+
g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
|
|
2740
|
+
var r, t, azi1;
|
|
2741
|
+
if (!caps)
|
|
2742
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2743
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
|
|
2744
|
+
azi1 = m.atan2d(r.salp1, r.calp1);
|
|
2745
|
+
if (caps & (g.OUT_MASK & g.DISTANCE_IN))
|
|
2746
|
+
caps |= g.DISTANCE;
|
|
2747
|
+
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
|
|
2748
|
+
t.SetArc(r.vals.a12);
|
|
2749
|
+
return t;
|
|
2750
|
+
};
|
|
2751
|
+
g.Geodesic.prototype.Polygon = function(polyline) {
|
|
2752
|
+
return new p.PolygonArea(this, polyline);
|
|
2753
|
+
};
|
|
2754
|
+
g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
|
|
2755
|
+
})(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.PolygonArea, geodesic.Math, geodesic.Constants);
|
|
2756
|
+
(function(g, l, m) {
|
|
2757
|
+
"use strict";
|
|
2758
|
+
l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
|
|
2759
|
+
var t, cbet1, sbet1, eps, s, c;
|
|
2760
|
+
if (!caps)
|
|
2761
|
+
caps = g.STANDARD | g.DISTANCE_IN;
|
|
2762
|
+
this.a = geod.a;
|
|
2763
|
+
this.f = geod.f;
|
|
2764
|
+
this._b = geod._b;
|
|
2765
|
+
this._c2 = geod._c2;
|
|
2766
|
+
this._f1 = geod._f1;
|
|
2767
|
+
this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
|
|
2768
|
+
this.lat1 = m.LatFix(lat1);
|
|
2769
|
+
this.lon1 = lon1;
|
|
2770
|
+
if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
|
|
2771
|
+
this.azi1 = m.AngNormalize(azi1);
|
|
2772
|
+
t = m.sincosd(m.AngRound(this.azi1));
|
|
2773
|
+
this.salp1 = t.s;
|
|
2774
|
+
this.calp1 = t.c;
|
|
2775
|
+
} else {
|
|
2776
|
+
this.azi1 = azi1;
|
|
2777
|
+
this.salp1 = salp1;
|
|
2778
|
+
this.calp1 = calp1;
|
|
2779
|
+
}
|
|
2780
|
+
t = m.sincosd(m.AngRound(this.lat1));
|
|
2781
|
+
sbet1 = this._f1 * t.s;
|
|
2782
|
+
cbet1 = t.c;
|
|
2783
|
+
t = m.hypot(sbet1, cbet1);
|
|
2784
|
+
sbet1 /= t;
|
|
2785
|
+
cbet1 /= t;
|
|
2786
|
+
cbet1 = Math.max(g.tiny_, cbet1);
|
|
2787
|
+
this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
|
|
2788
|
+
this._salp0 = this.salp1 * cbet1;
|
|
2789
|
+
this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
|
|
2790
|
+
this._ssig1 = sbet1;
|
|
2791
|
+
this._somg1 = this._salp0 * sbet1;
|
|
2792
|
+
this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
|
|
2793
|
+
t = m.hypot(this._ssig1, this._csig1);
|
|
2794
|
+
this._ssig1 /= t;
|
|
2795
|
+
this._csig1 /= t;
|
|
2796
|
+
this._k2 = m.sq(this._calp0) * geod._ep2;
|
|
2797
|
+
eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
|
|
2798
|
+
if (this.caps & g.CAP_C1) {
|
|
2799
|
+
this._A1m1 = g.A1m1f(eps);
|
|
2800
|
+
this._C1a = new Array(g.nC1_ + 1);
|
|
2801
|
+
g.C1f(eps, this._C1a);
|
|
2802
|
+
this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
|
|
2803
|
+
s = Math.sin(this._B11);
|
|
2804
|
+
c = Math.cos(this._B11);
|
|
2805
|
+
this._stau1 = this._ssig1 * c + this._csig1 * s;
|
|
2806
|
+
this._ctau1 = this._csig1 * c - this._ssig1 * s;
|
|
2807
|
+
}
|
|
2808
|
+
if (this.caps & g.CAP_C1p) {
|
|
2809
|
+
this._C1pa = new Array(g.nC1p_ + 1);
|
|
2810
|
+
g.C1pf(eps, this._C1pa);
|
|
2811
|
+
}
|
|
2812
|
+
if (this.caps & g.CAP_C2) {
|
|
2813
|
+
this._A2m1 = g.A2m1f(eps);
|
|
2814
|
+
this._C2a = new Array(g.nC2_ + 1);
|
|
2815
|
+
g.C2f(eps, this._C2a);
|
|
2816
|
+
this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
|
|
2817
|
+
}
|
|
2818
|
+
if (this.caps & g.CAP_C3) {
|
|
2819
|
+
this._C3a = new Array(g.nC3_);
|
|
2820
|
+
geod.C3f(eps, this._C3a);
|
|
2821
|
+
this._A3c = -this.f * this._salp0 * geod.A3f(eps);
|
|
2822
|
+
this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
|
|
2823
|
+
}
|
|
2824
|
+
if (this.caps & g.CAP_C4) {
|
|
2825
|
+
this._C4a = new Array(g.nC4_);
|
|
2826
|
+
geod.C4f(eps, this._C4a);
|
|
2827
|
+
this._A4 = m.sq(this.a) * this._calp0 * this._salp0 * geod._e2;
|
|
2828
|
+
this._B41 = g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
|
|
2829
|
+
}
|
|
2830
|
+
this.a13 = this.s13 = NaN;
|
|
2831
|
+
};
|
|
2832
|
+
l.GeodesicLine.prototype.GenPosition = function(arcmode, s12_a12, outmask, vals = {}) {
|
|
2833
|
+
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;
|
|
2834
|
+
if (!outmask)
|
|
2835
|
+
outmask = g.STANDARD;
|
|
2836
|
+
else if (outmask === g.LONG_UNROLL)
|
|
2837
|
+
outmask |= g.STANDARD;
|
|
2838
|
+
outmask &= this.caps & g.OUT_MASK;
|
|
2839
|
+
vals.lat1 = this.lat1;
|
|
2840
|
+
vals.azi1 = this.azi1;
|
|
2841
|
+
vals.lon1 = outmask & g.LONG_UNROLL ? this.lon1 : m.AngNormalize(this.lon1);
|
|
2842
|
+
if (arcmode)
|
|
2843
|
+
vals.a12 = s12_a12;
|
|
2844
|
+
else
|
|
2845
|
+
vals.s12 = s12_a12;
|
|
2846
|
+
if (!(arcmode || this.caps & g.DISTANCE_IN & g.OUT_MASK)) {
|
|
2847
|
+
vals.a12 = NaN;
|
|
2848
|
+
return vals;
|
|
2849
|
+
}
|
|
2850
|
+
B12 = 0;
|
|
2851
|
+
AB1 = 0;
|
|
2852
|
+
if (arcmode) {
|
|
2853
|
+
sig12 = s12_a12 * m.degree;
|
|
2854
|
+
t = m.sincosd(s12_a12);
|
|
2855
|
+
ssig12 = t.s;
|
|
2856
|
+
csig12 = t.c;
|
|
2857
|
+
} else {
|
|
2858
|
+
tau12 = s12_a12 / (this._b * (1 + this._A1m1));
|
|
2859
|
+
s = Math.sin(tau12);
|
|
2860
|
+
c = Math.cos(tau12);
|
|
2861
|
+
B12 = -g.SinCosSeries(true, this._stau1 * c + this._ctau1 * s, this._ctau1 * c - this._stau1 * s, this._C1pa);
|
|
2862
|
+
sig12 = tau12 - (B12 - this._B11);
|
|
2863
|
+
ssig12 = Math.sin(sig12);
|
|
2864
|
+
csig12 = Math.cos(sig12);
|
|
2865
|
+
if (Math.abs(this.f) > 0.01) {
|
|
2866
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
2867
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
2868
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
2869
|
+
serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) - s12_a12 / this._b;
|
|
2870
|
+
sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
|
2871
|
+
ssig12 = Math.sin(sig12);
|
|
2872
|
+
csig12 = Math.cos(sig12);
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
2876
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
2877
|
+
dn2 = Math.sqrt(1 + this._k2 * m.sq(ssig2));
|
|
2878
|
+
if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2879
|
+
if (arcmode || Math.abs(this.f) > 0.01)
|
|
2880
|
+
B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
2881
|
+
AB1 = (1 + this._A1m1) * (B12 - this._B11);
|
|
2882
|
+
}
|
|
2883
|
+
sbet2 = this._calp0 * ssig2;
|
|
2884
|
+
cbet2 = m.hypot(this._salp0, this._calp0 * csig2);
|
|
2885
|
+
if (cbet2 === 0)
|
|
2886
|
+
cbet2 = csig2 = g.tiny_;
|
|
2887
|
+
salp2 = this._salp0;
|
|
2888
|
+
calp2 = this._calp0 * csig2;
|
|
2889
|
+
if (arcmode && outmask & g.DISTANCE)
|
|
2890
|
+
vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
|
|
2891
|
+
if (outmask & g.LONGITUDE) {
|
|
2892
|
+
somg2 = this._salp0 * ssig2;
|
|
2893
|
+
comg2 = csig2;
|
|
2894
|
+
E = m.copysign(1, this._salp0);
|
|
2895
|
+
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);
|
|
2896
|
+
lam12 = omg12 + this._A3c * (sig12 + (g.SinCosSeries(true, ssig2, csig2, this._C3a) - this._B31));
|
|
2897
|
+
lon12 = lam12 / m.degree;
|
|
2898
|
+
vals.lon2 = outmask & g.LONG_UNROLL ? this.lon1 + lon12 : m.AngNormalize(m.AngNormalize(this.lon1) + m.AngNormalize(lon12));
|
|
2899
|
+
}
|
|
2900
|
+
if (outmask & g.LATITUDE)
|
|
2901
|
+
vals.lat2 = m.atan2d(sbet2, this._f1 * cbet2);
|
|
2902
|
+
if (outmask & g.AZIMUTH)
|
|
2903
|
+
vals.azi2 = m.atan2d(salp2, calp2);
|
|
2904
|
+
if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
|
|
2905
|
+
B22 = g.SinCosSeries(true, ssig2, csig2, this._C2a);
|
|
2906
|
+
AB2 = (1 + this._A2m1) * (B22 - this._B21);
|
|
2907
|
+
J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
|
|
2908
|
+
if (outmask & g.REDUCEDLENGTH)
|
|
2909
|
+
vals.m12 = this._b * (dn2 * (this._csig1 * ssig2) - this._dn1 * (this._ssig1 * csig2) - this._csig1 * csig2 * J12);
|
|
2910
|
+
if (outmask & g.GEODESICSCALE) {
|
|
2911
|
+
t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) / (this._dn1 + dn2);
|
|
2912
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
|
|
2913
|
+
vals.M21 = csig12 - (t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
if (outmask & g.AREA) {
|
|
2917
|
+
B42 = g.SinCosSeries(false, ssig2, csig2, this._C4a);
|
|
2918
|
+
if (this._calp0 === 0 || this._salp0 === 0) {
|
|
2919
|
+
salp12 = salp2 * this.calp1 - calp2 * this.salp1;
|
|
2920
|
+
calp12 = calp2 * this.calp1 + salp2 * this.salp1;
|
|
2921
|
+
} else {
|
|
2922
|
+
salp12 = this._calp0 * this._salp0 * (csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 : ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
|
|
2923
|
+
calp12 = m.sq(this._salp0) + m.sq(this._calp0) * this._csig1 * csig2;
|
|
2924
|
+
}
|
|
2925
|
+
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);
|
|
2926
|
+
}
|
|
2927
|
+
if (!arcmode)
|
|
2928
|
+
vals.a12 = sig12 / m.degree;
|
|
2929
|
+
return vals;
|
|
2930
|
+
};
|
|
2931
|
+
l.GeodesicLine.prototype.Position = function(s12, outmask) {
|
|
2932
|
+
return this.GenPosition(false, s12, outmask);
|
|
2933
|
+
};
|
|
2934
|
+
l.GeodesicLine.prototype.ArcPosition = function(a12, outmask) {
|
|
2935
|
+
return this.GenPosition(true, a12, outmask);
|
|
2936
|
+
};
|
|
2937
|
+
l.GeodesicLine.prototype.GenSetDistance = function(arcmode, s13_a13) {
|
|
2938
|
+
if (arcmode)
|
|
2939
|
+
this.SetArc(s13_a13);
|
|
2940
|
+
else
|
|
2941
|
+
this.SetDistance(s13_a13);
|
|
2942
|
+
};
|
|
2943
|
+
l.GeodesicLine.prototype.SetDistance = function(s13) {
|
|
2944
|
+
var r;
|
|
2945
|
+
this.s13 = s13;
|
|
2946
|
+
r = this.GenPosition(false, this.s13, g.ARC);
|
|
2947
|
+
this.a13 = 0 + r.a12;
|
|
2948
|
+
};
|
|
2949
|
+
l.GeodesicLine.prototype.SetArc = function(a13) {
|
|
2950
|
+
var r;
|
|
2951
|
+
this.a13 = a13;
|
|
2952
|
+
r = this.GenPosition(true, this.a13, g.DISTANCE);
|
|
2953
|
+
this.s13 = 0 + r.s12;
|
|
2954
|
+
};
|
|
2955
|
+
})(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.Math);
|
|
2956
|
+
|
|
2957
|
+
// dist/ellipsoid-geodesic.js
|
|
2958
|
+
var library = geodesic.Geodesic;
|
|
2959
|
+
var EllipsoidGeodesic = class {
|
|
2960
|
+
constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
|
|
2961
|
+
this.engine = createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b });
|
|
2962
|
+
}
|
|
2963
|
+
/** Total area in squared axis units, with the same normalization as S12. */
|
|
2964
|
+
get surfaceArea() {
|
|
2965
|
+
return 4 * Math.PI * this.engine._c2;
|
|
2966
|
+
}
|
|
2967
|
+
inverse(lat1, lon1, lat2, lon2, options = {}) {
|
|
2968
|
+
validatePoint(lat1, lon1);
|
|
2969
|
+
validatePoint(lat2, lon2);
|
|
2970
|
+
return this.engine.Inverse(lat1, lon1, lat2, lon2, outputMask(options));
|
|
2971
|
+
}
|
|
2972
|
+
direct(latitude, longitude, azimuth, distance, options = {}) {
|
|
2973
|
+
return this.line(latitude, longitude, azimuth, options).position(distance);
|
|
2974
|
+
}
|
|
2975
|
+
arcDirect(latitude, longitude, azimuth, arc, options = {}) {
|
|
2976
|
+
return this.line(latitude, longitude, azimuth, options).arcPosition(arc);
|
|
2977
|
+
}
|
|
2978
|
+
line(latitude, longitude, azimuth, options = {}) {
|
|
2979
|
+
validatePoint(latitude, longitude);
|
|
2980
|
+
validateFinite(azimuth);
|
|
2981
|
+
const selectedMask = outputMask(options);
|
|
2982
|
+
const line = this.engine.Line(latitude, longitude, azimuth, selectedMask | library.DISTANCE_IN);
|
|
2983
|
+
return {
|
|
2984
|
+
// Fourth argument is an internal result request; ordinary Array.map arguments remain ignored.
|
|
2985
|
+
position(distance, _index, _array, output) {
|
|
2986
|
+
validateFinite(distance);
|
|
2987
|
+
return line.GenPosition(false, distance, selectedMask, output);
|
|
2988
|
+
},
|
|
2989
|
+
arcPosition(arc) {
|
|
2990
|
+
validateFinite(arc);
|
|
2991
|
+
return line.ArcPosition(arc, selectedMask);
|
|
2992
|
+
}
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2996
|
+
function validatePoint(latitude, longitude) {
|
|
2997
|
+
if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
|
|
2998
|
+
throw new Error("Invalid geodesic coordinates");
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
function outputMask(options) {
|
|
3002
|
+
return library.ALL & ~(options.area ? 0 : library.AREA) | (options.unrollLongitude ? library.LONG_UNROLL : 0);
|
|
3003
|
+
}
|
|
3004
|
+
function validateFinite(value) {
|
|
3005
|
+
if (!Number.isFinite(value))
|
|
3006
|
+
throw new Error("Nonfinite axis, azimuth, distance or arc");
|
|
3007
|
+
}
|
|
3008
|
+
var nonAreaGeodesicMask = library.ALL & ~library.AREA;
|
|
3009
|
+
function createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b }) {
|
|
3010
|
+
validateFinite(a);
|
|
3011
|
+
validateFinite(b);
|
|
3012
|
+
return new library.Geodesic(a, (a - b) / a);
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
// dist/st-geodesic-functions.js
|
|
3016
|
+
var kernel;
|
|
3017
|
+
function meters(a, b) {
|
|
3018
|
+
kernel ?? (kernel = new EllipsoidGeodesic({
|
|
3019
|
+
semiMajorAxis: WGS84_RADIUS_X,
|
|
3020
|
+
semiMinorAxis: WGS84_RADIUS_Z
|
|
3021
|
+
}));
|
|
3022
|
+
return kernel.inverse(a[1], a[0], b[1], b[0]).s12;
|
|
3023
|
+
}
|
|
3024
|
+
function emptyPoint(coordinate) {
|
|
3025
|
+
return !coordinate.length || coordinate.every(Number.isNaN);
|
|
3026
|
+
}
|
|
3027
|
+
function pointDistance(a, b) {
|
|
3028
|
+
if (a.type !== "Point" || b.type !== "Point")
|
|
3029
|
+
throw new Error("Expected geodesic point pair");
|
|
3030
|
+
return emptyPoint(a.coordinates) || emptyPoint(b.coordinates) ? null : meters(a.coordinates, b.coordinates);
|
|
3031
|
+
}
|
|
3032
|
+
function lineLength(geometry) {
|
|
3033
|
+
const lines = geometry.type === "LineString" ? [geometry.coordinates] : geometry.type === "MultiLineString" ? geometry.coordinates : [];
|
|
3034
|
+
let length = 0;
|
|
3035
|
+
for (const path of lines)
|
|
3036
|
+
for (let index = 1; index < path.length; index++)
|
|
3037
|
+
length += meters(path[index - 1], path[index]);
|
|
3038
|
+
return length;
|
|
3039
|
+
}
|
|
3040
|
+
function isWGS84(crs) {
|
|
3041
|
+
if (typeof crs === "string") {
|
|
3042
|
+
const identifier = normalizeCRSIdentifier(crs);
|
|
3043
|
+
return identifier === "EPSG:4326" || identifier === "OGC:CRS84";
|
|
3044
|
+
}
|
|
3045
|
+
if (!crs || typeof crs !== "object" || !("id" in crs))
|
|
3046
|
+
return false;
|
|
3047
|
+
const { id } = crs;
|
|
3048
|
+
return Boolean(id && typeof id === "object" && "authority" in id && "code" in id && isWGS84(String(id.authority) + ":" + String(id.code)));
|
|
3049
|
+
}
|
|
3050
|
+
function validateWGS84(crs, name) {
|
|
3051
|
+
if (!isWGS84(crs))
|
|
3052
|
+
throw new Error(`${name} requires WGS84 CRS metadata (EPSG:4326 or OGC:CRS84)`);
|
|
3053
|
+
}
|
|
3054
|
+
var ST_GEODESICDISTANCE = /* @__PURE__ */ spatialFunction(
|
|
3055
|
+
"ST_GeodesicDistance",
|
|
3056
|
+
[pointKinds, pointKinds],
|
|
3057
|
+
/* @__PURE__ */ new import_apache_arrow2.Float64(),
|
|
3058
|
+
([a, b]) => pointDistance(a, b),
|
|
3059
|
+
0,
|
|
3060
|
+
true,
|
|
3061
|
+
false,
|
|
3062
|
+
validateWGS84
|
|
3063
|
+
);
|
|
3064
|
+
var ST_GEODESICLENGTH = /* @__PURE__ */ spatialFunction(
|
|
3065
|
+
"ST_GeodesicLength",
|
|
3066
|
+
[lineKinds],
|
|
3067
|
+
/* @__PURE__ */ new import_apache_arrow2.Float64(),
|
|
3068
|
+
([line]) => lineLength(line),
|
|
3069
|
+
0,
|
|
3070
|
+
true,
|
|
3071
|
+
false,
|
|
3072
|
+
validateWGS84
|
|
3073
|
+
);
|
|
3074
|
+
var ST_GEODESICDWITHIN = /* @__PURE__ */ spatialFunction(
|
|
3075
|
+
"ST_GeodesicDWithin",
|
|
3076
|
+
[pointKinds, pointKinds],
|
|
3077
|
+
/* @__PURE__ */ new import_apache_arrow2.Bool(),
|
|
3078
|
+
([a, b], radius) => {
|
|
3079
|
+
if (!Number.isFinite(radius) || radius < 0)
|
|
3080
|
+
throw new Error("ST_GeodesicDWithin requires a finite nonnegative radius in meters");
|
|
3081
|
+
const distance = pointDistance(a, b);
|
|
3082
|
+
return distance !== null && distance <= radius;
|
|
3083
|
+
},
|
|
3084
|
+
1,
|
|
3085
|
+
true,
|
|
3086
|
+
false,
|
|
3087
|
+
validateWGS84
|
|
3088
|
+
);
|
|
3089
|
+
var GEODESIC_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
3090
|
+
ST_GEODESICDISTANCE,
|
|
3091
|
+
ST_GEODESICLENGTH,
|
|
3092
|
+
ST_GEODESICDWITHIN
|
|
3093
|
+
]);
|
|
3094
|
+
|
|
979
3095
|
// dist/st-functions.js
|
|
980
3096
|
var ST_MAKEPOINT = {
|
|
981
3097
|
kind: "scalar",
|
|
@@ -986,14 +3102,14 @@ var ST_MAKEPOINT = {
|
|
|
986
3102
|
if (fields.length < 2 || fields.length > 4)
|
|
987
3103
|
return void 0;
|
|
988
3104
|
const arguments_ = fields.map((field) => {
|
|
989
|
-
if (field && !
|
|
3105
|
+
if (field && !import_apache_arrow3.DataType.isInt(field.type) && !import_apache_arrow3.DataType.isFloat(field.type))
|
|
990
3106
|
throw new Error("ST_MakePoint requires numeric coordinates");
|
|
991
|
-
return field ?? new
|
|
3107
|
+
return field ?? new import_apache_arrow3.Field("coordinate", new import_apache_arrow3.Float64(), true);
|
|
992
3108
|
});
|
|
993
|
-
const type = new
|
|
3109
|
+
const type = new import_apache_arrow3.Binary();
|
|
994
3110
|
return {
|
|
995
3111
|
arguments: arguments_,
|
|
996
|
-
result: new
|
|
3112
|
+
result: new import_apache_arrow3.Field("ST_MakePoint", type, true, /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.wkb"]])),
|
|
997
3113
|
/** Writes one point per active row, retaining nulls in all other rows. */
|
|
998
3114
|
evaluate(vectors, { activeRows, length }) {
|
|
999
3115
|
const values = new Array(length).fill(null);
|
|
@@ -1003,7 +3119,7 @@ var ST_MAKEPOINT = {
|
|
|
1003
3119
|
values[row] = (0, import_arrow4.writeWKB)({ type: "Point", coordinates });
|
|
1004
3120
|
}
|
|
1005
3121
|
}
|
|
1006
|
-
return (0,
|
|
3122
|
+
return (0, import_apache_arrow3.vectorFromArray)(values, type);
|
|
1007
3123
|
}
|
|
1008
3124
|
};
|
|
1009
3125
|
}
|
|
@@ -1052,21 +3168,21 @@ var ST_TILEENVELOPE = {
|
|
|
1052
3168
|
ST_ENVELOPE.resolvePrototype([root]);
|
|
1053
3169
|
const args = fields.map((field, i) => {
|
|
1054
3170
|
if (i === 3)
|
|
1055
|
-
return field ?? new
|
|
1056
|
-
if (field && !
|
|
3171
|
+
return field ?? new import_apache_arrow3.Field("bounds", new import_apache_arrow3.Binary(), true);
|
|
3172
|
+
if (field && !import_apache_arrow3.DataType.isInt(field.type) && !import_apache_arrow3.DataType.isFloat(field.type))
|
|
1057
3173
|
throw new Error("ST_TileEnvelope requires numeric indices and margin");
|
|
1058
|
-
return field ?? new
|
|
3174
|
+
return field ?? new import_apache_arrow3.Field("number", new import_apache_arrow3.Float64(), true);
|
|
1059
3175
|
});
|
|
1060
3176
|
const metadata = /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.wkb"]]);
|
|
1061
3177
|
const crs = custom ? root == null ? void 0 : root.metadata.get(EXTENSION_METADATA) : '{"crs_type":"authority_code","crs":"EPSG:3857"}';
|
|
1062
3178
|
if (crs)
|
|
1063
3179
|
metadata.set(EXTENSION_METADATA, crs);
|
|
1064
|
-
const type = new
|
|
3180
|
+
const type = new import_apache_arrow3.Binary();
|
|
1065
3181
|
const r = EPSG3857_HALF_CIRCUMFERENCE;
|
|
1066
3182
|
const world = [-r, -r, r, r];
|
|
1067
3183
|
return {
|
|
1068
3184
|
arguments: args,
|
|
1069
|
-
result: new
|
|
3185
|
+
result: new import_apache_arrow3.Field("ST_TileEnvelope", type, true, metadata),
|
|
1070
3186
|
/** Computes bounds for active rows using the top-left XYZ origin. */
|
|
1071
3187
|
evaluate(vectors, { activeRows, length }) {
|
|
1072
3188
|
const values = new Array(length).fill(null);
|
|
@@ -1079,7 +3195,7 @@ var ST_TILEENVELOPE = {
|
|
|
1079
3195
|
throw new Error("ST_TileEnvelope requires nonempty bounds");
|
|
1080
3196
|
values[row] = tileEnvelope(Number(vectors[0].get(row)), Number(vectors[1].get(row)), Number(vectors[2].get(row)), bounds, vectors[4] ? Number(vectors[4].get(row)) : 0);
|
|
1081
3197
|
}
|
|
1082
|
-
return (0,
|
|
3198
|
+
return (0, import_apache_arrow3.vectorFromArray)(values, type);
|
|
1083
3199
|
}
|
|
1084
3200
|
};
|
|
1085
3201
|
}
|
|
@@ -1094,17 +3210,17 @@ function pointOrdinate(ordinate) {
|
|
|
1094
3210
|
resolvePrototype(fields) {
|
|
1095
3211
|
if (fields.length !== 1)
|
|
1096
3212
|
return void 0;
|
|
1097
|
-
const field = fields[0] ?? new
|
|
3213
|
+
const field = fields[0] ?? new import_apache_arrow3.Field("point", new import_apache_arrow3.Binary(), true, /* @__PURE__ */ new Map([[EXTENSION_NAME, "geoarrow.wkb"]]));
|
|
1098
3214
|
const extension = (0, import_arrow4.getGeoArrowFieldInfo)(field);
|
|
1099
3215
|
if ((extension == null ? void 0 : extension.metadata["edges"]) === "spherical")
|
|
1100
3216
|
throw new Error(`${name} requires planar geometry`);
|
|
1101
3217
|
const encoding = extension == null ? void 0 : extension.encoding;
|
|
1102
|
-
if (encoding !== "geoarrow.point" && !(encoding === "geoarrow.wkb" && (
|
|
3218
|
+
if (encoding !== "geoarrow.point" && !(encoding === "geoarrow.wkb" && (import_apache_arrow3.DataType.isBinary(field.type) || import_apache_arrow3.DataType.isLargeBinary(field.type))))
|
|
1103
3219
|
throw new Error(`${name} requires a GeoArrow Point`);
|
|
1104
|
-
const type = new
|
|
3220
|
+
const type = new import_apache_arrow3.Float64();
|
|
1105
3221
|
return {
|
|
1106
3222
|
arguments: [field],
|
|
1107
|
-
result: new
|
|
3223
|
+
result: new import_apache_arrow3.Field(name, type, true),
|
|
1108
3224
|
/** Extracts ordinates using the WKB row or native field dimension. */
|
|
1109
3225
|
evaluate([vector], { length, activeRows }) {
|
|
1110
3226
|
if (encoding === "geoarrow.point") {
|
|
@@ -1119,7 +3235,7 @@ function pointOrdinate(ordinate) {
|
|
|
1119
3235
|
return coordinate;
|
|
1120
3236
|
});
|
|
1121
3237
|
}
|
|
1122
|
-
return (0,
|
|
3238
|
+
return (0, import_apache_arrow3.vectorFromArray)(result2, type);
|
|
1123
3239
|
}
|
|
1124
3240
|
const read = readGeometryValue(vector, field, activeRows, (geometry, dimension) => {
|
|
1125
3241
|
var _a;
|
|
@@ -1127,7 +3243,7 @@ function pointOrdinate(ordinate) {
|
|
|
1127
3243
|
throw new Error(`${name} requires a Point`);
|
|
1128
3244
|
return ((_a = pointCoordinates(geometry)) == null ? void 0 : _a[dimension.indexOf(ordinate)]) ?? null;
|
|
1129
3245
|
});
|
|
1130
|
-
return (0,
|
|
3246
|
+
return (0, import_apache_arrow3.vectorFromArray)(Array.from({ length }, (_, i) => activeRows[i] ? read(i) : null), type);
|
|
1131
3247
|
}
|
|
1132
3248
|
};
|
|
1133
3249
|
}
|
|
@@ -1140,7 +3256,7 @@ var ST_M = /* @__PURE__ */ pointOrdinate("m");
|
|
|
1140
3256
|
var ST_STARTPOINT = /* @__PURE__ */ spatialFunction(
|
|
1141
3257
|
"ST_StartPoint",
|
|
1142
3258
|
[["LineString"]],
|
|
1143
|
-
/* @__PURE__ */ new
|
|
3259
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1144
3260
|
([line]) => {
|
|
1145
3261
|
if ((line == null ? void 0 : line.type) !== "LineString" || !line.coordinates.length)
|
|
1146
3262
|
return null;
|
|
@@ -1150,7 +3266,7 @@ var ST_STARTPOINT = /* @__PURE__ */ spatialFunction(
|
|
|
1150
3266
|
var ST_ENDPOINT = /* @__PURE__ */ spatialFunction(
|
|
1151
3267
|
"ST_EndPoint",
|
|
1152
3268
|
[["LineString"]],
|
|
1153
|
-
/* @__PURE__ */ new
|
|
3269
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1154
3270
|
([line]) => {
|
|
1155
3271
|
if ((line == null ? void 0 : line.type) !== "LineString" || !line.coordinates.length)
|
|
1156
3272
|
return null;
|
|
@@ -1160,31 +3276,31 @@ var ST_ENDPOINT = /* @__PURE__ */ spatialFunction(
|
|
|
1160
3276
|
var ST_CONTAINS = /* @__PURE__ */ spatialFunction(
|
|
1161
3277
|
"ST_Contains",
|
|
1162
3278
|
[polygonKinds, pointKinds],
|
|
1163
|
-
/* @__PURE__ */ new
|
|
3279
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1164
3280
|
([polygon, point2]) => pointInPolygon(point2, polygon, true) ?? false
|
|
1165
3281
|
);
|
|
1166
3282
|
var ST_COVERS = /* @__PURE__ */ spatialFunction(
|
|
1167
3283
|
"ST_Covers",
|
|
1168
3284
|
[polygonKinds, pointKinds],
|
|
1169
|
-
/* @__PURE__ */ new
|
|
3285
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1170
3286
|
([polygon, point2]) => pointInPolygon(point2, polygon) ?? false
|
|
1171
3287
|
);
|
|
1172
3288
|
var ST_WITHIN = /* @__PURE__ */ spatialFunction(
|
|
1173
3289
|
"ST_Within",
|
|
1174
3290
|
[pointKinds, polygonKinds],
|
|
1175
|
-
/* @__PURE__ */ new
|
|
3291
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1176
3292
|
([p, polygon]) => pointInPolygon(p, polygon, true) ?? false
|
|
1177
3293
|
);
|
|
1178
3294
|
var ST_COVEREDBY = /* @__PURE__ */ spatialFunction(
|
|
1179
3295
|
"ST_CoveredBy",
|
|
1180
3296
|
[pointKinds, polygonKinds],
|
|
1181
|
-
/* @__PURE__ */ new
|
|
3297
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1182
3298
|
([p, polygon]) => pointInPolygon(p, polygon) ?? false
|
|
1183
3299
|
);
|
|
1184
3300
|
var ST_POINTN = /* @__PURE__ */ spatialFunction(
|
|
1185
3301
|
"ST_PointN",
|
|
1186
3302
|
[["LineString"]],
|
|
1187
|
-
/* @__PURE__ */ new
|
|
3303
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1188
3304
|
([line], position) => {
|
|
1189
3305
|
if (!Number.isInteger(position))
|
|
1190
3306
|
throw new Error("ST_PointN requires an integer position");
|
|
@@ -1199,7 +3315,7 @@ var ST_POINTN = /* @__PURE__ */ spatialFunction(
|
|
|
1199
3315
|
var ST_MAKEENVELOPE = /* @__PURE__ */ spatialFunction(
|
|
1200
3316
|
"ST_MakeEnvelope",
|
|
1201
3317
|
[],
|
|
1202
|
-
/* @__PURE__ */ new
|
|
3318
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1203
3319
|
(_, xmin, ymin, xmax, ymax) => (0, import_arrow4.writeWKB)({
|
|
1204
3320
|
type: "Polygon",
|
|
1205
3321
|
coordinates: [
|
|
@@ -1217,58 +3333,160 @@ var ST_MAKEENVELOPE = /* @__PURE__ */ spatialFunction(
|
|
|
1217
3333
|
var ST_DISTANCE = /* @__PURE__ */ spatialFunction(
|
|
1218
3334
|
"ST_Distance",
|
|
1219
3335
|
[pointKinds, pointKinds],
|
|
1220
|
-
/* @__PURE__ */ new
|
|
3336
|
+
/* @__PURE__ */ new import_apache_arrow3.Float64(),
|
|
1221
3337
|
([a, b]) => {
|
|
1222
3338
|
const p = pointCoordinates(a);
|
|
1223
3339
|
const q = pointCoordinates(b);
|
|
1224
3340
|
return p && q ? Math.hypot(q[0] - p[0], q[1] - p[1]) : null;
|
|
1225
3341
|
}
|
|
1226
3342
|
);
|
|
1227
|
-
var
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
3343
|
+
var routePointKinds = ["Point", "LineString"];
|
|
3344
|
+
function closestPair(a, b) {
|
|
3345
|
+
if (a.type === "LineString" && b.type === "LineString") {
|
|
3346
|
+
throw new Error("Route snapping requires at least one Point");
|
|
3347
|
+
}
|
|
3348
|
+
if (a.type === "LineString" || b.type === "LineString") {
|
|
3349
|
+
const lineFirst = a.type === "LineString";
|
|
3350
|
+
const point2 = lineFirst ? b : a;
|
|
3351
|
+
const xy = pointCoordinates(point2);
|
|
3352
|
+
const projection = projectPointToLine(lineFirst ? a : b, point2);
|
|
3353
|
+
if (!xy || !projection)
|
|
3354
|
+
return null;
|
|
3355
|
+
const { coordinate, distance } = projection;
|
|
3356
|
+
return { start: lineFirst ? coordinate : xy, end: lineFirst ? xy : coordinate, distance };
|
|
3357
|
+
}
|
|
3358
|
+
const start = pointCoordinates(a);
|
|
3359
|
+
const end = pointCoordinates(b);
|
|
3360
|
+
return start && end ? { start, end, distance: Math.hypot(end[0] - start[0], end[1] - start[1]) } : null;
|
|
3361
|
+
}
|
|
3362
|
+
var ST_CLOSESTPOINT = /* @__PURE__ */ spatialFunction(
|
|
3363
|
+
"ST_ClosestPoint",
|
|
3364
|
+
[routePointKinds, routePointKinds],
|
|
3365
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
3366
|
+
([a, b]) => {
|
|
3367
|
+
const pair = closestPair(a, b);
|
|
3368
|
+
return pair ? (0, import_arrow4.writeWKB)({ type: "Point", coordinates: pair.start }, "xy") : null;
|
|
3369
|
+
}
|
|
1239
3370
|
);
|
|
3371
|
+
var ST_SHORTESTLINE = /* @__PURE__ */ spatialFunction(
|
|
3372
|
+
"ST_ShortestLine",
|
|
3373
|
+
[routePointKinds, routePointKinds],
|
|
3374
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
3375
|
+
([a, b]) => {
|
|
3376
|
+
const pair = closestPair(a, b);
|
|
3377
|
+
return pair ? (0, import_arrow4.writeWKB)({ type: "LineString", coordinates: [pair.start, pair.end] }, "xy") : null;
|
|
3378
|
+
}
|
|
3379
|
+
);
|
|
3380
|
+
var proximityKinds = [...pointKinds, ...lineKinds, ...polygonKinds];
|
|
3381
|
+
function withinDistance(a, b, radius) {
|
|
3382
|
+
if (radius < 0)
|
|
3383
|
+
throw new Error("ST_DWithin distance must be nonnegative");
|
|
3384
|
+
if (Number.isNaN(radius))
|
|
3385
|
+
return false;
|
|
3386
|
+
if (a.type === "Point" && (b.type === "Polygon" || b.type === "MultiPolygon"))
|
|
3387
|
+
return pointWithinPolygonDistance(a, b, radius);
|
|
3388
|
+
if (b.type === "Point" && (a.type === "Polygon" || a.type === "MultiPolygon"))
|
|
3389
|
+
return pointWithinPolygonDistance(b, a, radius);
|
|
3390
|
+
if ((a.type === "LineString" || a.type === "MultiLineString") && (b.type === "LineString" || b.type === "MultiLineString"))
|
|
3391
|
+
return linesWithinDistance(a, b, radius);
|
|
3392
|
+
if (a.type === "Point" && (b.type === "Point" || b.type === "LineString") || b.type === "Point" && a.type === "LineString") {
|
|
3393
|
+
const pair = closestPair(a, b);
|
|
3394
|
+
return pair !== null && pair.distance <= radius;
|
|
3395
|
+
}
|
|
3396
|
+
throw new Error(`ST_DWithin does not support ${a.type} and ${b.type}`);
|
|
3397
|
+
}
|
|
3398
|
+
function makeDWithin() {
|
|
3399
|
+
const spatial = spatialFunction("ST_DWithin", [proximityKinds, proximityKinds], new import_apache_arrow3.Bool(), ([a, b], radius) => withinDistance(a, b, radius), 1);
|
|
3400
|
+
return {
|
|
3401
|
+
...spatial,
|
|
3402
|
+
/** Checks concrete native pairs at binding; WKB pairs are checked per row. */
|
|
3403
|
+
resolvePrototype(fields) {
|
|
3404
|
+
var _a, _b;
|
|
3405
|
+
const result2 = spatial.resolvePrototype(fields);
|
|
3406
|
+
const a = (_a = fields[0]) == null ? void 0 : _a.metadata.get(EXTENSION_NAME);
|
|
3407
|
+
const b = (_b = fields[1]) == null ? void 0 : _b.metadata.get(EXTENSION_NAME);
|
|
3408
|
+
if (result2 && a && b && a !== "geoarrow.wkb" && b !== "geoarrow.wkb") {
|
|
3409
|
+
const linear = (encoding) => encoding === "geoarrow.linestring" || encoding === "geoarrow.multilinestring";
|
|
3410
|
+
const pointPair = a === "geoarrow.point" && b !== "geoarrow.multilinestring" || b === "geoarrow.point" && a !== "geoarrow.multilinestring";
|
|
3411
|
+
if (!pointPair && !(linear(a) && linear(b)))
|
|
3412
|
+
throw new Error(`ST_DWithin does not support ${a} and ${b}`);
|
|
3413
|
+
}
|
|
3414
|
+
return result2;
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
}
|
|
3418
|
+
var ST_DWITHIN = /* @__PURE__ */ makeDWithin();
|
|
1240
3419
|
var ST_INTERSECTS = /* @__PURE__ */ spatialFunction(
|
|
1241
3420
|
"ST_Intersects",
|
|
1242
3421
|
[
|
|
1243
3422
|
[...geometryTypes, "GeometryCollection"],
|
|
1244
3423
|
[...geometryTypes, "GeometryCollection"]
|
|
1245
3424
|
],
|
|
1246
|
-
/* @__PURE__ */ new
|
|
3425
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1247
3426
|
([a, b]) => planarIntersects(a, b)
|
|
1248
3427
|
);
|
|
3428
|
+
var ST_TOUCHES = /* @__PURE__ */ spatialFunction(
|
|
3429
|
+
"ST_Touches",
|
|
3430
|
+
[geometryTypes, geometryTypes],
|
|
3431
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
3432
|
+
([a, b]) => planarTouches(a, b)
|
|
3433
|
+
);
|
|
1249
3434
|
var ST_LINEINTERPOLATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
1250
3435
|
"ST_LineInterpolatePoint",
|
|
1251
3436
|
[["LineString"]],
|
|
1252
|
-
/* @__PURE__ */ new
|
|
3437
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1253
3438
|
([line], fraction) => (0, import_arrow4.writeWKB)(lineSubstring(line, fraction, fraction) ?? { type: "Point", coordinates: [] }, "xy"),
|
|
1254
3439
|
1
|
|
1255
3440
|
);
|
|
1256
3441
|
var ST_LINELOCATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
1257
3442
|
"ST_LineLocatePoint",
|
|
1258
3443
|
[["LineString"], pointKinds],
|
|
1259
|
-
/* @__PURE__ */ new
|
|
3444
|
+
/* @__PURE__ */ new import_apache_arrow3.Float64(),
|
|
1260
3445
|
([line, point2]) => lineLocatePoint(line, point2)
|
|
1261
3446
|
);
|
|
1262
3447
|
var ST_LINESUBSTRING = /* @__PURE__ */ spatialFunction(
|
|
1263
3448
|
"ST_LineSubstring",
|
|
1264
3449
|
[["LineString"]],
|
|
1265
|
-
/* @__PURE__ */ new
|
|
3450
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1266
3451
|
([line], start, end) => {
|
|
1267
3452
|
const result2 = lineSubstring(line, start, end);
|
|
1268
3453
|
return result2 ? (0, import_arrow4.writeWKB)(result2, "xy") : null;
|
|
1269
3454
|
},
|
|
1270
3455
|
2
|
|
1271
3456
|
);
|
|
3457
|
+
var ST_ADDMEASURE = /* @__PURE__ */ spatialFunction(
|
|
3458
|
+
"ST_AddMeasure",
|
|
3459
|
+
[lineKinds],
|
|
3460
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
3461
|
+
([line], start, end) => {
|
|
3462
|
+
const result2 = addMeasure(line, line.dimension, start, end);
|
|
3463
|
+
return (0, import_arrow4.writeWKB)(result2.geometry, result2.dimension);
|
|
3464
|
+
},
|
|
3465
|
+
2,
|
|
3466
|
+
true
|
|
3467
|
+
);
|
|
3468
|
+
var ST_LOCATEALONG = /* @__PURE__ */ spatialFunction(
|
|
3469
|
+
"ST_LocateAlong",
|
|
3470
|
+
[lineKinds],
|
|
3471
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
3472
|
+
([line], measure) => {
|
|
3473
|
+
const dimension = measuredDimension(line.dimension);
|
|
3474
|
+
return (0, import_arrow4.writeWKB)(locateAlong(line, dimension, measure), dimension);
|
|
3475
|
+
},
|
|
3476
|
+
1,
|
|
3477
|
+
true
|
|
3478
|
+
);
|
|
3479
|
+
var ST_LOCATEBETWEEN = /* @__PURE__ */ spatialFunction(
|
|
3480
|
+
"ST_LocateBetween",
|
|
3481
|
+
[lineKinds],
|
|
3482
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
3483
|
+
([line], start, end) => {
|
|
3484
|
+
const dimension = measuredDimension(line.dimension);
|
|
3485
|
+
return (0, import_arrow4.writeWKB)(locateBetween(line, dimension, start, end), dimension);
|
|
3486
|
+
},
|
|
3487
|
+
2,
|
|
3488
|
+
true
|
|
3489
|
+
);
|
|
1272
3490
|
function geometrySRID(crs) {
|
|
1273
3491
|
let identifier = typeof crs === "string" ? normalizeCRSIdentifier(crs) : "";
|
|
1274
3492
|
if (crs && typeof crs === "object" && "id" in crs) {
|
|
@@ -1323,7 +3541,7 @@ function crsFunction(name) {
|
|
|
1323
3541
|
throw new Error(name + " requires a constant integer SRID between 0 and 998999");
|
|
1324
3542
|
if (name === "ST_Transform" && (![4326, 3857].includes(source) || ![4326, 3857].includes(target)))
|
|
1325
3543
|
throw new Error("ST_Transform supports EPSG:4326 and EPSG:3857 source and target CRS");
|
|
1326
|
-
const implementation = spatialFunction(name, [[...geometryTypes, "GeometryCollection"]], read ? new
|
|
3544
|
+
const implementation = spatialFunction(name, [[...geometryTypes, "GeometryCollection"]], read ? new import_apache_arrow3.Int32() : new import_apache_arrow3.Binary(), ([geometry]) => {
|
|
1327
3545
|
if (read)
|
|
1328
3546
|
return source;
|
|
1329
3547
|
const output = name === "ST_Transform" && source !== target ? projectGeometry(geometry, (p) => target === 3857 ? EPSG4326ToEPSG3857([...p], { clampLatitude: false }) : EPSG3857ToLngLat([...p])) : geometry;
|
|
@@ -1341,6 +3559,65 @@ function crsFunction(name) {
|
|
|
1341
3559
|
}
|
|
1342
3560
|
};
|
|
1343
3561
|
}
|
|
3562
|
+
function createSTTransform(engine) {
|
|
3563
|
+
return {
|
|
3564
|
+
kind: "scalar",
|
|
3565
|
+
name: "ST_Transform",
|
|
3566
|
+
prototypes: [],
|
|
3567
|
+
/** Resolves one source and target CRS for the entire projection. */
|
|
3568
|
+
resolvePrototype(fields, literals) {
|
|
3569
|
+
if (fields.length !== 2 || !fields[0])
|
|
3570
|
+
return void 0;
|
|
3571
|
+
const field = fields[0];
|
|
3572
|
+
const target = literals == null ? void 0 : literals[1];
|
|
3573
|
+
if (target === void 0 || !Number.isSafeInteger(target) || target <= 0 || target > 998999)
|
|
3574
|
+
throw new Error("ST_Transform requires a constant positive integer EPSG code");
|
|
3575
|
+
const info = (0, import_arrow4.getGeoArrowFieldInfo)(field);
|
|
3576
|
+
if (!info)
|
|
3577
|
+
throw new Error("ST_Transform requires a GeoArrow geometry column");
|
|
3578
|
+
if (info.metadata["edges"] === "spherical")
|
|
3579
|
+
throw new Error("ST_Transform requires planar geometry");
|
|
3580
|
+
const source = info.metadata["crs"];
|
|
3581
|
+
if (!(typeof source === "string" ? source.trim() : source && typeof source === "object" && !Array.isArray(source)))
|
|
3582
|
+
throw new Error("ST_Transform requires source CRS metadata");
|
|
3583
|
+
const to = "EPSG:" + target;
|
|
3584
|
+
const transform = engine.createProjection({
|
|
3585
|
+
from: source,
|
|
3586
|
+
to,
|
|
3587
|
+
enforceAxis: false
|
|
3588
|
+
});
|
|
3589
|
+
const metadata = JSON.stringify({ ...info.metadata, crs: to, crs_type: "authority_code" });
|
|
3590
|
+
const targetField = fields[1] ?? new import_apache_arrow3.Field("srid", new import_apache_arrow3.Int32(), false);
|
|
3591
|
+
if (!import_apache_arrow3.DataType.isInt(targetField.type) && !import_apache_arrow3.DataType.isFloat(targetField.type))
|
|
3592
|
+
throw new Error("ST_Transform requires a numeric SRID");
|
|
3593
|
+
const project = (coordinate) => {
|
|
3594
|
+
if (coordinate.every(Number.isNaN))
|
|
3595
|
+
return [...coordinate];
|
|
3596
|
+
const [x, y] = transform.projectSync([coordinate[0], coordinate[1]]);
|
|
3597
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
3598
|
+
throw new Error("ST_Transform produced nonfinite coordinates");
|
|
3599
|
+
return [x, y, ...coordinate.slice(2)];
|
|
3600
|
+
};
|
|
3601
|
+
if (info.encoding === "geoarrow.wkb") {
|
|
3602
|
+
const prototype = spatialFunction("ST_Transform", [[...geometryTypes, "GeometryCollection"]], new import_apache_arrow3.Binary(), ([geometry]) => (0, import_arrow4.writeWKB)(projectGeometry(geometry, project), "xy"), 1).resolvePrototype(fields);
|
|
3603
|
+
prototype.result.metadata.set(EXTENSION_METADATA, metadata);
|
|
3604
|
+
return prototype;
|
|
3605
|
+
}
|
|
3606
|
+
if (!geometryTypes.some((kind) => "geoarrow." + kind.toLowerCase() === info.encoding))
|
|
3607
|
+
throw new Error("ST_Transform requires WKB or a specialized native GeoArrow encoding");
|
|
3608
|
+
const outputMetadata = new Map(field.metadata);
|
|
3609
|
+
outputMetadata.set(EXTENSION_METADATA, metadata);
|
|
3610
|
+
return {
|
|
3611
|
+
arguments: [field, targetField],
|
|
3612
|
+
result: new import_apache_arrow3.Field("ST_Transform", field.type, field.nullable, outputMetadata),
|
|
3613
|
+
/** Maps native coordinate buffers directly, retaining topology and null rows. */
|
|
3614
|
+
evaluate([vector], { activeRows }) {
|
|
3615
|
+
return (0, import_arrow4.mapGeoArrowVectorCoordinates)(vector, (coordinate, row) => activeRows[row] ? project(coordinate) : coordinate, { field });
|
|
3616
|
+
}
|
|
3617
|
+
};
|
|
3618
|
+
}
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
1344
3621
|
var ST_SRID = /* @__PURE__ */ crsFunction("ST_SRID");
|
|
1345
3622
|
var ST_SETSRID = /* @__PURE__ */ crsFunction("ST_SetSRID");
|
|
1346
3623
|
var ST_TRANSFORM = /* @__PURE__ */ crsFunction("ST_Transform");
|
|
@@ -1352,7 +3629,7 @@ function lineReduction(name, mode) {
|
|
|
1352
3629
|
/** Binds the geometry and any supplied numeric tolerance. */
|
|
1353
3630
|
resolvePrototype(fields) {
|
|
1354
3631
|
const numericArguments = mode === "removeRepeated" && fields.length === 1 ? 0 : 1;
|
|
1355
|
-
return spatialFunction(name, [lineKinds], new
|
|
3632
|
+
return spatialFunction(name, [lineKinds], new import_apache_arrow3.Binary(), ([line], tolerance = 0) => {
|
|
1356
3633
|
const result2 = reduceLineVertices(line, tolerance, mode);
|
|
1357
3634
|
return result2 ? (0, import_arrow4.writeWKB)(result2, "xy") : null;
|
|
1358
3635
|
}, numericArguments).resolvePrototype(fields);
|
|
@@ -1361,10 +3638,25 @@ function lineReduction(name, mode) {
|
|
|
1361
3638
|
}
|
|
1362
3639
|
var ST_REMOVEREPEATEDPOINTS = /* @__PURE__ */ lineReduction("ST_RemoveRepeatedPoints", "removeRepeated");
|
|
1363
3640
|
var ST_SIMPLIFY = /* @__PURE__ */ lineReduction("ST_Simplify", "simplify");
|
|
3641
|
+
var ST_SIMPLIFYPRESERVETOPOLOGY = {
|
|
3642
|
+
kind: "scalar",
|
|
3643
|
+
name: "ST_SimplifyPreserveTopology",
|
|
3644
|
+
prototypes: [],
|
|
3645
|
+
/** Preserves specialized native storage where the input schema identifies its family. */
|
|
3646
|
+
resolvePrototype(fields) {
|
|
3647
|
+
var _a;
|
|
3648
|
+
const encoding = (_a = fields[0]) == null ? void 0 : _a.metadata.get(EXTENSION_NAME);
|
|
3649
|
+
const native2 = encoding === "geoarrow.polygon" || encoding === "geoarrow.multipolygon";
|
|
3650
|
+
return spatialFunction("ST_SimplifyPreserveTopology", [polygonKinds], native2 ? nativePolygonResult(encoding) : new import_apache_arrow3.Binary(), ([geometry], tolerance) => {
|
|
3651
|
+
const result2 = simplifyPolygonTopology(geometry, tolerance);
|
|
3652
|
+
return native2 ? result2 : (0, import_arrow4.writeWKB)(result2, "xy");
|
|
3653
|
+
}, 1).resolvePrototype(fields);
|
|
3654
|
+
}
|
|
3655
|
+
};
|
|
1364
3656
|
var ST_AZIMUTH = /* @__PURE__ */ spatialFunction(
|
|
1365
3657
|
"ST_Azimuth",
|
|
1366
3658
|
[pointKinds, pointKinds],
|
|
1367
|
-
/* @__PURE__ */ new
|
|
3659
|
+
/* @__PURE__ */ new import_apache_arrow3.Float64(),
|
|
1368
3660
|
([a, b]) => {
|
|
1369
3661
|
const p = pointCoordinates(a);
|
|
1370
3662
|
const q = pointCoordinates(b);
|
|
@@ -1381,26 +3673,26 @@ var ST_AZIMUTH = /* @__PURE__ */ spatialFunction(
|
|
|
1381
3673
|
var ST_AREA = /* @__PURE__ */ spatialFunction(
|
|
1382
3674
|
"ST_Area",
|
|
1383
3675
|
[geometryTypes],
|
|
1384
|
-
/* @__PURE__ */ new
|
|
3676
|
+
/* @__PURE__ */ new import_apache_arrow3.Float64(),
|
|
1385
3677
|
([geometry]) => planarArea(geometry)
|
|
1386
3678
|
);
|
|
1387
3679
|
var ST_LENGTH = /* @__PURE__ */ spatialFunction(
|
|
1388
3680
|
"ST_Length",
|
|
1389
|
-
[geometryTypes],
|
|
1390
|
-
/* @__PURE__ */ new
|
|
3681
|
+
[[...geometryTypes, "GeometryCollection"]],
|
|
3682
|
+
/* @__PURE__ */ new import_apache_arrow3.Float64(),
|
|
1391
3683
|
([geometry]) => planarLength(geometry)
|
|
1392
3684
|
);
|
|
1393
3685
|
var ST_CENTROID = /* @__PURE__ */ spatialFunction(
|
|
1394
3686
|
"ST_Centroid",
|
|
1395
3687
|
[geometryTypes],
|
|
1396
|
-
/* @__PURE__ */ new
|
|
3688
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1397
3689
|
([geometry]) => (0, import_arrow4.writeWKB)(planarCentroid(geometry), "xy")
|
|
1398
3690
|
);
|
|
1399
3691
|
var inspectionKinds = [[...geometryTypes, "GeometryCollection"]];
|
|
1400
3692
|
var ST_NPOINTS = /* @__PURE__ */ spatialFunction(
|
|
1401
3693
|
"ST_NPoints",
|
|
1402
3694
|
inspectionKinds,
|
|
1403
|
-
/* @__PURE__ */ new
|
|
3695
|
+
/* @__PURE__ */ new import_apache_arrow3.Int32(),
|
|
1404
3696
|
([g]) => vertexCount(g),
|
|
1405
3697
|
0,
|
|
1406
3698
|
true
|
|
@@ -1408,7 +3700,7 @@ var ST_NPOINTS = /* @__PURE__ */ spatialFunction(
|
|
|
1408
3700
|
var ST_NUMGEOMETRIES = /* @__PURE__ */ spatialFunction(
|
|
1409
3701
|
"ST_NumGeometries",
|
|
1410
3702
|
inspectionKinds,
|
|
1411
|
-
/* @__PURE__ */ new
|
|
3703
|
+
/* @__PURE__ */ new import_apache_arrow3.Int32(),
|
|
1412
3704
|
([g]) => memberCount(g),
|
|
1413
3705
|
0,
|
|
1414
3706
|
true
|
|
@@ -1416,7 +3708,7 @@ var ST_NUMGEOMETRIES = /* @__PURE__ */ spatialFunction(
|
|
|
1416
3708
|
var ST_ISEMPTY = /* @__PURE__ */ spatialFunction(
|
|
1417
3709
|
"ST_IsEmpty",
|
|
1418
3710
|
inspectionKinds,
|
|
1419
|
-
/* @__PURE__ */ new
|
|
3711
|
+
/* @__PURE__ */ new import_apache_arrow3.Bool(),
|
|
1420
3712
|
([g]) => !vertexCount(g),
|
|
1421
3713
|
0,
|
|
1422
3714
|
true
|
|
@@ -1424,7 +3716,7 @@ var ST_ISEMPTY = /* @__PURE__ */ spatialFunction(
|
|
|
1424
3716
|
var ST_GEOMETRYTYPE = /* @__PURE__ */ spatialFunction(
|
|
1425
3717
|
"ST_GeometryType",
|
|
1426
3718
|
inspectionKinds,
|
|
1427
|
-
/* @__PURE__ */ new
|
|
3719
|
+
/* @__PURE__ */ new import_apache_arrow3.Utf8(),
|
|
1428
3720
|
([g]) => "ST_" + g.type,
|
|
1429
3721
|
0,
|
|
1430
3722
|
true
|
|
@@ -1432,7 +3724,7 @@ var ST_GEOMETRYTYPE = /* @__PURE__ */ spatialFunction(
|
|
|
1432
3724
|
var ST_FORCE2D = /* @__PURE__ */ spatialFunction(
|
|
1433
3725
|
"ST_Force2D",
|
|
1434
3726
|
inspectionKinds,
|
|
1435
|
-
/* @__PURE__ */ new
|
|
3727
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1436
3728
|
([g]) => (0, import_arrow4.writeWKB)(g, "xy"),
|
|
1437
3729
|
0,
|
|
1438
3730
|
true
|
|
@@ -1440,7 +3732,7 @@ var ST_FORCE2D = /* @__PURE__ */ spatialFunction(
|
|
|
1440
3732
|
var ST_GEOMETRYN = /* @__PURE__ */ spatialFunction(
|
|
1441
3733
|
"ST_GeometryN",
|
|
1442
3734
|
inspectionKinds,
|
|
1443
|
-
/* @__PURE__ */ new
|
|
3735
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1444
3736
|
([g], position) => {
|
|
1445
3737
|
var _a;
|
|
1446
3738
|
const part = geometryMember(g, position);
|
|
@@ -1455,7 +3747,7 @@ var ST_MAKELINE = /* @__PURE__ */ spatialFunction(
|
|
|
1455
3747
|
["Point", "MultiPoint", "LineString"],
|
|
1456
3748
|
["Point", "MultiPoint", "LineString"]
|
|
1457
3749
|
],
|
|
1458
|
-
/* @__PURE__ */ new
|
|
3750
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1459
3751
|
(geometries) => (0, import_arrow4.writeWKB)(makeLine(geometries), "xy")
|
|
1460
3752
|
);
|
|
1461
3753
|
var ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
@@ -1464,7 +3756,7 @@ var ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
|
1464
3756
|
[...geometryTypes, "GeometryCollection"],
|
|
1465
3757
|
[...geometryTypes, "GeometryCollection"]
|
|
1466
3758
|
],
|
|
1467
|
-
/* @__PURE__ */ new
|
|
3759
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1468
3760
|
([a, b]) => a ? (0, import_arrow4.writeWKB)(b ? collectPair(a, b) : a, "xy") : null,
|
|
1469
3761
|
0,
|
|
1470
3762
|
false,
|
|
@@ -1473,14 +3765,14 @@ var ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
|
1473
3765
|
var ST_POINTONSURFACE = /* @__PURE__ */ spatialFunction(
|
|
1474
3766
|
"ST_PointOnSurface",
|
|
1475
3767
|
[polygonKinds],
|
|
1476
|
-
/* @__PURE__ */ new
|
|
3768
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1477
3769
|
([polygon]) => (0, import_arrow4.writeWKB)(planarPolygonPointOnSurface(polygon), "xy")
|
|
1478
3770
|
);
|
|
1479
3771
|
function makeEnvelopeFunction() {
|
|
1480
3772
|
const envelopeFunction = spatialFunction(
|
|
1481
3773
|
"ST_Envelope",
|
|
1482
3774
|
[[...geometryTypes, "GeometryCollection"]],
|
|
1483
|
-
/* @__PURE__ */ new
|
|
3775
|
+
/* @__PURE__ */ new import_apache_arrow3.Binary(),
|
|
1484
3776
|
([geometry]) => (0, import_arrow4.writeWKB)(planarEnvelope(geometry), "xy")
|
|
1485
3777
|
);
|
|
1486
3778
|
return {
|
|
@@ -1489,7 +3781,7 @@ function makeEnvelopeFunction() {
|
|
|
1489
3781
|
resolvePrototype(fields) {
|
|
1490
3782
|
const prototype = envelopeFunction.resolvePrototype(fields);
|
|
1491
3783
|
const field = fields[0];
|
|
1492
|
-
if (!prototype || !field ||
|
|
3784
|
+
if (!prototype || !field || import_apache_arrow3.DataType.isBinary(field.type) || import_apache_arrow3.DataType.isLargeBinary(field.type)) {
|
|
1493
3785
|
return prototype;
|
|
1494
3786
|
}
|
|
1495
3787
|
return {
|
|
@@ -1507,7 +3799,7 @@ function makeEnvelopeFunction() {
|
|
|
1507
3799
|
const [geometry] = (0, import_arrow4.materializeGeoArrowRows)((0, import_arrow4.getGeoArrowColumnView)(column2, row, row + 1));
|
|
1508
3800
|
return geometry ? (0, import_arrow4.writeWKB)(geometry, "xy") : null;
|
|
1509
3801
|
});
|
|
1510
|
-
return (0,
|
|
3802
|
+
return (0, import_apache_arrow3.vectorFromArray)(values, new import_apache_arrow3.Binary());
|
|
1511
3803
|
}
|
|
1512
3804
|
};
|
|
1513
3805
|
}
|
|
@@ -1524,7 +3816,7 @@ var ST_EXTENT = {
|
|
|
1524
3816
|
throw new Error("ST_Extent requires one geometry column");
|
|
1525
3817
|
ST_ENVELOPE.resolvePrototype([field]);
|
|
1526
3818
|
return {
|
|
1527
|
-
outputField: new
|
|
3819
|
+
outputField: new import_apache_arrow3.Field("ST_Extent", new import_apache_arrow3.FixedSizeList(4, new import_apache_arrow3.Field("value", new import_apache_arrow3.Float64(), false)), true),
|
|
1528
3820
|
/** Creates independent bounds for this group. */
|
|
1529
3821
|
createAccumulator() {
|
|
1530
3822
|
let bounds = null;
|
|
@@ -1541,7 +3833,7 @@ var ST_EXTENT = {
|
|
|
1541
3833
|
return {
|
|
1542
3834
|
/** Accumulates nonempty geometry bounds from one record batch. */
|
|
1543
3835
|
update([vector], { length }) {
|
|
1544
|
-
if (!
|
|
3836
|
+
if (!import_apache_arrow3.DataType.isBinary(field.type) && !import_apache_arrow3.DataType.isLargeBinary(field.type)) {
|
|
1545
3837
|
const column2 = (0, import_arrow4.makeGeoArrowColumnFromArrowVector)(vector, { field });
|
|
1546
3838
|
const box = (0, import_arrow4.getGeoArrowBounds)(column2);
|
|
1547
3839
|
if (box)
|
|
@@ -1586,12 +3878,16 @@ var POSTGIS_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
|
1586
3878
|
ST_MAKEENVELOPE,
|
|
1587
3879
|
ST_DISTANCE,
|
|
1588
3880
|
ST_DWITHIN,
|
|
3881
|
+
ST_CLOSESTPOINT,
|
|
3882
|
+
ST_SHORTESTLINE,
|
|
1589
3883
|
ST_INTERSECTS,
|
|
3884
|
+
ST_TOUCHES,
|
|
1590
3885
|
ST_SRID,
|
|
1591
3886
|
ST_SETSRID,
|
|
1592
3887
|
ST_TRANSFORM,
|
|
1593
3888
|
ST_REMOVEREPEATEDPOINTS,
|
|
1594
3889
|
ST_SIMPLIFY,
|
|
3890
|
+
ST_SIMPLIFYPRESERVETOPOLOGY,
|
|
1595
3891
|
ST_AZIMUTH,
|
|
1596
3892
|
ST_MAKEPOINT,
|
|
1597
3893
|
ST_TILEENVELOPE,
|
|
@@ -1600,6 +3896,9 @@ var POSTGIS_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
|
1600
3896
|
ST_LINEINTERPOLATEPOINT,
|
|
1601
3897
|
ST_LINELOCATEPOINT,
|
|
1602
3898
|
ST_LINESUBSTRING,
|
|
3899
|
+
ST_ADDMEASURE,
|
|
3900
|
+
ST_LOCATEALONG,
|
|
3901
|
+
ST_LOCATEBETWEEN,
|
|
1603
3902
|
ST_POINTONSURFACE,
|
|
1604
3903
|
ST_CENTROID,
|
|
1605
3904
|
ST_NPOINTS,
|