@math.gl/geospatial 5.0.1 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coverage-simplification.d.ts +9 -0
- package/dist/coverage-simplification.d.ts.map +1 -0
- package/dist/coverage-simplification.js +167 -0
- package/dist/coverage-simplification.js.map +1 -0
- package/dist/line-network/build-line-network.d.ts +100 -0
- package/dist/line-network/build-line-network.d.ts.map +1 -0
- package/dist/line-network/build-line-network.js +766 -0
- package/dist/line-network/build-line-network.js.map +1 -0
- package/dist/line-network/line-network-routes.d.ts +53 -0
- package/dist/line-network/line-network-routes.d.ts.map +1 -0
- package/dist/line-network/line-network-routes.js +146 -0
- package/dist/line-network/line-network-routes.js.map +1 -0
- package/dist/line-network/line-network-weights.d.ts +11 -0
- package/dist/line-network/line-network-weights.d.ts.map +1 -0
- package/dist/line-network/line-network-weights.js +25 -0
- package/dist/line-network/line-network-weights.js.map +1 -0
- package/dist/line-network.cjs +850 -0
- package/dist/line-network.cjs.map +6 -0
- package/dist/line-network.d.ts +7 -0
- package/dist/line-network.d.ts.map +1 -0
- package/dist/line-network.js +7 -0
- package/dist/line-network.js.map +1 -0
- package/dist/linear-referencing.d.ts +2 -12
- package/dist/linear-referencing.d.ts.map +1 -1
- package/dist/linear-referencing.js +17 -49
- package/dist/linear-referencing.js.map +1 -1
- package/dist/polygon-simplification.d.ts.map +1 -1
- package/dist/polygon-simplification.js +3 -33
- package/dist/polygon-simplification.js.map +1 -1
- package/dist/route-editing.d.ts +10 -0
- package/dist/route-editing.d.ts.map +1 -0
- package/dist/route-editing.js +58 -0
- package/dist/route-editing.js.map +1 -0
- package/dist/spatial-line-polygon-intersection.d.ts.map +1 -1
- package/dist/spatial-line-polygon-intersection.js +2 -2
- package/dist/spatial-line-polygon-intersection.js.map +1 -1
- package/dist/spatial-planar-intersects.d.ts +1 -11
- package/dist/spatial-planar-intersects.d.ts.map +1 -1
- package/dist/spatial-planar-intersects.js +2 -42
- package/dist/spatial-planar-intersects.js.map +1 -1
- package/dist/spatial-sql.d.ts +6 -4
- package/dist/spatial-sql.d.ts.map +1 -1
- package/dist/spatial-sql.js +38 -4
- package/dist/spatial-sql.js.map +1 -1
- package/dist/spatial-touches.d.ts +0 -2
- package/dist/spatial-touches.d.ts.map +1 -1
- package/dist/spatial-touches.js +1 -15
- package/dist/spatial-touches.js.map +1 -1
- package/dist/st-coverage-functions.d.ts +11 -0
- package/dist/st-coverage-functions.d.ts.map +1 -0
- package/dist/st-coverage-functions.js +57 -0
- package/dist/st-coverage-functions.js.map +1 -0
- package/dist/st-functions.cjs +1201 -775
- package/dist/st-functions.cjs.map +3 -3
- package/dist/st-functions.d.ts +36 -3
- package/dist/st-functions.d.ts.map +1 -1
- package/dist/st-functions.js +53 -19
- package/dist/st-functions.js.map +1 -1
- package/dist/st-geodesic-functions.d.ts +10 -2
- package/dist/st-geodesic-functions.d.ts.map +1 -1
- package/dist/st-geodesic-functions.js +179 -25
- package/dist/st-geodesic-functions.js.map +1 -1
- package/dist/st-hull-functions.cjs.map +1 -1
- package/dist/st-overlay-functions.cjs +114 -67
- package/dist/st-overlay-functions.cjs.map +2 -2
- package/dist/st-overlay-functions.d.ts +11 -1
- package/dist/st-overlay-functions.d.ts.map +1 -1
- package/dist/st-overlay-functions.js +74 -9
- package/dist/st-overlay-functions.js.map +1 -1
- package/dist/st-viewport-functions.cjs.map +1 -1
- package/dist/turf-functions.cjs.map +1 -1
- package/package.json +12 -6
- package/src/coverage-simplification.ts +215 -0
- package/src/line-network/build-line-network.ts +990 -0
- package/src/line-network/line-network-routes.ts +213 -0
- package/src/line-network/line-network-weights.ts +40 -0
- package/src/line-network.ts +29 -0
- package/src/linear-referencing.ts +23 -64
- package/src/polygon-simplification.ts +3 -42
- package/src/route-editing.ts +107 -0
- package/src/spatial-line-polygon-intersection.ts +7 -2
- package/src/spatial-planar-intersects.ts +7 -54
- package/src/spatial-sql.ts +54 -5
- package/src/spatial-touches.ts +1 -15
- package/src/st-coverage-functions.ts +88 -0
- package/src/st-functions.ts +70 -19
- package/src/st-geodesic-functions.ts +218 -26
- package/src/st-overlay-functions.ts +79 -10
package/src/spatial-sql.ts
CHANGED
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
DataType,
|
|
8
8
|
Field,
|
|
9
9
|
Float64,
|
|
10
|
+
FixedSizeList,
|
|
11
|
+
makeData,
|
|
12
|
+
makeVector,
|
|
10
13
|
vectorFromArray,
|
|
11
14
|
type Bool,
|
|
12
|
-
type FixedSizeList,
|
|
13
15
|
type Int32,
|
|
14
16
|
type Utf8,
|
|
15
17
|
type Vector
|
|
@@ -58,19 +60,66 @@ type SpatialResult = Int32 | Float64 | Bool | Binary | FixedSizeList<Float64> |
|
|
|
58
60
|
/** Native geometry result storage and its row-aligned Arrow vector builder. */
|
|
59
61
|
export type NativeSpatialResult = {
|
|
60
62
|
/** Extension encoding declared on the bound result field. */
|
|
61
|
-
encoding:
|
|
63
|
+
encoding:
|
|
64
|
+
| 'geoarrow.point'
|
|
65
|
+
| 'geoarrow.linestring'
|
|
66
|
+
| 'geoarrow.multilinestring'
|
|
67
|
+
| 'geoarrow.polygon'
|
|
68
|
+
| 'geoarrow.multipolygon'
|
|
69
|
+
| 'geoarrow.geometry';
|
|
62
70
|
/** Fixed physical Arrow schema for all batches. */
|
|
63
71
|
type: DataType;
|
|
64
72
|
/** Packs decoded geometry rows into native coordinate buffers. */
|
|
65
73
|
build: (rows: readonly (WellKnownGeometry | null)[]) => Vector;
|
|
66
74
|
};
|
|
67
75
|
|
|
68
|
-
/**
|
|
69
|
-
export function
|
|
76
|
+
/** Wraps already-packed point coordinates and row validity without copying either buffer. */
|
|
77
|
+
export function nativePointVector(
|
|
78
|
+
type: FixedSizeList<Float64>,
|
|
79
|
+
data: Float64Array,
|
|
80
|
+
nullBitmap: Uint8Array,
|
|
81
|
+
nullCount: number
|
|
82
|
+
): Vector {
|
|
83
|
+
const child = makeData({type: type.valueType, data, length: data.length});
|
|
84
|
+
return makeVector(
|
|
85
|
+
makeData({type, length: data.length / type.listSize, nullCount, nullBitmap, child})
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Declares interleaved XY point storage and packs each output row once. */
|
|
90
|
+
function nativeXYPointResult(): NativeSpatialResult {
|
|
91
|
+
const type = new FixedSizeList(2, new Field('xy', new Float64(), true));
|
|
92
|
+
return {
|
|
93
|
+
encoding: 'geoarrow.point',
|
|
94
|
+
type,
|
|
95
|
+
/** Writes empty points as NaN coordinates and uses a bitmap for null rows. */
|
|
96
|
+
build(rows) {
|
|
97
|
+
const values = new Float64Array(rows.length * 2);
|
|
98
|
+
const validity = new Uint8Array(Math.ceil(rows.length / 8));
|
|
99
|
+
let nullCount = 0;
|
|
100
|
+
for (let row = 0; row < rows.length; row++) {
|
|
101
|
+
const point = rows[row];
|
|
102
|
+
if (!point) {
|
|
103
|
+
nullCount++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (point.type !== 'Point') throw new Error('Expected a Point result');
|
|
107
|
+
validity[row >> 3]! |= 1 << (row & 7);
|
|
108
|
+
values[2 * row] = point.coordinates[0] ?? NaN;
|
|
109
|
+
values[2 * row + 1] = point.coordinates[1] ?? NaN;
|
|
110
|
+
}
|
|
111
|
+
return nativePointVector(type, values, validity, nullCount);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Declares a fixed native interleaved XY layout, including for empty or all-null batches. */
|
|
117
|
+
export function nativeGeometryResult(
|
|
70
118
|
encoding: Exclude<NativeSpatialResult['encoding'], 'geoarrow.geometry'>
|
|
71
119
|
): NativeSpatialResult {
|
|
120
|
+
if (encoding === 'geoarrow.point') return nativeXYPointResult();
|
|
72
121
|
const options = {encoding, dimension: 'xy', coordinateLayout: 'interleaved'} as const;
|
|
73
|
-
/** Packs the output
|
|
122
|
+
/** Packs the output into native coordinate buffers. */
|
|
74
123
|
const build: NativeSpatialResult['build'] = rows =>
|
|
75
124
|
makeArrowVectorFromGeoArrowColumn(GeoArrowBuilder.build(rows, options));
|
|
76
125
|
return {encoding, type: build([]).type, build};
|
package/src/spatial-touches.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type {WellKnownGeometry} from '@math.gl/core/arrow';
|
|
6
6
|
import polygonClipping from 'polygon-clipping';
|
|
7
7
|
import {
|
|
8
|
+
endpointContacts,
|
|
8
9
|
locatePointInPolygon,
|
|
9
10
|
planarIntersects,
|
|
10
11
|
pointOnSegment,
|
|
@@ -84,21 +85,6 @@ function lineBoundary(components: readonly Path[]): ReadonlyMap<string, Position
|
|
|
84
85
|
return boundary;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
/** Finds shared endpoints, including an endpoint lying in the other segment's interior. */
|
|
88
|
-
export function endpointContacts(a: Edge, b: Edge): Position[] {
|
|
89
|
-
const contacts: Position[] = [];
|
|
90
|
-
for (const [endpoints, other] of [
|
|
91
|
-
[a, b],
|
|
92
|
-
[b, a]
|
|
93
|
-
] as const) {
|
|
94
|
-
for (const point of endpoints) {
|
|
95
|
-
if (pointOnSegment(point, ...other) && !contacts.some(value => samePoint(value, point)))
|
|
96
|
-
contacts.push(point);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return contacts;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
88
|
/** Tests whether any odd endpoint is also on both segments of a proper crossing. */
|
|
103
89
|
function hasBoundaryCrossing(boundary: ReadonlyMap<string, Position>, a: Edge, b: Edge): boolean {
|
|
104
90
|
for (const point of boundary.values()) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Data, Schema, Struct, Table} from 'apache-arrow';
|
|
6
|
+
import {
|
|
7
|
+
createRecordBatchWithMetadata,
|
|
8
|
+
getRecordBatchMetadata,
|
|
9
|
+
getGeoArrowFieldInfo,
|
|
10
|
+
makeGeoArrowColumnFromArrowVector,
|
|
11
|
+
materializeGeoArrowRows,
|
|
12
|
+
type WellKnownGeometry
|
|
13
|
+
} from '@math.gl/core/arrow';
|
|
14
|
+
import type {TableFunction} from '@math.gl/sql/arrow';
|
|
15
|
+
import {simplifyCoverage} from './coverage-simplification';
|
|
16
|
+
import {nativeGeometryResult} from './spatial-sql';
|
|
17
|
+
|
|
18
|
+
/** Settings for a whole-relation coverage simplification. */
|
|
19
|
+
export type CoverageSimplifyOptions = {
|
|
20
|
+
/** Maximum vertex displacement in planar coordinate units. */
|
|
21
|
+
tolerance: number;
|
|
22
|
+
/** Name of the native Polygon or MultiPolygon column. */
|
|
23
|
+
geometry: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Creates an opted-in ST_CoverageSimplify table function with fixed tolerance. */
|
|
27
|
+
export function createSTCoverageSimplify({
|
|
28
|
+
geometry,
|
|
29
|
+
tolerance
|
|
30
|
+
}: CoverageSimplifyOptions): TableFunction {
|
|
31
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
32
|
+
throw new Error('ST_CoverageSimplify requires a finite nonnegative tolerance');
|
|
33
|
+
return {
|
|
34
|
+
kind: 'table',
|
|
35
|
+
name: 'ST_CoverageSimplify',
|
|
36
|
+
/** Binds one native 2D polygon field and a stable output schema. */
|
|
37
|
+
bind(inputSchema) {
|
|
38
|
+
const index = inputSchema.fields.findIndex(field => field.name === geometry);
|
|
39
|
+
const field = inputSchema.fields[index];
|
|
40
|
+
const info = field && getGeoArrowFieldInfo(field);
|
|
41
|
+
const encoding = info?.encoding;
|
|
42
|
+
if (
|
|
43
|
+
!field ||
|
|
44
|
+
(encoding !== 'geoarrow.polygon' && encoding !== 'geoarrow.multipolygon') ||
|
|
45
|
+
info.dimension !== 'xy' ||
|
|
46
|
+
info.metadata['edges'] === 'spherical'
|
|
47
|
+
)
|
|
48
|
+
throw new Error(
|
|
49
|
+
'ST_CoverageSimplify requires a native planar XY Polygon or MultiPolygon column'
|
|
50
|
+
);
|
|
51
|
+
const output = nativeGeometryResult(encoding);
|
|
52
|
+
const fields = inputSchema.fields.slice();
|
|
53
|
+
fields[index] = field.clone({type: output.type});
|
|
54
|
+
const outputSchema = new Schema(
|
|
55
|
+
fields,
|
|
56
|
+
inputSchema.metadata,
|
|
57
|
+
undefined,
|
|
58
|
+
inputSchema.metadataVersion
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
outputSchema,
|
|
62
|
+
/** Simplifies shared boundaries across batches while preserving row alignment. */
|
|
63
|
+
evaluate(input, {signal}) {
|
|
64
|
+
signal?.throwIfAborted();
|
|
65
|
+
if (!input.numRows) return new Table(outputSchema, []);
|
|
66
|
+
const vector = input.getChildAt(index)!;
|
|
67
|
+
const column = makeGeoArrowColumnFromArrowVector(vector, {field});
|
|
68
|
+
const rows = materializeGeoArrowRows(column) as (Extract<
|
|
69
|
+
WellKnownGeometry,
|
|
70
|
+
{type: 'Polygon' | 'MultiPolygon'}
|
|
71
|
+
> | null)[];
|
|
72
|
+
const result = simplifyCoverage(rows, tolerance, signal);
|
|
73
|
+
let first = 0;
|
|
74
|
+
const type = new Struct(fields);
|
|
75
|
+
const batches = input.batches.map(batch => {
|
|
76
|
+
signal?.throwIfAborted();
|
|
77
|
+
const children = batch.data.children.slice();
|
|
78
|
+
children[index] = output.build(result.slice(first, first + batch.numRows)).data[0]!;
|
|
79
|
+
first += batch.numRows;
|
|
80
|
+
const data = new Data(type, 0, batch.numRows, 0, undefined, children);
|
|
81
|
+
return createRecordBatchWithMetadata(outputSchema, data, getRecordBatchMetadata(batch));
|
|
82
|
+
});
|
|
83
|
+
return new Table(outputSchema, batches);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
package/src/st-functions.ts
CHANGED
|
@@ -26,9 +26,11 @@ import {
|
|
|
26
26
|
writeWKB,
|
|
27
27
|
type WellKnownGeometry
|
|
28
28
|
} from '@math.gl/core/arrow';
|
|
29
|
+
import {getPolygonValidityReason} from '@math.gl/geometry/polygon';
|
|
29
30
|
import {planarIntersects} from './spatial-planar-intersects';
|
|
30
31
|
import {planarTouches} from './spatial-touches';
|
|
31
32
|
import {linesWithinDistance, pointWithinPolygonDistance} from './spatial-dwithin';
|
|
33
|
+
import {mergeRoute, routeEditingFunction, segmentizeFunction} from './route-editing';
|
|
32
34
|
import {lineLocatePoint, lineSubstring, projectPointToLine} from './linear-referencing';
|
|
33
35
|
import {addMeasure, locateAlong, locateBetween, measuredDimension} from './measure-referencing';
|
|
34
36
|
import {normalizeCRSIdentifier} from './crs/crs-identifier';
|
|
@@ -53,7 +55,8 @@ import {
|
|
|
53
55
|
EXTENSION_NAME,
|
|
54
56
|
geometryTypes,
|
|
55
57
|
lineKinds,
|
|
56
|
-
|
|
58
|
+
nativeGeometryResult,
|
|
59
|
+
nativePointVector,
|
|
57
60
|
planarGeometry,
|
|
58
61
|
pointCoordinates,
|
|
59
62
|
pointInPolygon,
|
|
@@ -69,7 +72,7 @@ export const ST_MAKEPOINT: ScalarFunction = {
|
|
|
69
72
|
kind: 'scalar',
|
|
70
73
|
name: 'ST_MakePoint',
|
|
71
74
|
prototypes: [],
|
|
72
|
-
/** Binds two to four numeric
|
|
75
|
+
/** Binds two to four numeric ordinates to a native GeoArrow point. */
|
|
73
76
|
resolvePrototype(fields) {
|
|
74
77
|
if (fields.length < 2 || fields.length > 4) return undefined;
|
|
75
78
|
const arguments_ = fields.map(field => {
|
|
@@ -77,20 +80,29 @@ export const ST_MAKEPOINT: ScalarFunction = {
|
|
|
77
80
|
throw new Error('ST_MakePoint requires numeric coordinates');
|
|
78
81
|
return field ?? new Field('coordinate', new Float64(), true);
|
|
79
82
|
});
|
|
80
|
-
const
|
|
83
|
+
const dimension = fields.length === 2 ? 'xy' : fields.length === 3 ? 'xyz' : 'xyzm';
|
|
84
|
+
const coordinateType = new Float64();
|
|
85
|
+
const size = fields.length;
|
|
86
|
+
const type = new FixedSizeList(size, new Field(dimension, coordinateType, true));
|
|
81
87
|
return {
|
|
82
88
|
arguments: arguments_,
|
|
83
|
-
result: new Field('ST_MakePoint', type, true, new Map([[EXTENSION_NAME, 'geoarrow.
|
|
84
|
-
/** Writes
|
|
89
|
+
result: new Field('ST_MakePoint', type, true, new Map([[EXTENSION_NAME, 'geoarrow.point']])),
|
|
90
|
+
/** Writes active rows directly to the interleaved coordinate buffer. */
|
|
85
91
|
evaluate(vectors, {activeRows, length}) {
|
|
86
|
-
const
|
|
92
|
+
const data = new Float64Array(length * size);
|
|
93
|
+
const nullBitmap = new Uint8Array(Math.ceil(length / 8));
|
|
94
|
+
let nullCount = 0;
|
|
87
95
|
for (let row = 0; row < length; row++) {
|
|
88
|
-
if (activeRows[row]) {
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
if (!activeRows[row]) {
|
|
97
|
+
nullCount++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
nullBitmap[row >> 3]! |= 1 << (row & 7);
|
|
101
|
+
for (let coordinate = 0; coordinate < size; coordinate++) {
|
|
102
|
+
data[row * size + coordinate] = Number(vectors[coordinate]!.get(row));
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
|
-
return
|
|
105
|
+
return nativePointVector(type, data, nullBitmap, nullCount);
|
|
94
106
|
}
|
|
95
107
|
};
|
|
96
108
|
}
|
|
@@ -389,25 +401,25 @@ function closestPair(a: WellKnownGeometry, b: WellKnownGeometry) {
|
|
|
389
401
|
: null;
|
|
390
402
|
}
|
|
391
403
|
|
|
392
|
-
/** Returns the closest point on the first geometry as GeoArrow
|
|
404
|
+
/** Returns the closest point on the first geometry as a native GeoArrow point. */
|
|
393
405
|
export const ST_CLOSESTPOINT = /* @__PURE__ */ spatialFunction(
|
|
394
406
|
'ST_ClosestPoint',
|
|
395
407
|
[routePointKinds, routePointKinds],
|
|
396
|
-
/* @__PURE__ */
|
|
408
|
+
/* @__PURE__ */ nativeGeometryResult('geoarrow.point'),
|
|
397
409
|
([a, b]) => {
|
|
398
410
|
const pair = closestPair(a!, b!);
|
|
399
|
-
return pair ?
|
|
411
|
+
return pair ? {type: 'Point', coordinates: pair.start} : null;
|
|
400
412
|
}
|
|
401
413
|
);
|
|
402
414
|
|
|
403
|
-
/** Returns the shortest segment from the first geometry to the second as GeoArrow
|
|
415
|
+
/** Returns the shortest segment from the first geometry to the second as a native GeoArrow line. */
|
|
404
416
|
export const ST_SHORTESTLINE = /* @__PURE__ */ spatialFunction(
|
|
405
417
|
'ST_ShortestLine',
|
|
406
418
|
[routePointKinds, routePointKinds],
|
|
407
|
-
/* @__PURE__ */
|
|
419
|
+
/* @__PURE__ */ nativeGeometryResult('geoarrow.linestring'),
|
|
408
420
|
([a, b]) => {
|
|
409
421
|
const pair = closestPair(a!, b!);
|
|
410
|
-
return pair ?
|
|
422
|
+
return pair ? {type: 'LineString', coordinates: [pair.start, pair.end]} : null;
|
|
411
423
|
}
|
|
412
424
|
);
|
|
413
425
|
|
|
@@ -490,6 +502,12 @@ export const ST_TOUCHES = /* @__PURE__ */ spatialFunction(
|
|
|
490
502
|
([a, b]) => planarTouches(a!, b!)
|
|
491
503
|
);
|
|
492
504
|
|
|
505
|
+
/** Joins planar line components through exact degree-two endpoints. */
|
|
506
|
+
export const ST_LINEMERGE = /* @__PURE__ */ routeEditingFunction('ST_LineMerge', false, mergeRoute);
|
|
507
|
+
|
|
508
|
+
/** Splits planar segments evenly to meet the maximum length in CRS units. */
|
|
509
|
+
export const ST_SEGMENTIZE = /* @__PURE__ */ segmentizeFunction('ST_Segmentize');
|
|
510
|
+
|
|
493
511
|
/** Interpolates a point at a fraction of the planar length. */
|
|
494
512
|
export const ST_LINEINTERPOLATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
495
513
|
'ST_LineInterpolatePoint',
|
|
@@ -803,7 +821,7 @@ export const ST_SIMPLIFYPRESERVETOPOLOGY: ScalarFunction = {
|
|
|
803
821
|
return spatialFunction(
|
|
804
822
|
'ST_SimplifyPreserveTopology',
|
|
805
823
|
[polygonKinds],
|
|
806
|
-
native ?
|
|
824
|
+
native ? nativeGeometryResult(encoding) : new Binary(),
|
|
807
825
|
([geometry], tolerance) => {
|
|
808
826
|
const result = simplifyPolygonTopology(
|
|
809
827
|
geometry as Extract<WellKnownGeometry, {type: 'Polygon' | 'MultiPolygon'}>,
|
|
@@ -948,12 +966,39 @@ export const ST_COLLECT = /* @__PURE__ */ spatialFunction(
|
|
|
948
966
|
true
|
|
949
967
|
);
|
|
950
968
|
|
|
969
|
+
/** Adapts a SQL polygon value to the coordinate-space validity kernel. */
|
|
970
|
+
function polygonValidityReason(geometry: WellKnownGeometry): string | undefined {
|
|
971
|
+
if (geometry.type === 'Polygon') return getPolygonValidityReason([geometry.coordinates]);
|
|
972
|
+
if (geometry.type === 'MultiPolygon') return getPolygonValidityReason(geometry.coordinates);
|
|
973
|
+
throw new Error('Expected polygonal geometry');
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** Checks Polygon or MultiPolygon validity in XY. */
|
|
977
|
+
export const ST_ISVALID = /* @__PURE__ */ spatialFunction(
|
|
978
|
+
'ST_IsValid',
|
|
979
|
+
[polygonKinds],
|
|
980
|
+
/* @__PURE__ */ new Bool(),
|
|
981
|
+
([polygon]) => polygonValidityReason(polygon!) === undefined,
|
|
982
|
+
0,
|
|
983
|
+
true
|
|
984
|
+
);
|
|
985
|
+
|
|
986
|
+
/** Returns the first XY polygon validity diagnostic, or Valid Geometry. */
|
|
987
|
+
export const ST_ISVALIDREASON = /* @__PURE__ */ spatialFunction(
|
|
988
|
+
'ST_IsValidReason',
|
|
989
|
+
[polygonKinds],
|
|
990
|
+
/* @__PURE__ */ new Utf8(),
|
|
991
|
+
([polygon]) => polygonValidityReason(polygon!) ?? 'Valid Geometry',
|
|
992
|
+
0,
|
|
993
|
+
true
|
|
994
|
+
);
|
|
995
|
+
|
|
951
996
|
/** Returns an interior label point for a planar polygonal surface. */
|
|
952
997
|
export const ST_POINTONSURFACE = /* @__PURE__ */ spatialFunction(
|
|
953
998
|
'ST_PointOnSurface',
|
|
954
999
|
[polygonKinds],
|
|
955
|
-
/* @__PURE__ */
|
|
956
|
-
([polygon]) =>
|
|
1000
|
+
/* @__PURE__ */ nativeGeometryResult('geoarrow.point'),
|
|
1001
|
+
([polygon]) => planarPolygonPointOnSurface(polygon!)
|
|
957
1002
|
);
|
|
958
1003
|
|
|
959
1004
|
/** Binds the WKB fallback and native row-bounds implementation. */
|
|
@@ -1092,6 +1137,8 @@ export const POSTGIS_SPATIAL_FUNCTIONS: readonly (ArrowTableFunction | Aggregate
|
|
|
1092
1137
|
ST_TILEENVELOPE,
|
|
1093
1138
|
ST_AREA,
|
|
1094
1139
|
ST_LENGTH,
|
|
1140
|
+
ST_LINEMERGE,
|
|
1141
|
+
ST_SEGMENTIZE,
|
|
1095
1142
|
ST_LINEINTERPOLATEPOINT,
|
|
1096
1143
|
ST_LINELOCATEPOINT,
|
|
1097
1144
|
ST_LINESUBSTRING,
|
|
@@ -1099,6 +1146,8 @@ export const POSTGIS_SPATIAL_FUNCTIONS: readonly (ArrowTableFunction | Aggregate
|
|
|
1099
1146
|
ST_LOCATEALONG,
|
|
1100
1147
|
ST_LOCATEBETWEEN,
|
|
1101
1148
|
ST_POINTONSURFACE,
|
|
1149
|
+
ST_ISVALID,
|
|
1150
|
+
ST_ISVALIDREASON,
|
|
1102
1151
|
ST_CENTROID,
|
|
1103
1152
|
ST_NPOINTS,
|
|
1104
1153
|
ST_NUMGEOMETRIES,
|
|
@@ -1116,5 +1165,7 @@ export {
|
|
|
1116
1165
|
ST_GEODESICDISTANCE,
|
|
1117
1166
|
ST_GEODESICLENGTH,
|
|
1118
1167
|
ST_GEODESICDWITHIN,
|
|
1168
|
+
ST_GEODESICSEGMENTIZE,
|
|
1119
1169
|
GEODESIC_SPATIAL_FUNCTIONS
|
|
1120
1170
|
} from './st-geodesic-functions';
|
|
1171
|
+
export {createSTCoverageSimplify, type CoverageSimplifyOptions} from './st-coverage-functions';
|