@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.
Files changed (127) hide show
  1. package/dist/line-simplification.d.ts +7 -0
  2. package/dist/line-simplification.d.ts.map +1 -1
  3. package/dist/line-simplification.js +4 -13
  4. package/dist/line-simplification.js.map +1 -1
  5. package/dist/linear-referencing.d.ts +13 -1
  6. package/dist/linear-referencing.d.ts.map +1 -1
  7. package/dist/linear-referencing.js +29 -9
  8. package/dist/linear-referencing.js.map +1 -1
  9. package/dist/measure-referencing.d.ts +16 -0
  10. package/dist/measure-referencing.d.ts.map +1 -0
  11. package/dist/measure-referencing.js +143 -0
  12. package/dist/measure-referencing.js.map +1 -0
  13. package/dist/polygon-simplification.d.ts +6 -0
  14. package/dist/polygon-simplification.d.ts.map +1 -0
  15. package/dist/polygon-simplification.js +141 -0
  16. package/dist/polygon-simplification.js.map +1 -0
  17. package/dist/spatial-box-clipping.d.ts +9 -0
  18. package/dist/spatial-box-clipping.d.ts.map +1 -0
  19. package/dist/spatial-box-clipping.js +123 -0
  20. package/dist/spatial-box-clipping.js.map +1 -0
  21. package/dist/spatial-dwithin.d.ts +19 -0
  22. package/dist/spatial-dwithin.d.ts.map +1 -0
  23. package/dist/spatial-dwithin.js +107 -0
  24. package/dist/spatial-dwithin.js.map +1 -0
  25. package/dist/spatial-hulls.d.ts +6 -0
  26. package/dist/spatial-hulls.d.ts.map +1 -0
  27. package/dist/spatial-hulls.js +176 -0
  28. package/dist/spatial-hulls.js.map +1 -0
  29. package/dist/spatial-line-intersection-result.d.ts +4 -0
  30. package/dist/spatial-line-intersection-result.d.ts.map +1 -0
  31. package/dist/spatial-line-intersection-result.js +79 -0
  32. package/dist/spatial-line-intersection-result.js.map +1 -0
  33. package/dist/spatial-line-polygon-intersection.d.ts +4 -0
  34. package/dist/spatial-line-polygon-intersection.d.ts.map +1 -0
  35. package/dist/spatial-line-polygon-intersection.js +130 -0
  36. package/dist/spatial-line-polygon-intersection.js.map +1 -0
  37. package/dist/spatial-planar-intersects.d.ts +11 -0
  38. package/dist/spatial-planar-intersects.d.ts.map +1 -1
  39. package/dist/spatial-planar-intersects.js +20 -12
  40. package/dist/spatial-planar-intersects.js.map +1 -1
  41. package/dist/spatial-planar.d.ts +9 -0
  42. package/dist/spatial-planar.d.ts.map +1 -1
  43. package/dist/spatial-planar.js +13 -1
  44. package/dist/spatial-planar.js.map +1 -1
  45. package/dist/spatial-polygon-overlay.d.ts +5 -0
  46. package/dist/spatial-polygon-overlay.d.ts.map +1 -0
  47. package/dist/spatial-polygon-overlay.js +23 -0
  48. package/dist/spatial-polygon-overlay.js.map +1 -0
  49. package/dist/spatial-sql.d.ts +13 -2
  50. package/dist/spatial-sql.d.ts.map +1 -1
  51. package/dist/spatial-sql.js +30 -12
  52. package/dist/spatial-sql.js.map +1 -1
  53. package/dist/spatial-subdivision.d.ts +9 -0
  54. package/dist/spatial-subdivision.d.ts.map +1 -0
  55. package/dist/spatial-subdivision.js +61 -0
  56. package/dist/spatial-subdivision.js.map +1 -0
  57. package/dist/spatial-touches.d.ts +13 -0
  58. package/dist/spatial-touches.d.ts.map +1 -0
  59. package/dist/spatial-touches.js +192 -0
  60. package/dist/spatial-touches.js.map +1 -0
  61. package/dist/st-functions.cjs +2411 -112
  62. package/dist/st-functions.cjs.map +3 -3
  63. package/dist/st-functions.d.ts +67 -2
  64. package/dist/st-functions.d.ts.map +1 -1
  65. package/dist/st-functions.js +195 -12
  66. package/dist/st-functions.js.map +1 -1
  67. package/dist/st-geodesic-functions.d.ts +33 -0
  68. package/dist/st-geodesic-functions.d.ts.map +1 -0
  69. package/dist/st-geodesic-functions.js +84 -0
  70. package/dist/st-geodesic-functions.js.map +1 -0
  71. package/dist/st-hull-functions.cjs +386 -0
  72. package/dist/st-hull-functions.cjs.map +6 -0
  73. package/dist/st-hull-functions.d.ts +17 -0
  74. package/dist/st-hull-functions.d.ts.map +1 -0
  75. package/dist/st-hull-functions.js +14 -0
  76. package/dist/st-hull-functions.js.map +1 -0
  77. package/dist/st-overlay-functions.cjs +621 -0
  78. package/dist/st-overlay-functions.cjs.map +6 -0
  79. package/dist/st-overlay-functions.d.ts +36 -0
  80. package/dist/st-overlay-functions.d.ts.map +1 -0
  81. package/dist/st-overlay-functions.js +183 -0
  82. package/dist/st-overlay-functions.js.map +1 -0
  83. package/dist/st-viewport-functions.cjs +481 -0
  84. package/dist/st-viewport-functions.cjs.map +6 -0
  85. package/dist/st-viewport-functions.d.ts +13 -0
  86. package/dist/st-viewport-functions.d.ts.map +1 -0
  87. package/dist/st-viewport-functions.js +81 -0
  88. package/dist/st-viewport-functions.js.map +1 -0
  89. package/dist/terrain/index.cjs +93 -20
  90. package/dist/terrain/index.cjs.map +3 -3
  91. package/dist/terrain/index.d.ts +1 -0
  92. package/dist/terrain/index.d.ts.map +1 -1
  93. package/dist/terrain/index.js +1 -0
  94. package/dist/terrain/index.js.map +1 -1
  95. package/dist/terrain/regional-watersheds.d.ts +44 -0
  96. package/dist/terrain/regional-watersheds.d.ts.map +1 -0
  97. package/dist/terrain/regional-watersheds.js +108 -0
  98. package/dist/terrain/regional-watersheds.js.map +1 -0
  99. package/dist/terrain/tile-cutout-update.d.ts.map +1 -1
  100. package/dist/terrain/tile-cutout-update.js +28 -22
  101. package/dist/terrain/tile-cutout-update.js.map +1 -1
  102. package/dist/turf-functions.cjs +16 -9
  103. package/dist/turf-functions.cjs.map +1 -1
  104. package/package.json +21 -6
  105. package/src/line-simplification.ts +4 -16
  106. package/src/linear-referencing.ts +44 -16
  107. package/src/measure-referencing.ts +165 -0
  108. package/src/polygon-simplification.ts +185 -0
  109. package/src/spatial-box-clipping.ts +140 -0
  110. package/src/spatial-dwithin.ts +135 -0
  111. package/src/spatial-hulls.ts +203 -0
  112. package/src/spatial-line-intersection-result.ts +93 -0
  113. package/src/spatial-line-polygon-intersection.ts +147 -0
  114. package/src/spatial-planar-intersects.ts +21 -15
  115. package/src/spatial-planar.ts +20 -1
  116. package/src/spatial-polygon-overlay.ts +30 -0
  117. package/src/spatial-sql.ts +47 -12
  118. package/src/spatial-subdivision.ts +75 -0
  119. package/src/spatial-touches.ts +218 -0
  120. package/src/st-functions.ts +283 -15
  121. package/src/st-geodesic-functions.ts +121 -0
  122. package/src/st-hull-functions.ts +25 -0
  123. package/src/st-overlay-functions.ts +244 -0
  124. package/src/st-viewport-functions.ts +98 -0
  125. package/src/terrain/index.ts +7 -0
  126. package/src/terrain/regional-watersheds.ts +153 -0
  127. package/src/terrain/tile-cutout-update.ts +32 -26
@@ -63,6 +63,7 @@ __export(index_exports, {
63
63
  createTerrainMixedIsobands: () => createTerrainMixedIsobands,
64
64
  createTerrainMixedVertexTileHalos: () => createTerrainMixedVertexTileHalos,
65
65
  createTerrainRegionalViewshed: () => createTerrainRegionalViewshed,
66
+ createTerrainRegionalWatersheds: () => createTerrainRegionalWatersheds,
66
67
  createTerrainSkirt: () => createTerrainSkirt,
67
68
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
68
69
  createTerrainSurface: () => createTerrainSurface,
@@ -8032,6 +8033,7 @@ function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
8032
8033
  splitTerrainMesh({ positions: new Float64Array(), indices: new Uint32Array() }, polygon2, limits);
8033
8034
  const entries = /* @__PURE__ */ new Map();
8034
8035
  const rebuilt = [];
8036
+ const dirty = /* @__PURE__ */ new Map();
8035
8037
  let boundaryCount = 0;
8036
8038
  for (const resident of residents) {
8037
8039
  if (!resident.id || typeof resident.id !== "string" || entries.has(resident.id) || !Number.isSafeInteger(resident.revision) || resident.revision < 0)
@@ -8053,6 +8055,7 @@ function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
8053
8055
  }
8054
8056
  entry = { resident: { ...resident }, split, displayed: split, bounds: bounds2, edges: edges2 };
8055
8057
  rebuilt.push(resident.id);
8058
+ dirty.set(entry, entries.size);
8056
8059
  }
8057
8060
  boundaryCount += entry.edges.length;
8058
8061
  if (boundaryCount > limits.maxBoundaryEdges)
@@ -8060,45 +8063,42 @@ function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
8060
8063
  entries.set(resident.id, entry);
8061
8064
  }
8062
8065
  const values = [...entries.values()];
8063
- let pairs = 0;
8064
- for (let i = 0; i < values.length; i++)
8065
- for (let j = i + 1; j < values.length; j++) {
8066
- if (++pairs > limits.maxPairChecks)
8067
- throw new RangeError("Terrain cutout pair budget exceeded");
8068
- const a = values[i], b = values[j];
8069
- if (a.bounds[2] < b.bounds[0] || b.bounds[2] < a.bounds[0] || a.bounds[3] < b.bounds[1] || b.bounds[3] < a.bounds[1])
8066
+ const pairCount = values.length * (values.length - 1) / 2;
8067
+ if (pairCount > limits.maxPairChecks)
8068
+ throw new RangeError("Terrain cutout pair budget exceeded");
8069
+ for (const [a, index] of dirty)
8070
+ for (const b of values) {
8071
+ if (a === b || (dirty.get(b) ?? Infinity) < index)
8070
8072
  continue;
8071
- if (compatible && prior.entries.get(a.resident.id) === a && prior.entries.get(b.resident.id) === b)
8073
+ if (a.bounds[2] < b.bounds[0] || b.bounds[2] < a.bounds[0] || a.bounds[3] < b.bounds[1] || b.bounds[3] < a.bounds[1])
8072
8074
  continue;
8073
8075
  const combined = assembleTerrainCutoutTiles([a.resident.mesh, b.resident.mesh], limits);
8074
8076
  validateTerrainCutoutTopology(combined.mesh, combined.remainingWork);
8075
8077
  }
8076
8078
  const boundaries = /* @__PURE__ */ new Map();
8077
- const cutKeys = /* @__PURE__ */ new Map();
8078
8079
  for (let tile = 0; tile < values.length; tile++)
8079
8080
  for (const edge2 of values[tile].edges) {
8080
8081
  const other = boundaries.get(edge2.key);
8081
- if (!other) {
8082
- boundaries.set(edge2.key, { edge: edge2, paired: false });
8082
+ if (other === void 0) {
8083
+ boundaries.set(edge2.key, edge2);
8083
8084
  continue;
8084
8085
  }
8085
- if (other.paired || other.edge.start !== edge2.end || other.edge.end !== edge2.start)
8086
+ if (typeof other !== "object" || other === null || other.start !== edge2.end || other.end !== edge2.start)
8086
8087
  throw new RangeError("Nonconforming terrain cutout tile boundary");
8087
- other.paired = true;
8088
- if (other.edge.side !== edge2.side) {
8089
- cutKeys.set(edge2.key, edge2.side === 0 ? edge2.polygon : other.edge.polygon);
8090
- }
8088
+ boundaries.set(edge2.key, other.side === edge2.side ? null : edge2.side === 0 ? edge2.polygon : other.polygon);
8091
8089
  }
8092
8090
  const tiles = /* @__PURE__ */ new Map();
8093
8091
  const changed = [];
8092
+ const cuts = [[], []];
8093
+ const polygons = [[], []];
8094
8094
  for (let i = 0; i < values.length; i++) {
8095
8095
  const entry = values[i];
8096
8096
  const old = prior == null ? void 0 : prior.entries.get(entry.resident.id);
8097
- const cuts = [[], []];
8098
- const polygons = [[], []];
8097
+ cuts[0].length = cuts[1].length = 0;
8098
+ polygons[0].length = polygons[1].length = 0;
8099
8099
  for (const edge2 of entry.edges) {
8100
- const polygonIndex = cutKeys.get(edge2.key);
8101
- if (polygonIndex !== void 0) {
8100
+ const polygonIndex = boundaries.get(edge2.key);
8101
+ if (typeof polygonIndex === "number") {
8102
8102
  cuts[edge2.side].push(edge2.a, edge2.b);
8103
8103
  polygons[edge2.side].push(polygonIndex);
8104
8104
  }
@@ -8374,4 +8374,77 @@ function contains(ring, p, charge) {
8374
8374
  }
8375
8375
  return winding === 0 ? -1 : 1;
8376
8376
  }
8377
+
8378
+ // dist/terrain/regional-watersheds.js
8379
+ function createTerrainRegionalWatersheds(tiles, { width, height, origin, outlets, maxCells = 4194304 }) {
8380
+ const count = width * height;
8381
+ if (!Number.isSafeInteger(width) || width < 2 || !Number.isSafeInteger(height) || height < 2 || !Number.isSafeInteger(maxCells) || maxCells < 0 || origin.length !== 2 || !origin.every(Number.isFinite) || count > maxCells || count > 2147483647 || !tiles.length)
8382
+ throw new RangeError("Invalid regional watershed window or cell budget");
8383
+ const { columnStep, rowStep, heightReference, diagonal } = tiles[0].field;
8384
+ const heights = new Float64Array(count);
8385
+ const validity = new Uint8Array(count);
8386
+ const coverage = new Uint8Array(count);
8387
+ for (const { column, row, field: field2 } of tiles) {
8388
+ if (!Number.isSafeInteger(column) || !Number.isSafeInteger(row) || column < 0 || row < 0 || column + field2.width > width || row + field2.height > height || field2.registration !== "cell" || field2.heightReference !== heightReference || field2.diagonal !== diagonal || !origin.every((value, axis) => field2.origin[axis] === value + column * columnStep[axis] + row * rowStep[axis] && field2.columnStep[axis] === columnStep[axis] && field2.rowStep[axis] === rowStep[axis]))
8389
+ throw new RangeError("Regional watershed tiles must align to the shared cell grid");
8390
+ for (let y = 0; y < field2.height; y++) {
8391
+ for (let x = 0; x < field2.width; x++) {
8392
+ const index = (row + y) * width + column + x;
8393
+ if (coverage[index])
8394
+ throw new RangeError("Regional watershed tiles overlap");
8395
+ const value = field2.getHeight(x, y);
8396
+ coverage[index] = value === void 0 ? 1 : 2;
8397
+ if (value !== void 0) {
8398
+ heights[index] = value;
8399
+ validity[index] = 1;
8400
+ }
8401
+ }
8402
+ }
8403
+ }
8404
+ const mosaic = new HeightField({
8405
+ width,
8406
+ height,
8407
+ origin,
8408
+ columnStep,
8409
+ rowStep,
8410
+ heightReference,
8411
+ diagonal,
8412
+ registration: "cell",
8413
+ heights,
8414
+ validity
8415
+ });
8416
+ const { field, receiver } = fillTerrainDepressions(mosaic, { outlets, maxCells });
8417
+ const touchesUnknown = new Uint8Array(count);
8418
+ const queue = new Int32Array(count);
8419
+ let end = 0;
8420
+ function mark(index) {
8421
+ if (coverage[index] !== 2 || touchesUnknown[index])
8422
+ return;
8423
+ touchesUnknown[index] = 1;
8424
+ queue[end++] = index;
8425
+ }
8426
+ function markNeighbors(index) {
8427
+ const x = index % width;
8428
+ if (x > 0)
8429
+ mark(index - 1);
8430
+ if (x + 1 < width)
8431
+ mark(index + 1);
8432
+ if (index >= width)
8433
+ mark(index - width);
8434
+ if (index < count - width)
8435
+ mark(index + width);
8436
+ }
8437
+ for (let i = 0; i < count; i++)
8438
+ if (coverage[i] === 0)
8439
+ markNeighbors(i);
8440
+ for (let i = 0; i < end; i++)
8441
+ markNeighbors(queue[i]);
8442
+ return {
8443
+ field,
8444
+ receiver,
8445
+ coverage,
8446
+ touchesUnknown,
8447
+ ...accumulateTerrainWatersheds(receiver, { maxCells })
8448
+ };
8449
+ }
8377
8450
  //# sourceMappingURL=index.cjs.map