@math.gl/geospatial 5.0.0-rc.2 → 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/README.md +6 -6
- package/dist/coordinates.cjs +2523 -0
- package/dist/coordinates.cjs.map +6 -0
- package/dist/coordinates.d.ts +4 -0
- package/dist/coordinates.d.ts.map +1 -1
- package/dist/coordinates.js +2 -0
- package/dist/coordinates.js.map +1 -1
- package/dist/entries/ellipsoid.cjs +1209 -0
- package/dist/entries/ellipsoid.cjs.map +6 -0
- package/dist/entries/ellipsoid.d.ts +3 -19
- package/dist/entries/ellipsoid.d.ts.map +1 -1
- package/dist/entries/ellipsoid.js +1 -9
- package/dist/entries/ellipsoid.js.map +1 -1
- package/dist/expressions.cjs +726 -0
- package/dist/expressions.cjs.map +6 -0
- package/dist/geodesics.cjs +3195 -0
- package/dist/geodesics.cjs.map +6 -0
- package/dist/geodesics.d.ts +18 -0
- package/dist/geodesics.d.ts.map +1 -0
- package/dist/geodesics.js +13 -0
- package/dist/geodesics.js.map +1 -0
- package/dist/geographic-atlas/sampling.d.ts +1 -1
- package/dist/geographic-atlas/sampling.d.ts.map +1 -1
- package/dist/geographic-atlas/sampling.js +1 -1
- package/dist/geographic-atlas/sampling.js.map +1 -1
- package/dist/geographic-cuts.cjs +4160 -0
- package/dist/geographic-cuts.cjs.map +6 -0
- package/dist/geographic-cuts.d.ts +2 -0
- package/dist/geographic-cuts.d.ts.map +1 -1
- package/dist/geographic-cuts.js +1 -0
- package/dist/geographic-cuts.js.map +1 -1
- package/dist/geographic-seams/subdivide-cut.d.ts +1 -1
- package/dist/geographic-seams/subdivide-cut.d.ts.map +1 -1
- package/dist/geographic-seams/subdivide-cut.js +1 -1
- package/dist/geographic-seams/subdivide-cut.js.map +1 -1
- package/dist/geographic-seams/types.shared.cjs +32 -0
- package/dist/geographic-seams/types.shared.cjs.map +6 -0
- package/dist/globe.cjs +4223 -0
- package/dist/globe.cjs.map +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- 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/maps/map-transition.shared.cjs +364 -0
- package/dist/maps/map-transition.shared.cjs.map +6 -0
- package/dist/maps/myriahedral/unfold.d.ts +1 -1
- package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
- package/dist/maps/myriahedral/unfold.js +1 -1
- package/dist/maps/myriahedral/unfold.js.map +1 -1
- package/dist/maps/presets.cjs +2 -2
- package/dist/maps/presets.cjs.map +2 -2
- package/dist/maps/transitions.cjs +3 -342
- package/dist/maps/transitions.cjs.map +3 -3
- package/dist/maps.cjs +15 -319
- package/dist/maps.cjs.map +3 -3
- 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/projection/experimental/core.cjs +63 -1317
- package/dist/projection/experimental/core.cjs.map +3 -3
- package/dist/projection/experimental/core.d.ts +1 -1
- package/dist/projection/experimental/core.d.ts.map +1 -1
- package/dist/projection/experimental/crs/projjson.cjs +26 -45
- package/dist/projection/experimental/crs/projjson.cjs.map +3 -3
- package/dist/projection/experimental/crs/types.shared.cjs +44 -0
- package/dist/projection/experimental/crs/types.shared.cjs.map +6 -0
- package/dist/projection/experimental/crs/wkt.cjs +36 -52
- package/dist/projection/experimental/crs/wkt.cjs.map +3 -3
- package/dist/projection/experimental/entries/projections/ob_tran.cjs +9 -23
- package/dist/projection/experimental/entries/projections/ob_tran.cjs.map +3 -3
- package/dist/projection/experimental/lazy-projections/aea.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/aea.js +1 -1
- package/dist/projection/experimental/lazy-projections/aeqd.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/aeqd.js +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.js +1 -1
- package/dist/projection/experimental/lazy-projections/cass.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/cass.js +1 -1
- package/dist/projection/experimental/lazy-projections/cea.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/cea.js +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.js +1 -1
- package/dist/projection/experimental/lazy-projections/eqc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/eqc.js +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.js +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.js +1 -1
- package/dist/projection/experimental/lazy-projections/equi.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/equi.js +1 -1
- package/dist/projection/experimental/lazy-projections/etmerc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/etmerc.js +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.js +1 -1
- package/dist/projection/experimental/lazy-projections/geos.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/geos.js +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.js +1 -1
- package/dist/projection/experimental/lazy-projections/gstmerc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/gstmerc.js +1 -1
- package/dist/projection/experimental/lazy-projections/index.cjs +60 -903
- package/dist/projection/experimental/lazy-projections/index.cjs.map +3 -3
- package/dist/projection/experimental/lazy-projections/krovak.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.js +1 -1
- package/dist/projection/experimental/lazy-projections/laea.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/laea.js +1 -1
- package/dist/projection/experimental/lazy-projections/lcc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/lcc.js +1 -1
- package/dist/projection/experimental/lazy-projections/merc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/merc.js +1 -1
- package/dist/projection/experimental/lazy-projections/mill.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/mill.js +1 -1
- package/dist/projection/experimental/lazy-projections/moll.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/moll.js +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.js +1 -1
- package/dist/projection/experimental/lazy-projections/ob_tran.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/ob_tran.js +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.js +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.js +1 -1
- package/dist/projection/experimental/lazy-projections/poly.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/poly.js +1 -1
- package/dist/projection/experimental/lazy-projections/qsc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/qsc.js +1 -1
- package/dist/projection/experimental/lazy-projections/robin.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/robin.js +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.js +1 -1
- package/dist/projection/experimental/lazy-projections/somerc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/somerc.js +1 -1
- package/dist/projection/experimental/lazy-projections/stere.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/stere.js +1 -1
- package/dist/projection/experimental/lazy-projections/sterea.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/sterea.js +1 -1
- package/dist/projection/experimental/lazy-projections/tmerc.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/tmerc.js +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.js +1 -1
- package/dist/projection/experimental/lazy-projections/utm.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/utm.js +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.cjs +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.js +1 -1
- package/dist/projection/experimental/projection-engine.shared.cjs +1184 -0
- package/dist/projection/experimental/projection-engine.shared.cjs.map +6 -0
- package/dist/projection/experimental/typescript-projection.shared.cjs +1703 -0
- package/dist/projection/experimental/typescript-projection.shared.cjs.map +6 -0
- package/dist/projection/index.cjs +622 -1535
- package/dist/projection/index.cjs.map +3 -3
- package/dist/projection/pipeline.cjs +44 -58
- package/dist/projection/pipeline.cjs.map +3 -3
- package/dist/projection/transform-analysis.cjs +20 -936
- package/dist/projection/transform-analysis.cjs.map +3 -3
- 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/subdivide-geodesic-polyline.d.ts +1 -1
- package/dist/subdivide-geodesic-polyline.d.ts.map +1 -1
- package/dist/subdivide-geodesic-polyline.js +1 -1
- package/dist/subdivide-geodesic-polyline.js.map +1 -1
- package/dist/subdivide-globe-mesh.d.ts +1 -1
- package/dist/subdivide-globe-mesh.d.ts.map +1 -1
- package/dist/subdivide-globe-mesh.js +1 -1
- package/dist/subdivide-globe-mesh.js.map +1 -1
- package/dist/subdivide-rhumb-polyline.d.ts +1 -1
- package/dist/subdivide-rhumb-polyline.d.ts.map +1 -1
- package/dist/subdivide-rhumb-polyline.js +1 -1
- package/dist/subdivide-rhumb-polyline.js.map +1 -1
- package/dist/tasks/index.cjs +808 -2993
- package/dist/tasks/index.cjs.map +3 -3
- package/dist/terrain/geometry.d.ts +1 -1
- package/dist/terrain/geometry.d.ts.map +1 -1
- package/dist/terrain/geometry.js +1 -1
- package/dist/terrain/geometry.js.map +1 -1
- package/dist/terrain/index.cjs +95 -22
- 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/tiles.cjs +354 -0
- package/dist/tiles.cjs.map +6 -0
- package/dist/turf-functions.cjs +16 -9
- package/dist/turf-functions.cjs.map +1 -1
- package/package.json +154 -117
- package/src/coordinates.ts +5 -0
- package/src/entries/ellipsoid.ts +7 -32
- package/src/geodesics.ts +40 -0
- package/src/geographic-atlas/sampling.ts +1 -1
- package/src/geographic-cuts.ts +21 -0
- package/src/geographic-seams/subdivide-cut.ts +1 -1
- package/src/index.ts +2 -0
- package/src/line-simplification.ts +4 -16
- package/src/linear-referencing.ts +44 -16
- package/src/maps/myriahedral/unfold.ts +1 -1
- package/src/measure-referencing.ts +165 -0
- package/src/polygon-simplification.ts +185 -0
- package/src/projection/experimental/core.ts +1 -1
- package/src/projection/experimental/lazy-projections/aea.ts +1 -1
- package/src/projection/experimental/lazy-projections/aeqd.ts +1 -1
- package/src/projection/experimental/lazy-projections/bonne.ts +1 -1
- package/src/projection/experimental/lazy-projections/cass.ts +1 -1
- package/src/projection/experimental/lazy-projections/cea.ts +1 -1
- package/src/projection/experimental/lazy-projections/eck6.ts +1 -1
- package/src/projection/experimental/lazy-projections/eqc.ts +1 -1
- package/src/projection/experimental/lazy-projections/eqdc.ts +1 -1
- package/src/projection/experimental/lazy-projections/eqearth.ts +1 -1
- package/src/projection/experimental/lazy-projections/equi.ts +1 -1
- package/src/projection/experimental/lazy-projections/etmerc.ts +1 -1
- package/src/projection/experimental/lazy-projections/geocent.ts +1 -1
- package/src/projection/experimental/lazy-projections/geos.ts +1 -1
- package/src/projection/experimental/lazy-projections/gnom.ts +1 -1
- package/src/projection/experimental/lazy-projections/gstmerc.ts +1 -1
- package/src/projection/experimental/lazy-projections/krovak.ts +1 -1
- package/src/projection/experimental/lazy-projections/laea.ts +1 -1
- package/src/projection/experimental/lazy-projections/lcc.ts +1 -1
- package/src/projection/experimental/lazy-projections/merc.ts +1 -1
- package/src/projection/experimental/lazy-projections/mill.ts +1 -1
- package/src/projection/experimental/lazy-projections/moll.ts +1 -1
- package/src/projection/experimental/lazy-projections/nzmg.ts +1 -1
- package/src/projection/experimental/lazy-projections/ob_tran.ts +1 -1
- package/src/projection/experimental/lazy-projections/omerc.ts +1 -1
- package/src/projection/experimental/lazy-projections/ortho.ts +1 -1
- package/src/projection/experimental/lazy-projections/poly.ts +1 -1
- package/src/projection/experimental/lazy-projections/qsc.ts +1 -1
- package/src/projection/experimental/lazy-projections/robin.ts +1 -1
- package/src/projection/experimental/lazy-projections/sinu.ts +1 -1
- package/src/projection/experimental/lazy-projections/somerc.ts +1 -1
- package/src/projection/experimental/lazy-projections/stere.ts +1 -1
- package/src/projection/experimental/lazy-projections/sterea.ts +1 -1
- package/src/projection/experimental/lazy-projections/tmerc.ts +1 -1
- package/src/projection/experimental/lazy-projections/tpers.ts +1 -1
- package/src/projection/experimental/lazy-projections/utm.ts +1 -1
- package/src/projection/experimental/lazy-projections/vandg.ts +1 -1
- 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/subdivide-geodesic-polyline.ts +2 -2
- package/src/subdivide-globe-mesh.ts +2 -2
- package/src/subdivide-rhumb-polyline.ts +2 -2
- package/src/terrain/geometry.ts +1 -1
- 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/index.cjs +0 -18674
- package/dist/index.cjs.map +0 -6
- package/dist/turf-expressions.cjs +0 -1997
- package/dist/turf-expressions.cjs.map +0 -6
- package/dist/turf-expressions.d.ts +0 -3
- package/dist/turf-expressions.d.ts.map +0 -1
- package/dist/turf-expressions.js +0 -7
- package/dist/turf-expressions.js.map +0 -1
- package/src/turf-expressions.ts +0 -7
package/src/st-functions.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import type {AggregateFunction, ArrowTableFunction, ScalarFunction} from '@math.gl/sql/arrow';
|
|
17
17
|
import {
|
|
18
18
|
getGeoArrowFieldInfo,
|
|
19
|
+
mapGeoArrowVectorCoordinates,
|
|
19
20
|
getGeoArrowBounds,
|
|
20
21
|
getGeoArrowRowBounds,
|
|
21
22
|
getGeoArrowColumnView,
|
|
@@ -26,11 +27,15 @@ import {
|
|
|
26
27
|
type WellKnownGeometry
|
|
27
28
|
} from '@math.gl/core/arrow';
|
|
28
29
|
import {planarIntersects} from './spatial-planar-intersects';
|
|
29
|
-
import {
|
|
30
|
+
import {planarTouches} from './spatial-touches';
|
|
31
|
+
import {linesWithinDistance, pointWithinPolygonDistance} from './spatial-dwithin';
|
|
32
|
+
import {lineLocatePoint, lineSubstring, projectPointToLine} from './linear-referencing';
|
|
33
|
+
import {addMeasure, locateAlong, locateBetween, measuredDimension} from './measure-referencing';
|
|
30
34
|
import {normalizeCRSIdentifier} from './crs/crs-identifier';
|
|
31
35
|
import {EPSG3857ToLngLat, EPSG4326ToEPSG3857} from './web-mercator/mercator-meters';
|
|
32
36
|
import {vertexCount, memberCount, geometryMember} from './geometry-inspection';
|
|
33
37
|
import {reduceLineVertices} from './line-simplification';
|
|
38
|
+
import {simplifyPolygonTopology} from './polygon-simplification';
|
|
34
39
|
import {collectPair, makeLine} from './geometry-constructors';
|
|
35
40
|
import {EPSG3857_HALF_CIRCUMFERENCE} from './web-mercator/mercator-meters';
|
|
36
41
|
import {
|
|
@@ -48,6 +53,7 @@ import {
|
|
|
48
53
|
EXTENSION_NAME,
|
|
49
54
|
geometryTypes,
|
|
50
55
|
lineKinds,
|
|
56
|
+
nativePolygonResult,
|
|
51
57
|
planarGeometry,
|
|
52
58
|
pointCoordinates,
|
|
53
59
|
pointInPolygon,
|
|
@@ -359,20 +365,112 @@ export const ST_DISTANCE = /* @__PURE__ */ spatialFunction(
|
|
|
359
365
|
}
|
|
360
366
|
);
|
|
361
367
|
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
368
|
+
/** Geometry arguments supported by the route-snapping functions. */
|
|
369
|
+
const routePointKinds = ['Point', 'LineString'] as const;
|
|
370
|
+
|
|
371
|
+
/** Returns the closest pair in argument order for point/point and point/line inputs. */
|
|
372
|
+
function closestPair(a: WellKnownGeometry, b: WellKnownGeometry) {
|
|
373
|
+
if (a.type === 'LineString' && b.type === 'LineString') {
|
|
374
|
+
throw new Error('Route snapping requires at least one Point');
|
|
375
|
+
}
|
|
376
|
+
if (a.type === 'LineString' || b.type === 'LineString') {
|
|
377
|
+
const lineFirst = a.type === 'LineString';
|
|
378
|
+
const point = lineFirst ? b : a;
|
|
379
|
+
const xy = pointCoordinates(point);
|
|
380
|
+
const projection = projectPointToLine(lineFirst ? a : b, point);
|
|
381
|
+
if (!xy || !projection) return null;
|
|
382
|
+
const {coordinate, distance} = projection;
|
|
383
|
+
return {start: lineFirst ? coordinate : xy, end: lineFirst ? xy : coordinate, distance};
|
|
384
|
+
}
|
|
385
|
+
const start = pointCoordinates(a);
|
|
386
|
+
const end = pointCoordinates(b);
|
|
387
|
+
return start && end
|
|
388
|
+
? {start, end, distance: Math.hypot(end[0]! - start[0]!, end[1]! - start[1]!)}
|
|
389
|
+
: null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Returns the closest point on the first geometry as GeoArrow WKB. */
|
|
393
|
+
export const ST_CLOSESTPOINT = /* @__PURE__ */ spatialFunction(
|
|
394
|
+
'ST_ClosestPoint',
|
|
395
|
+
[routePointKinds, routePointKinds],
|
|
396
|
+
/* @__PURE__ */ new Binary(),
|
|
397
|
+
([a, b]) => {
|
|
398
|
+
const pair = closestPair(a!, b!);
|
|
399
|
+
return pair ? writeWKB({type: 'Point', coordinates: pair.start}, 'xy') : null;
|
|
400
|
+
}
|
|
374
401
|
);
|
|
375
402
|
|
|
403
|
+
/** Returns the shortest segment from the first geometry to the second as GeoArrow WKB. */
|
|
404
|
+
export const ST_SHORTESTLINE = /* @__PURE__ */ spatialFunction(
|
|
405
|
+
'ST_ShortestLine',
|
|
406
|
+
[routePointKinds, routePointKinds],
|
|
407
|
+
/* @__PURE__ */ new Binary(),
|
|
408
|
+
([a, b]) => {
|
|
409
|
+
const pair = closestPair(a!, b!);
|
|
410
|
+
return pair ? writeWKB({type: 'LineString', coordinates: [pair.start, pair.end]}, 'xy') : null;
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
/** Geometry kinds accepted by the supported proximity pairings. */
|
|
415
|
+
const proximityKinds = [...pointKinds, ...lineKinds, ...polygonKinds];
|
|
416
|
+
|
|
417
|
+
/** Dispatches to the exact planar kernel for the two input geometry types. */
|
|
418
|
+
function withinDistance(a: WellKnownGeometry, b: WellKnownGeometry, radius: number): boolean {
|
|
419
|
+
if (radius < 0) throw new Error('ST_DWithin distance must be nonnegative');
|
|
420
|
+
if (Number.isNaN(radius)) return false;
|
|
421
|
+
if (a.type === 'Point' && (b.type === 'Polygon' || b.type === 'MultiPolygon'))
|
|
422
|
+
return pointWithinPolygonDistance(a, b, radius);
|
|
423
|
+
if (b.type === 'Point' && (a.type === 'Polygon' || a.type === 'MultiPolygon'))
|
|
424
|
+
return pointWithinPolygonDistance(b, a, radius);
|
|
425
|
+
if (
|
|
426
|
+
(a.type === 'LineString' || a.type === 'MultiLineString') &&
|
|
427
|
+
(b.type === 'LineString' || b.type === 'MultiLineString')
|
|
428
|
+
)
|
|
429
|
+
return linesWithinDistance(a, b, radius);
|
|
430
|
+
if (
|
|
431
|
+
(a.type === 'Point' && (b.type === 'Point' || b.type === 'LineString')) ||
|
|
432
|
+
(b.type === 'Point' && a.type === 'LineString')
|
|
433
|
+
) {
|
|
434
|
+
const pair = closestPair(a, b);
|
|
435
|
+
return pair !== null && pair.distance <= radius;
|
|
436
|
+
}
|
|
437
|
+
throw new Error(`ST_DWithin does not support ${a.type} and ${b.type}`);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Binds supported combinations when both input encodings identify their geometry kinds. */
|
|
441
|
+
function makeDWithin(): ScalarFunction {
|
|
442
|
+
const spatial = spatialFunction(
|
|
443
|
+
'ST_DWithin',
|
|
444
|
+
[proximityKinds, proximityKinds],
|
|
445
|
+
new Bool(),
|
|
446
|
+
([a, b], radius) => withinDistance(a!, b!, radius!),
|
|
447
|
+
1
|
|
448
|
+
);
|
|
449
|
+
return {
|
|
450
|
+
...spatial,
|
|
451
|
+
/** Checks concrete native pairs at binding; WKB pairs are checked per row. */
|
|
452
|
+
resolvePrototype(fields) {
|
|
453
|
+
const result = spatial.resolvePrototype!(fields);
|
|
454
|
+
const a = fields[0]?.metadata.get(EXTENSION_NAME);
|
|
455
|
+
const b = fields[1]?.metadata.get(EXTENSION_NAME);
|
|
456
|
+
if (result && a && b && a !== 'geoarrow.wkb' && b !== 'geoarrow.wkb') {
|
|
457
|
+
/** Identifies either concrete native line encoding. */
|
|
458
|
+
const linear = (encoding: string) =>
|
|
459
|
+
encoding === 'geoarrow.linestring' || encoding === 'geoarrow.multilinestring';
|
|
460
|
+
const pointPair =
|
|
461
|
+
(a === 'geoarrow.point' && b !== 'geoarrow.multilinestring') ||
|
|
462
|
+
(b === 'geoarrow.point' && a !== 'geoarrow.multilinestring');
|
|
463
|
+
if (!pointPair && !(linear(a) && linear(b)))
|
|
464
|
+
throw new Error(`ST_DWithin does not support ${a} and ${b}`);
|
|
465
|
+
}
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Tests an inclusive planar radius in the coordinate units of the geometries. */
|
|
472
|
+
export const ST_DWITHIN = /* @__PURE__ */ makeDWithin();
|
|
473
|
+
|
|
376
474
|
/** Tests whether two planar geometries share any point, including their boundaries. */
|
|
377
475
|
export const ST_INTERSECTS = /* @__PURE__ */ spatialFunction(
|
|
378
476
|
'ST_Intersects',
|
|
@@ -384,6 +482,14 @@ export const ST_INTERSECTS = /* @__PURE__ */ spatialFunction(
|
|
|
384
482
|
([a, b]) => planarIntersects(a!, b!)
|
|
385
483
|
);
|
|
386
484
|
|
|
485
|
+
/** Tests boundary contact while excluding intersections between geometry interiors. */
|
|
486
|
+
export const ST_TOUCHES = /* @__PURE__ */ spatialFunction(
|
|
487
|
+
'ST_Touches',
|
|
488
|
+
[geometryTypes, geometryTypes],
|
|
489
|
+
/* @__PURE__ */ new Bool(),
|
|
490
|
+
([a, b]) => planarTouches(a!, b!)
|
|
491
|
+
);
|
|
492
|
+
|
|
387
493
|
/** Interpolates a point at a fraction of the planar length. */
|
|
388
494
|
export const ST_LINEINTERPOLATEPOINT = /* @__PURE__ */ spatialFunction(
|
|
389
495
|
'ST_LineInterpolatePoint',
|
|
@@ -414,6 +520,45 @@ export const ST_LINESUBSTRING = /* @__PURE__ */ spatialFunction(
|
|
|
414
520
|
2
|
|
415
521
|
);
|
|
416
522
|
|
|
523
|
+
/** Interpolates a new M ordinate by cumulative XY length while retaining Z. */
|
|
524
|
+
export const ST_ADDMEASURE = /* @__PURE__ */ spatialFunction(
|
|
525
|
+
'ST_AddMeasure',
|
|
526
|
+
[lineKinds],
|
|
527
|
+
/* @__PURE__ */ new Binary(),
|
|
528
|
+
([line], start, end) => {
|
|
529
|
+
const result = addMeasure(line!, line!.dimension!, start!, end!);
|
|
530
|
+
return writeWKB(result.geometry, result.dimension);
|
|
531
|
+
},
|
|
532
|
+
2,
|
|
533
|
+
true
|
|
534
|
+
);
|
|
535
|
+
|
|
536
|
+
/** Returns the points on a measured route that match the requested measure. */
|
|
537
|
+
export const ST_LOCATEALONG = /* @__PURE__ */ spatialFunction(
|
|
538
|
+
'ST_LocateAlong',
|
|
539
|
+
[lineKinds],
|
|
540
|
+
/* @__PURE__ */ new Binary(),
|
|
541
|
+
([line], measure) => {
|
|
542
|
+
const dimension = measuredDimension(line!.dimension!);
|
|
543
|
+
return writeWKB(locateAlong(line!, dimension, measure!), dimension);
|
|
544
|
+
},
|
|
545
|
+
1,
|
|
546
|
+
true
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
/** Returns the portions of a measured route within an inclusive measure interval. */
|
|
550
|
+
export const ST_LOCATEBETWEEN = /* @__PURE__ */ spatialFunction(
|
|
551
|
+
'ST_LocateBetween',
|
|
552
|
+
[lineKinds],
|
|
553
|
+
/* @__PURE__ */ new Binary(),
|
|
554
|
+
([line], start, end) => {
|
|
555
|
+
const dimension = measuredDimension(line!.dimension!);
|
|
556
|
+
return writeWKB(locateBetween(line!, dimension, start!, end!), dimension);
|
|
557
|
+
},
|
|
558
|
+
2,
|
|
559
|
+
true
|
|
560
|
+
);
|
|
561
|
+
|
|
417
562
|
/** Extracts an EPSG code from a GeoArrow authority identifier or a PROJJSON root ID. */
|
|
418
563
|
function geometrySRID(crs: unknown): number {
|
|
419
564
|
let identifier = typeof crs === 'string' ? normalizeCRSIdentifier(crs) : '';
|
|
@@ -524,6 +669,90 @@ function crsFunction(name: 'ST_SRID' | 'ST_SetSRID' | 'ST_Transform'): ScalarFun
|
|
|
524
669
|
};
|
|
525
670
|
}
|
|
526
671
|
|
|
672
|
+
/** A synchronous projection engine with the requested CRS definitions available. */
|
|
673
|
+
export type SpatialSQLProjectionEngine = {
|
|
674
|
+
/** Prepares a transform in GeoArrow XY axis order. */
|
|
675
|
+
createProjection(options: {from: string | object; to: string; enforceAxis: false}): {
|
|
676
|
+
/** Projects one horizontal coordinate. */
|
|
677
|
+
projectSync(coordinate: readonly number[]): readonly number[];
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
/** Creates an ST_Transform overload backed by a supplied CRS projection engine. */
|
|
682
|
+
export function createSTTransform(engine: SpatialSQLProjectionEngine): ScalarFunction {
|
|
683
|
+
return {
|
|
684
|
+
kind: 'scalar',
|
|
685
|
+
name: 'ST_Transform',
|
|
686
|
+
prototypes: [],
|
|
687
|
+
/** Resolves one source and target CRS for the entire projection. */
|
|
688
|
+
resolvePrototype(fields, literals) {
|
|
689
|
+
if (fields.length !== 2 || !fields[0]) return undefined;
|
|
690
|
+
const field = fields[0];
|
|
691
|
+
const target = literals?.[1];
|
|
692
|
+
if (target === undefined || !Number.isSafeInteger(target) || target <= 0 || target > 998999)
|
|
693
|
+
throw new Error('ST_Transform requires a constant positive integer EPSG code');
|
|
694
|
+
const info = getGeoArrowFieldInfo(field);
|
|
695
|
+
if (!info) throw new Error('ST_Transform requires a GeoArrow geometry column');
|
|
696
|
+
if (info.metadata['edges'] === 'spherical')
|
|
697
|
+
throw new Error('ST_Transform requires planar geometry');
|
|
698
|
+
const source = info.metadata['crs'];
|
|
699
|
+
if (
|
|
700
|
+
!(typeof source === 'string'
|
|
701
|
+
? source.trim()
|
|
702
|
+
: source && typeof source === 'object' && !Array.isArray(source))
|
|
703
|
+
)
|
|
704
|
+
throw new Error('ST_Transform requires source CRS metadata');
|
|
705
|
+
const to = 'EPSG:' + target;
|
|
706
|
+
const transform = engine.createProjection({
|
|
707
|
+
from: source as string | object,
|
|
708
|
+
to,
|
|
709
|
+
enforceAxis: false
|
|
710
|
+
});
|
|
711
|
+
const metadata = JSON.stringify({...info.metadata, crs: to, crs_type: 'authority_code'});
|
|
712
|
+
const targetField = fields[1] ?? new Field('srid', new Int32(), false);
|
|
713
|
+
if (!DataType.isInt(targetField.type) && !DataType.isFloat(targetField.type))
|
|
714
|
+
throw new Error('ST_Transform requires a numeric SRID');
|
|
715
|
+
|
|
716
|
+
/** Projects XY and retains additional ordinates, including the empty-point sentinel. */
|
|
717
|
+
const project = (coordinate: readonly number[]): number[] => {
|
|
718
|
+
if (coordinate.every(Number.isNaN)) return [...coordinate];
|
|
719
|
+
const [x, y] = transform.projectSync([coordinate[0]!, coordinate[1]!]);
|
|
720
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
721
|
+
throw new Error('ST_Transform produced nonfinite coordinates');
|
|
722
|
+
return [x!, y!, ...coordinate.slice(2)];
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
if (info.encoding === 'geoarrow.wkb') {
|
|
726
|
+
const prototype = spatialFunction(
|
|
727
|
+
'ST_Transform',
|
|
728
|
+
[[...geometryTypes, 'GeometryCollection']],
|
|
729
|
+
new Binary(),
|
|
730
|
+
([geometry]) => writeWKB(projectGeometry(geometry!, project), 'xy'),
|
|
731
|
+
1
|
|
732
|
+
).resolvePrototype!(fields)!;
|
|
733
|
+
prototype.result.metadata.set(EXTENSION_METADATA, metadata);
|
|
734
|
+
return prototype;
|
|
735
|
+
}
|
|
736
|
+
if (!geometryTypes.some(kind => 'geoarrow.' + kind.toLowerCase() === info.encoding))
|
|
737
|
+
throw new Error('ST_Transform requires WKB or a specialized native GeoArrow encoding');
|
|
738
|
+
const outputMetadata = new Map(field.metadata);
|
|
739
|
+
outputMetadata.set(EXTENSION_METADATA, metadata);
|
|
740
|
+
return {
|
|
741
|
+
arguments: [field, targetField],
|
|
742
|
+
result: new Field('ST_Transform', field.type, field.nullable, outputMetadata),
|
|
743
|
+
/** Maps native coordinate buffers directly, retaining topology and null rows. */
|
|
744
|
+
evaluate([vector], {activeRows}) {
|
|
745
|
+
return mapGeoArrowVectorCoordinates(
|
|
746
|
+
vector!,
|
|
747
|
+
(coordinate, row) => (activeRows[row] ? project(coordinate) : coordinate),
|
|
748
|
+
{field}
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
527
756
|
/** Returns the field EPSG code, or zero for an unidentified CRS. */
|
|
528
757
|
export const ST_SRID = /* @__PURE__ */ crsFunction('ST_SRID');
|
|
529
758
|
/** Assigns a CRS to a geometry column, preserving its coordinate values. */
|
|
@@ -562,6 +791,31 @@ export const ST_REMOVEREPEATEDPOINTS = /* @__PURE__ */ lineReduction(
|
|
|
562
791
|
/** Reduces route vertices with Douglas-Peucker simplification. */
|
|
563
792
|
export const ST_SIMPLIFY = /* @__PURE__ */ lineReduction('ST_Simplify', 'simplify');
|
|
564
793
|
|
|
794
|
+
/** Simplifies polygon boundaries while retaining shells, holes, and component topology. */
|
|
795
|
+
export const ST_SIMPLIFYPRESERVETOPOLOGY: ScalarFunction = {
|
|
796
|
+
kind: 'scalar',
|
|
797
|
+
name: 'ST_SimplifyPreserveTopology',
|
|
798
|
+
prototypes: [],
|
|
799
|
+
/** Preserves specialized native storage where the input schema identifies its family. */
|
|
800
|
+
resolvePrototype(fields) {
|
|
801
|
+
const encoding = fields[0]?.metadata.get(EXTENSION_NAME);
|
|
802
|
+
const native = encoding === 'geoarrow.polygon' || encoding === 'geoarrow.multipolygon';
|
|
803
|
+
return spatialFunction(
|
|
804
|
+
'ST_SimplifyPreserveTopology',
|
|
805
|
+
[polygonKinds],
|
|
806
|
+
native ? nativePolygonResult(encoding) : new Binary(),
|
|
807
|
+
([geometry], tolerance) => {
|
|
808
|
+
const result = simplifyPolygonTopology(
|
|
809
|
+
geometry as Extract<WellKnownGeometry, {type: 'Polygon' | 'MultiPolygon'}>,
|
|
810
|
+
tolerance!
|
|
811
|
+
);
|
|
812
|
+
return native ? result : writeWKB(result, 'xy');
|
|
813
|
+
},
|
|
814
|
+
1
|
|
815
|
+
).resolvePrototype!(fields);
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
|
|
565
819
|
/** Returns clockwise azimuth from positive Y in radians. */
|
|
566
820
|
export const ST_AZIMUTH = /* @__PURE__ */ spatialFunction(
|
|
567
821
|
'ST_Azimuth',
|
|
@@ -587,10 +841,10 @@ export const ST_AREA = /* @__PURE__ */ spatialFunction(
|
|
|
587
841
|
([geometry]) => planarArea(geometry!)
|
|
588
842
|
);
|
|
589
843
|
|
|
590
|
-
/** Returns planar
|
|
844
|
+
/** Returns the summed planar length of linear components. */
|
|
591
845
|
export const ST_LENGTH = /* @__PURE__ */ spatialFunction(
|
|
592
846
|
'ST_Length',
|
|
593
|
-
[geometryTypes],
|
|
847
|
+
[[...geometryTypes, 'GeometryCollection']],
|
|
594
848
|
/* @__PURE__ */ new Float64(),
|
|
595
849
|
([geometry]) => planarLength(geometry!)
|
|
596
850
|
);
|
|
@@ -823,12 +1077,16 @@ export const POSTGIS_SPATIAL_FUNCTIONS: readonly (ArrowTableFunction | Aggregate
|
|
|
823
1077
|
ST_MAKEENVELOPE,
|
|
824
1078
|
ST_DISTANCE,
|
|
825
1079
|
ST_DWITHIN,
|
|
1080
|
+
ST_CLOSESTPOINT,
|
|
1081
|
+
ST_SHORTESTLINE,
|
|
826
1082
|
ST_INTERSECTS,
|
|
1083
|
+
ST_TOUCHES,
|
|
827
1084
|
ST_SRID,
|
|
828
1085
|
ST_SETSRID,
|
|
829
1086
|
ST_TRANSFORM,
|
|
830
1087
|
ST_REMOVEREPEATEDPOINTS,
|
|
831
1088
|
ST_SIMPLIFY,
|
|
1089
|
+
ST_SIMPLIFYPRESERVETOPOLOGY,
|
|
832
1090
|
ST_AZIMUTH,
|
|
833
1091
|
ST_MAKEPOINT,
|
|
834
1092
|
ST_TILEENVELOPE,
|
|
@@ -837,6 +1095,9 @@ export const POSTGIS_SPATIAL_FUNCTIONS: readonly (ArrowTableFunction | Aggregate
|
|
|
837
1095
|
ST_LINEINTERPOLATEPOINT,
|
|
838
1096
|
ST_LINELOCATEPOINT,
|
|
839
1097
|
ST_LINESUBSTRING,
|
|
1098
|
+
ST_ADDMEASURE,
|
|
1099
|
+
ST_LOCATEALONG,
|
|
1100
|
+
ST_LOCATEBETWEEN,
|
|
840
1101
|
ST_POINTONSURFACE,
|
|
841
1102
|
ST_CENTROID,
|
|
842
1103
|
ST_NPOINTS,
|
|
@@ -850,3 +1111,10 @@ export const POSTGIS_SPATIAL_FUNCTIONS: readonly (ArrowTableFunction | Aggregate
|
|
|
850
1111
|
ST_ENVELOPE,
|
|
851
1112
|
ST_EXTENT
|
|
852
1113
|
]);
|
|
1114
|
+
|
|
1115
|
+
export {
|
|
1116
|
+
ST_GEODESICDISTANCE,
|
|
1117
|
+
ST_GEODESICLENGTH,
|
|
1118
|
+
ST_GEODESICDWITHIN,
|
|
1119
|
+
GEODESIC_SPATIAL_FUNCTIONS
|
|
1120
|
+
} from './st-geodesic-functions';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Bool, Float64} from 'apache-arrow';
|
|
6
|
+
import type {WellKnownGeometry} from '@math.gl/core/arrow';
|
|
7
|
+
import {WGS84_RADIUS_X, WGS84_RADIUS_Z} from './constants';
|
|
8
|
+
import {normalizeCRSIdentifier} from './crs/crs-identifier';
|
|
9
|
+
import {EllipsoidGeodesic} from './ellipsoid-geodesic';
|
|
10
|
+
import {lineKinds, pointKinds, spatialFunction} from './spatial-sql';
|
|
11
|
+
|
|
12
|
+
/** Ellipsoidal kernel with axes expressed in meters, initialized when first used. */
|
|
13
|
+
let kernel: EllipsoidGeodesic | undefined;
|
|
14
|
+
|
|
15
|
+
/** Measures the shortest WGS84 geodesic between two longitude–latitude positions. */
|
|
16
|
+
function meters(a: readonly number[], b: readonly number[]): number {
|
|
17
|
+
kernel ??= new EllipsoidGeodesic({
|
|
18
|
+
semiMajorAxis: WGS84_RADIUS_X,
|
|
19
|
+
semiMinorAxis: WGS84_RADIUS_Z
|
|
20
|
+
});
|
|
21
|
+
return kernel.inverse(a[1]!, a[0]!, b[1]!, b[0]!).s12;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Tests the coordinate representation of an empty point. */
|
|
25
|
+
function emptyPoint(coordinate: readonly number[]): boolean {
|
|
26
|
+
return !coordinate.length || coordinate.every(Number.isNaN);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Measures a point pair, with null for the empty set. */
|
|
30
|
+
function pointDistance(a: WellKnownGeometry, b: WellKnownGeometry): number | null {
|
|
31
|
+
if (a.type !== 'Point' || b.type !== 'Point') throw new Error('Expected geodesic point pair');
|
|
32
|
+
return emptyPoint(a.coordinates) || emptyPoint(b.coordinates)
|
|
33
|
+
? null
|
|
34
|
+
: meters(a.coordinates, b.coordinates);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Measures linear components without adding a segment between components. */
|
|
38
|
+
function lineLength(geometry: WellKnownGeometry): number {
|
|
39
|
+
const lines =
|
|
40
|
+
geometry.type === 'LineString'
|
|
41
|
+
? [geometry.coordinates]
|
|
42
|
+
: geometry.type === 'MultiLineString'
|
|
43
|
+
? geometry.coordinates
|
|
44
|
+
: [];
|
|
45
|
+
let length = 0;
|
|
46
|
+
for (const path of lines)
|
|
47
|
+
for (let index = 1; index < path.length; index++)
|
|
48
|
+
length += meters(path[index - 1]!, path[index]!);
|
|
49
|
+
return length;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Recognizes the WGS84 geographic identifiers in GeoArrow field metadata. */
|
|
53
|
+
function isWGS84(crs: unknown): boolean {
|
|
54
|
+
if (typeof crs === 'string') {
|
|
55
|
+
const identifier = normalizeCRSIdentifier(crs);
|
|
56
|
+
return identifier === 'EPSG:4326' || identifier === 'OGC:CRS84';
|
|
57
|
+
}
|
|
58
|
+
if (!crs || typeof crs !== 'object' || !('id' in crs)) return false;
|
|
59
|
+
const {id} = crs;
|
|
60
|
+
return Boolean(
|
|
61
|
+
id &&
|
|
62
|
+
typeof id === 'object' &&
|
|
63
|
+
'authority' in id &&
|
|
64
|
+
'code' in id &&
|
|
65
|
+
isWGS84(String(id.authority) + ':' + String(id.code))
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Validates the CRS only when a geodesic function is bound. */
|
|
70
|
+
function validateWGS84(crs: unknown, name: string): void {
|
|
71
|
+
if (!isWGS84(crs))
|
|
72
|
+
throw new Error(`${name} requires WGS84 CRS metadata (EPSG:4326 or OGC:CRS84)`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Returns WGS84 point-to-point distance in meters. */
|
|
76
|
+
export const ST_GEODESICDISTANCE = /* @__PURE__ */ spatialFunction(
|
|
77
|
+
'ST_GeodesicDistance',
|
|
78
|
+
[pointKinds, pointKinds],
|
|
79
|
+
/* @__PURE__ */ new Float64(),
|
|
80
|
+
([a, b]) => pointDistance(a!, b!),
|
|
81
|
+
0,
|
|
82
|
+
true,
|
|
83
|
+
false,
|
|
84
|
+
validateWGS84
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/** Sums WGS84 geodesic segment lengths in meters. */
|
|
88
|
+
export const ST_GEODESICLENGTH = /* @__PURE__ */ spatialFunction(
|
|
89
|
+
'ST_GeodesicLength',
|
|
90
|
+
[lineKinds],
|
|
91
|
+
/* @__PURE__ */ new Float64(),
|
|
92
|
+
([line]) => lineLength(line!),
|
|
93
|
+
0,
|
|
94
|
+
true,
|
|
95
|
+
false,
|
|
96
|
+
validateWGS84
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/** Checks an inclusive WGS84 point-to-point proximity threshold in meters. */
|
|
100
|
+
export const ST_GEODESICDWITHIN = /* @__PURE__ */ spatialFunction(
|
|
101
|
+
'ST_GeodesicDWithin',
|
|
102
|
+
[pointKinds, pointKinds],
|
|
103
|
+
/* @__PURE__ */ new Bool(),
|
|
104
|
+
([a, b], radius) => {
|
|
105
|
+
if (!Number.isFinite(radius) || radius! < 0)
|
|
106
|
+
throw new Error('ST_GeodesicDWithin requires a finite nonnegative radius in meters');
|
|
107
|
+
const distance = pointDistance(a!, b!);
|
|
108
|
+
return distance !== null && distance <= radius!;
|
|
109
|
+
},
|
|
110
|
+
1,
|
|
111
|
+
true,
|
|
112
|
+
false,
|
|
113
|
+
validateWGS84
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
/** Opt-in SQL package for ellipsoidal distance, length, and proximity. */
|
|
117
|
+
export const GEODESIC_SPATIAL_FUNCTIONS = /* @__PURE__ */ Object.freeze([
|
|
118
|
+
ST_GEODESICDISTANCE,
|
|
119
|
+
ST_GEODESICLENGTH,
|
|
120
|
+
ST_GEODESICDWITHIN
|
|
121
|
+
]);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Binary} from 'apache-arrow';
|
|
6
|
+
import {writeWKB} from '@math.gl/core/arrow';
|
|
7
|
+
import {concaveHull, convexHull} from './spatial-hulls';
|
|
8
|
+
import {geometryTypes, spatialFunction} from './spatial-sql';
|
|
9
|
+
|
|
10
|
+
/** Returns the smallest convex footprint enclosing the input vertices. */
|
|
11
|
+
export const ST_CONVEXHULL = /* @__PURE__ */ spatialFunction(
|
|
12
|
+
'ST_ConvexHull',
|
|
13
|
+
[[...geometryTypes, 'GeometryCollection']],
|
|
14
|
+
/* @__PURE__ */ new Binary(),
|
|
15
|
+
([geometry]) => writeWKB(convexHull(geometry!), 'xy')
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
/** Returns a hole-free concave footprint around a planar point cloud. */
|
|
19
|
+
export const ST_CONCAVEHULL = /* @__PURE__ */ spatialFunction(
|
|
20
|
+
'ST_ConcaveHull',
|
|
21
|
+
[['Point', 'MultiPoint']],
|
|
22
|
+
/* @__PURE__ */ new Binary(),
|
|
23
|
+
([geometry], ratio) => writeWKB(concaveHull(geometry!, ratio!), 'xy'),
|
|
24
|
+
1
|
|
25
|
+
);
|