@loaders.gl/raster 5.0.0-beta.5 → 5.0.0-beta.6
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/geotiff/advanced.cjs +4 -4
- package/dist/geotiff/geotiff-loader-types.js +1 -1
- package/dist/geotiff/geotiff-raster-loader-types.js +1 -1
- package/dist/geotiff/geotiff-source-loader.js +1 -1
- package/dist/geotiff/loaders.js +1 -1
- package/dist/geotiff/ometiff-source-loader.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lerc/lerc-loader-types.js +1 -1
- package/dist/quantized-mesh-worker.js +4379 -4481
- package/dist/terrain/heightmap.cjs +2 -333
- package/dist/terrain/heightmap.cjs.map +4 -4
- package/dist/terrain/heightmap.d.ts +1 -5
- package/dist/terrain/heightmap.d.ts.map +1 -1
- package/dist/terrain/heightmap.js +0 -3
- package/dist/terrain/heightmap.js.map +1 -1
- package/dist/terrain/index.cjs +35 -76
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +1 -2
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/lib/helpers/skirt.d.ts +2 -9
- package/dist/terrain/lib/helpers/skirt.d.ts.map +1 -1
- package/dist/terrain/lib/helpers/skirt.js +30 -114
- package/dist/terrain/lib/helpers/skirt.js.map +1 -1
- package/dist/terrain/lib/terrain-contracts.d.ts +0 -15
- package/dist/terrain/lib/terrain-contracts.d.ts.map +1 -1
- package/dist/terrain/lib/utils/version.js +1 -1
- package/dist/terrain-worker.js +131 -117
- package/package.json +5 -17
- package/src/index.ts +0 -7
- package/src/terrain/heightmap.ts +0 -10
- package/src/terrain/index.ts +0 -7
- package/src/terrain/lib/helpers/skirt.ts +41 -151
- package/src/terrain/lib/terrain-contracts.ts +0 -19
- package/dist/terrain/lib/terrain-height-field.d.ts +0 -51
- package/dist/terrain/lib/terrain-height-field.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-height-field.js +0 -260
- package/dist/terrain/lib/terrain-height-field.js.map +0 -1
- package/dist/terrain/lib/terrain-height-grid.d.ts +0 -14
- package/dist/terrain/lib/terrain-height-grid.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-height-grid.js +0 -104
- package/dist/terrain/lib/terrain-height-grid.js.map +0 -1
- package/dist/terrain/lib/terrain-neighborhood.d.ts +0 -15
- package/dist/terrain/lib/terrain-neighborhood.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-neighborhood.js +0 -58
- package/dist/terrain/lib/terrain-neighborhood.js.map +0 -1
- package/src/terrain/lib/terrain-height-field.ts +0 -355
- package/src/terrain/lib/terrain-height-grid.ts +0 -157
- package/src/terrain/lib/terrain-neighborhood.ts +0 -69
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {TerrainHeightmap} from './terrain-heightmap-types';
|
|
6
|
-
import type {TerrainGridMetadata, TerrainHeightGrid} from './terrain-contracts';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Detach a decoded heightmap and its explicit georeferencing/validity into a physical grid.
|
|
10
|
-
* Never derives missing data from alpha, fills holes, converts datums or exaggerates heights.
|
|
11
|
-
*/
|
|
12
|
-
export function createTerrainHeightGrid(
|
|
13
|
-
heightmap: TerrainHeightmap,
|
|
14
|
-
metadata: TerrainGridMetadata,
|
|
15
|
-
validity?: Uint8Array
|
|
16
|
-
): TerrainHeightGrid {
|
|
17
|
-
const {width, height} = heightmap;
|
|
18
|
-
const {bounds, registration, verticalDatum} = metadata;
|
|
19
|
-
if (
|
|
20
|
-
!Number.isSafeInteger(width) ||
|
|
21
|
-
!Number.isSafeInteger(height) ||
|
|
22
|
-
width < 2 ||
|
|
23
|
-
height < 2 ||
|
|
24
|
-
!Number.isSafeInteger(width * height) ||
|
|
25
|
-
heightmap.heights.length !== width * height
|
|
26
|
-
) {
|
|
27
|
-
throw new RangeError('Terrain grid requires a complete heightmap of at least 2 by 2');
|
|
28
|
-
}
|
|
29
|
-
if (
|
|
30
|
-
bounds.length !== 4 ||
|
|
31
|
-
!bounds.every(Number.isFinite) ||
|
|
32
|
-
bounds[0] >= bounds[2] ||
|
|
33
|
-
bounds[1] >= bounds[3] ||
|
|
34
|
-
!Number.isFinite(bounds[2] - bounds[0]) ||
|
|
35
|
-
!Number.isFinite(bounds[3] - bounds[1])
|
|
36
|
-
) {
|
|
37
|
-
throw new RangeError('Terrain grid bounds must have finite positive extent');
|
|
38
|
-
}
|
|
39
|
-
if (
|
|
40
|
-
!['pixel-center', 'grid-node'].includes(registration) ||
|
|
41
|
-
!['ellipsoidal', 'orthometric', 'unknown'].includes(verticalDatum)
|
|
42
|
-
) {
|
|
43
|
-
throw new RangeError('Terrain grid registration and vertical datum must be explicit');
|
|
44
|
-
}
|
|
45
|
-
if (validity && validity.length !== width * height)
|
|
46
|
-
throw new RangeError('Terrain grid validity must match samples');
|
|
47
|
-
const heights = new Float32Array(width * height);
|
|
48
|
-
const valid = new Uint8Array(width * height);
|
|
49
|
-
for (let index = 0; index < heights.length; index++) {
|
|
50
|
-
valid[index] = validity ? Number(validity[index] !== 0) : 1;
|
|
51
|
-
heights[index] = valid[index] ? heightmap.heights[index] : NaN;
|
|
52
|
-
if (valid[index] && !Number.isFinite(heights[index]))
|
|
53
|
-
throw new RangeError('Valid terrain heights must be finite');
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
width,
|
|
57
|
-
height,
|
|
58
|
-
heights,
|
|
59
|
-
valid,
|
|
60
|
-
bounds: [bounds[0], bounds[1], bounds[2], bounds[3]],
|
|
61
|
-
registration,
|
|
62
|
-
verticalDatum
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Bilinear sample of a valid physical grid. Closed footprint edges clamp to the nearest
|
|
68
|
-
* pixel center. Outside points and missing nonzero-weight support return null, never zero.
|
|
69
|
-
* The caller must not mutate the grid while it is shared with consumers.
|
|
70
|
-
*/
|
|
71
|
-
export function sampleTerrainHeightGrid(
|
|
72
|
-
grid: TerrainHeightGrid,
|
|
73
|
-
position: readonly [number, number]
|
|
74
|
-
): number | null {
|
|
75
|
-
const [west, south, east, north] = grid.bounds;
|
|
76
|
-
if (
|
|
77
|
-
position.length !== 2 ||
|
|
78
|
-
!position.every(Number.isFinite) ||
|
|
79
|
-
position[0] < west ||
|
|
80
|
-
position[0] > east ||
|
|
81
|
-
position[1] < south ||
|
|
82
|
-
position[1] > north
|
|
83
|
-
)
|
|
84
|
-
return null;
|
|
85
|
-
const centered = grid.registration === 'pixel-center';
|
|
86
|
-
const column = snapTerrainSample(
|
|
87
|
-
Math.max(
|
|
88
|
-
0,
|
|
89
|
-
Math.min(
|
|
90
|
-
grid.width - 1,
|
|
91
|
-
((position[0] - west) / (east - west)) * (centered ? grid.width : grid.width - 1) -
|
|
92
|
-
(centered ? 0.5 : 0)
|
|
93
|
-
)
|
|
94
|
-
),
|
|
95
|
-
position[0],
|
|
96
|
-
west,
|
|
97
|
-
east,
|
|
98
|
-
grid.width
|
|
99
|
-
);
|
|
100
|
-
const row = snapTerrainSample(
|
|
101
|
-
Math.max(
|
|
102
|
-
0,
|
|
103
|
-
Math.min(
|
|
104
|
-
grid.height - 1,
|
|
105
|
-
((north - position[1]) / (north - south)) * (centered ? grid.height : grid.height - 1) -
|
|
106
|
-
(centered ? 0.5 : 0)
|
|
107
|
-
)
|
|
108
|
-
),
|
|
109
|
-
position[1],
|
|
110
|
-
south,
|
|
111
|
-
north,
|
|
112
|
-
grid.height
|
|
113
|
-
);
|
|
114
|
-
const left = Math.floor(column),
|
|
115
|
-
top = Math.floor(row);
|
|
116
|
-
const horizontal = column - left,
|
|
117
|
-
vertical = row - top;
|
|
118
|
-
const samples = [
|
|
119
|
-
top * grid.width + left,
|
|
120
|
-
top * grid.width + Math.min(left + 1, grid.width - 1),
|
|
121
|
-
Math.min(top + 1, grid.height - 1) * grid.width + left,
|
|
122
|
-
Math.min(top + 1, grid.height - 1) * grid.width + Math.min(left + 1, grid.width - 1)
|
|
123
|
-
];
|
|
124
|
-
const weights = [
|
|
125
|
-
(1 - horizontal) * (1 - vertical),
|
|
126
|
-
horizontal * (1 - vertical),
|
|
127
|
-
(1 - horizontal) * vertical,
|
|
128
|
-
horizontal * vertical
|
|
129
|
-
];
|
|
130
|
-
let height = 0;
|
|
131
|
-
for (let index = 0; index < samples.length; index++) {
|
|
132
|
-
if (weights[index] === 0) continue;
|
|
133
|
-
if (!grid.valid[samples[index]]) return null;
|
|
134
|
-
height += grid.heights[samples[index]] * weights[index];
|
|
135
|
-
}
|
|
136
|
-
return height;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Remove coordinate roundoff at exact samples, without broadening support by more than 1e-6 pixels. */
|
|
140
|
-
function snapTerrainSample(
|
|
141
|
-
value: number,
|
|
142
|
-
coordinate: number,
|
|
143
|
-
minimum: number,
|
|
144
|
-
maximum: number,
|
|
145
|
-
size: number
|
|
146
|
-
): number {
|
|
147
|
-
const nearest = Math.round(value);
|
|
148
|
-
const tolerance = Math.min(
|
|
149
|
-
1e-6,
|
|
150
|
-
((8 *
|
|
151
|
-
Number.EPSILON *
|
|
152
|
-
Math.max(1, Math.abs(coordinate), Math.abs(minimum), Math.abs(maximum))) /
|
|
153
|
-
(maximum - minimum)) *
|
|
154
|
-
size
|
|
155
|
-
);
|
|
156
|
-
return Math.abs(value - nearest) <= tolerance ? nearest : value;
|
|
157
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {TerrainHeightGrid} from './terrain-contracts';
|
|
6
|
-
import {TerrainHeightField} from './terrain-height-field';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Sample physical meters across closed neighboring footprints, averaging shared edges.
|
|
10
|
-
* Any contributing hole returns null. Datums must match; no wrapping or reprojection occurs.
|
|
11
|
-
* Reuse TerrainHeightField rather than this convenience function for repeated queries.
|
|
12
|
-
*/
|
|
13
|
-
export function sampleTerrainNeighborhood(
|
|
14
|
-
grids: readonly TerrainHeightGrid[],
|
|
15
|
-
position: readonly [number, number]
|
|
16
|
-
): number | null {
|
|
17
|
-
return new TerrainHeightField(grids).sampleHeight(position);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Reconstruct explicit edge nodes from a pixel-centered grid and equal-resolution neighbors.
|
|
22
|
-
* Pixel-centered inputs become (width + 1) by (height + 1); grid-node inputs retain dimensions.
|
|
23
|
-
* Missing neighbors clamp to the source edge. Touching holes remain invalid, never filled.
|
|
24
|
-
* Arrays are detached; heights remain physical source meters with the original vertical datum.
|
|
25
|
-
*/
|
|
26
|
-
export function resampleTerrainNodes(
|
|
27
|
-
grid: TerrainHeightGrid,
|
|
28
|
-
neighbors: readonly TerrainHeightGrid[] = []
|
|
29
|
-
): TerrainHeightGrid {
|
|
30
|
-
const grids = [grid, ...new Set(neighbors.filter(neighbor => neighbor !== grid))];
|
|
31
|
-
const field = new TerrainHeightField(grids);
|
|
32
|
-
const [west, south, east, north] = grid.bounds;
|
|
33
|
-
for (const neighbor of grids) {
|
|
34
|
-
if (
|
|
35
|
-
neighbor.registration !== grid.registration ||
|
|
36
|
-
neighbor.width !== grid.width ||
|
|
37
|
-
neighbor.height !== grid.height ||
|
|
38
|
-
Math.abs((neighbor.bounds[2] - neighbor.bounds[0]) / (east - west) - 1) > 1e-8 ||
|
|
39
|
-
Math.abs((neighbor.bounds[3] - neighbor.bounds[1]) / (north - south) - 1) > 1e-8
|
|
40
|
-
)
|
|
41
|
-
throw new RangeError('Terrain neighbors require matching resolution and registration');
|
|
42
|
-
}
|
|
43
|
-
const columns = grid.registration === 'pixel-center' ? grid.width : grid.width - 1;
|
|
44
|
-
const rows = grid.registration === 'pixel-center' ? grid.height : grid.height - 1;
|
|
45
|
-
const width = columns + 1;
|
|
46
|
-
const height = rows + 1;
|
|
47
|
-
const heights = new Float32Array(width * height);
|
|
48
|
-
const valid = new Uint8Array(width * height);
|
|
49
|
-
for (let row = 0; row < height; row++) {
|
|
50
|
-
for (let column = 0; column < width; column++) {
|
|
51
|
-
const value = field.sampleHeight([
|
|
52
|
-
west + (column / columns) * (east - west),
|
|
53
|
-
north - (row / rows) * (north - south)
|
|
54
|
-
]);
|
|
55
|
-
const index = row * width + column;
|
|
56
|
-
heights[index] = value ?? NaN;
|
|
57
|
-
valid[index] = Number(value !== null);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
width,
|
|
62
|
-
height,
|
|
63
|
-
heights,
|
|
64
|
-
valid,
|
|
65
|
-
bounds: [west, south, east, north],
|
|
66
|
-
registration: 'grid-node',
|
|
67
|
-
verticalDatum: grid.verticalDatum
|
|
68
|
-
};
|
|
69
|
-
}
|