@gisatcz/deckgl-geolib 1.12.0-dev.0 → 1.12.0-dev.11
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 +67 -64
- package/dist/cjs/index.js +3450 -13059
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +3 -4
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/types/cogbitmaplayer/CogBitmapLayer.d.ts +2 -4
- package/dist/cjs/types/cogtiles/cogtiles.d.ts +121 -16
- package/dist/cjs/types/geoimage/geoimage.d.ts +7 -6
- package/dist/esm/index.js +3450 -13059
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +3 -4
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/types/cogbitmaplayer/CogBitmapLayer.d.ts +2 -4
- package/dist/esm/types/cogtiles/cogtiles.d.ts +121 -16
- package/dist/esm/types/geoimage/geoimage.d.ts +7 -6
- package/package.json +26 -4
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -3
- package/CHANGELOG.md +0 -166
- package/rollup.config.mjs +0 -77
- package/src/cogbitmaplayer/CogBitmapLayer.ts +0 -326
- package/src/cogbitmaplayer/README.md +0 -113
- package/src/cogterrainlayer/CogTerrainLayer.ts +0 -445
- package/src/cogterrainlayer/README.md +0 -118
- package/src/cogtiles/README.md +0 -72
- package/src/cogtiles/cogtiles.ts +0 -316
- package/src/cogtiles/lzw.js +0 -256
- package/src/geoimage/README.md +0 -129
- package/src/geoimage/delatin/index.ts +0 -495
- package/src/geoimage/geoimage.ts +0 -597
- package/src/geoimage/helpers/skirt.ts +0 -171
- package/src/index.ts +0 -11
- package/src/utilities/tileurls.ts +0 -21
- package/tsconfig.json +0 -6
package/src/cogtiles/cogtiles.ts
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
/* eslint 'max-len': [1, { code: 100, comments: 999, ignoreStrings: true, ignoreUrls: true }] */
|
|
2
|
-
// COG loading
|
|
3
|
-
import { Tiff, TiffImage } from '@cogeotiff/core';
|
|
4
|
-
import { SourceHttp } from '@chunkd/source-http';
|
|
5
|
-
|
|
6
|
-
// Image compression support
|
|
7
|
-
import { inflate } from 'pako';
|
|
8
|
-
import jpeg from 'jpeg-js';
|
|
9
|
-
import { worldToLngLat } from '@math.gl/web-mercator';
|
|
10
|
-
import LZWDecoder from './lzw';
|
|
11
|
-
|
|
12
|
-
// Bitmap styling
|
|
13
|
-
import GeoImage, { GeoImageOptions } from '../geoimage/geoimage.ts';
|
|
14
|
-
|
|
15
|
-
export type Bounds = [minX: number, minY: number, maxX: number, maxY: number];
|
|
16
|
-
|
|
17
|
-
const EARTH_CIRCUMFERENCE = 2 * Math.PI * 6378137;
|
|
18
|
-
const EARTH_HALF_CIRCUMFERENCE = EARTH_CIRCUMFERENCE / 2;
|
|
19
|
-
|
|
20
|
-
const CogTilesGeoImageOptionsDefaults = {
|
|
21
|
-
blurredTexture: true,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
class CogTiles {
|
|
25
|
-
cog: Tiff;
|
|
26
|
-
|
|
27
|
-
zoomRange = [0, 0];
|
|
28
|
-
|
|
29
|
-
tileSize: number;
|
|
30
|
-
|
|
31
|
-
lowestOriginTileOffset = [0, 0];
|
|
32
|
-
|
|
33
|
-
lowestOriginTileSize = 0;
|
|
34
|
-
|
|
35
|
-
loaded: boolean = false;
|
|
36
|
-
|
|
37
|
-
geo: GeoImage = new GeoImage();
|
|
38
|
-
|
|
39
|
-
lzw: LZWDecoder = new LZWDecoder();
|
|
40
|
-
|
|
41
|
-
options: GeoImageOptions;
|
|
42
|
-
|
|
43
|
-
constructor(options: GeoImageOptions) {
|
|
44
|
-
this.options = { ...CogTilesGeoImageOptionsDefaults, ...options };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async initializeCog(url: string) {
|
|
48
|
-
// Set native fetch instead node-fetch to SourceHttp
|
|
49
|
-
SourceHttp.fetch = async (input, init) => {
|
|
50
|
-
const res = await fetch(input, init);
|
|
51
|
-
return res;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const source = new SourceHttp(url);
|
|
55
|
-
this.cog = await Tiff.create(source);
|
|
56
|
-
|
|
57
|
-
this.cog.images.forEach((image:TiffImage) => {
|
|
58
|
-
image.loadGeoTiffTags();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.tileSize = this.getTileSize(this.cog);
|
|
62
|
-
|
|
63
|
-
this.lowestOriginTileOffset = this.getImageTileIndex(
|
|
64
|
-
this.cog.images[this.cog.images.length - 1],
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
this.zoomRange = this.getZoomRange(this.cog);
|
|
68
|
-
|
|
69
|
-
return this.cog;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getTileSize(cog: Tiff) {
|
|
73
|
-
return cog.images[cog.images.length - 1].tileSize.width;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getZoomRange(cog: Tiff) {
|
|
77
|
-
const img = cog.images[cog.images.length - 1];
|
|
78
|
-
|
|
79
|
-
const minZoom = this.getZoomLevelFromResolution(
|
|
80
|
-
cog.images[cog.images.length - 1].tileSize.width,
|
|
81
|
-
img.resolution[0],
|
|
82
|
-
);
|
|
83
|
-
const maxZoom = minZoom + (cog.images.length - 1);
|
|
84
|
-
|
|
85
|
-
return [minZoom, maxZoom];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getBoundsAsLatLon(cog: Tiff) {
|
|
89
|
-
const { bbox } = cog.images[cog.images.length - 1];
|
|
90
|
-
|
|
91
|
-
const minX = Math.min(bbox[0], bbox[2]);
|
|
92
|
-
const maxX = Math.max(bbox[0], bbox[2]);
|
|
93
|
-
const minY = Math.min(bbox[1], bbox[3]);
|
|
94
|
-
const maxY = Math.max(bbox[1], bbox[3]);
|
|
95
|
-
|
|
96
|
-
const minXYDeg = this.getLatLon([minX, minY]);
|
|
97
|
-
const maxXYDeg = this.getLatLon([maxX, maxY]);
|
|
98
|
-
|
|
99
|
-
return [minXYDeg[0], minXYDeg[1], maxXYDeg[0], maxXYDeg[1]] as [number, number, number, number];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
getOriginAsLatLon(cog: Tiff) {
|
|
103
|
-
const { origin } = cog.images[cog.images.length - 1];
|
|
104
|
-
return this.getLatLon(origin);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getImageTileIndex(img: TiffImage) {
|
|
108
|
-
const ax = EARTH_HALF_CIRCUMFERENCE + img.origin[0];
|
|
109
|
-
const ay = -(EARTH_HALF_CIRCUMFERENCE + (img.origin[1] - EARTH_CIRCUMFERENCE));
|
|
110
|
-
// let mpt = img.resolution[0] * img.tileSize.width;
|
|
111
|
-
|
|
112
|
-
const mpt = img.tileSize.width * this.getResolutionFromZoomLevel(
|
|
113
|
-
img.tileSize.width,
|
|
114
|
-
this.getZoomLevelFromResolution(
|
|
115
|
-
img.tileSize.width,
|
|
116
|
-
img.resolution[0],
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const ox = Math.round(ax / mpt);
|
|
121
|
-
const oy = Math.round(ay / mpt);
|
|
122
|
-
|
|
123
|
-
const oz = this.getZoomLevelFromResolution(img.tileSize.width, img.resolution[0]);
|
|
124
|
-
|
|
125
|
-
return [ox, oy, oz];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getResolutionFromZoomLevel(tileSize: number, z: number) {
|
|
129
|
-
return (EARTH_CIRCUMFERENCE / tileSize) / (2 ** z);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
getZoomLevelFromResolution(tileSize: number, resolution: number) {
|
|
133
|
-
return Math.round(Math.log2(EARTH_CIRCUMFERENCE / (resolution * tileSize)));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
getLatLon(input: number[]) {
|
|
137
|
-
const ax = EARTH_HALF_CIRCUMFERENCE + input[0];
|
|
138
|
-
const ay = -(EARTH_HALF_CIRCUMFERENCE + (input[1] - EARTH_CIRCUMFERENCE));
|
|
139
|
-
|
|
140
|
-
const cartesianPosition = [
|
|
141
|
-
ax * (512 / EARTH_CIRCUMFERENCE),
|
|
142
|
-
ay * (512 / EARTH_CIRCUMFERENCE),
|
|
143
|
-
];
|
|
144
|
-
const cartographicPosition = worldToLngLat(cartesianPosition);
|
|
145
|
-
const cartographicPositionAdjusted = [cartographicPosition[0], -cartographicPosition[1]];
|
|
146
|
-
|
|
147
|
-
return cartographicPositionAdjusted;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async getTile(x: number, y: number, z: number, bounds:Bounds, meshMaxError: number) {
|
|
151
|
-
const wantedMpp = this.getResolutionFromZoomLevel(this.tileSize, z);
|
|
152
|
-
const img = this.cog.getImageByResolution(wantedMpp);
|
|
153
|
-
// await img.loadGeoTiffTags(1)
|
|
154
|
-
let offset: number[] = [0, 0];
|
|
155
|
-
|
|
156
|
-
if (z === this.zoomRange[0]) {
|
|
157
|
-
offset = this.lowestOriginTileOffset;
|
|
158
|
-
} else {
|
|
159
|
-
const power = 2 ** (z - this.zoomRange[0]);
|
|
160
|
-
offset[0] = Math.floor(this.lowestOriginTileOffset[0] * power);
|
|
161
|
-
offset[1] = Math.floor(this.lowestOriginTileOffset[1] * power);
|
|
162
|
-
}
|
|
163
|
-
const tilesX = img.tileCount.x;
|
|
164
|
-
const tilesY = img.tileCount.y;
|
|
165
|
-
// console.log("------OFFSET IS------ " + offset[0] + " ; " + offset[1])
|
|
166
|
-
|
|
167
|
-
const ox = offset[0];
|
|
168
|
-
const oy = offset[1];
|
|
169
|
-
|
|
170
|
-
// console.log("Asking for " + Math.floor(x - ox) + " : " + Math.floor(y - oy))
|
|
171
|
-
|
|
172
|
-
let decompressed: string;
|
|
173
|
-
let decoded: any;
|
|
174
|
-
|
|
175
|
-
this.options.numOfChannels = Number(img.tags.get(277).value);
|
|
176
|
-
this.options.noDataValue = this.getNoDataValue(img.tags);
|
|
177
|
-
|
|
178
|
-
if (!this.options.format) {
|
|
179
|
-
// More information about TIFF tags: https://www.awaresystems.be/imaging/tiff/tifftags.html
|
|
180
|
-
this.options.format = this.getFormat(
|
|
181
|
-
img.tags.get(339).value as Array<number>,
|
|
182
|
-
img.tags.get(258).value as Array<number>,
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
let bitsPerSample = img.tags.get(258)!.value;
|
|
187
|
-
if (Array.isArray(bitsPerSample)) {
|
|
188
|
-
if (this.options.type === 'terrain') {
|
|
189
|
-
let c = 0;
|
|
190
|
-
bitsPerSample.forEach((sample) => {
|
|
191
|
-
c += sample;
|
|
192
|
-
});
|
|
193
|
-
bitsPerSample = c;
|
|
194
|
-
} else {
|
|
195
|
-
[bitsPerSample] = bitsPerSample;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// const samplesPerPixel = img.tags.get(277)!.value
|
|
200
|
-
// console.log("Samples per pixel:" + samplesPerPixel)
|
|
201
|
-
// console.log("Bits per sample: " + bitsPerSample)
|
|
202
|
-
// console.log("Single channel pixel format: " + bitsPerSample/)
|
|
203
|
-
|
|
204
|
-
if (x - ox >= 0 && y - oy >= 0 && x - ox < tilesX && y - oy < tilesY) {
|
|
205
|
-
// console.log(`getting tile: ${[x - ox, y - oy]}`);
|
|
206
|
-
const tile = await img.getTile((x - ox), (y - oy));
|
|
207
|
-
// console.time("Request to data time: ")
|
|
208
|
-
|
|
209
|
-
switch (img.compression) {
|
|
210
|
-
case 'image/jpeg':
|
|
211
|
-
decoded = jpeg.decode(tile!.bytes, { useTArray: true });
|
|
212
|
-
break;
|
|
213
|
-
case 'application/deflate':
|
|
214
|
-
decoded = await inflate(tile!.bytes);
|
|
215
|
-
break;
|
|
216
|
-
case 'application/lzw':
|
|
217
|
-
decoded = this.lzw.decodeBlock(tile!.bytes.buffer);
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
console.warn(`Unexpected compression method: ${img.compression}`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let decompressedFormatted;
|
|
224
|
-
// bitsPerSample = 8
|
|
225
|
-
|
|
226
|
-
switch (this.options.format) {
|
|
227
|
-
case 'uint8':
|
|
228
|
-
decompressedFormatted = new Uint8Array(decoded.buffer); break;
|
|
229
|
-
case 'uint16':
|
|
230
|
-
decompressedFormatted = new Uint16Array(decoded.buffer); break;
|
|
231
|
-
case 'uint32':
|
|
232
|
-
decompressedFormatted = new Uint32Array(decoded.buffer); break;
|
|
233
|
-
case 'int8':
|
|
234
|
-
decompressedFormatted = new Int8Array(decoded.buffer); break;
|
|
235
|
-
case 'int16':
|
|
236
|
-
decompressedFormatted = new Int16Array(decoded.buffer); break;
|
|
237
|
-
case 'int32':
|
|
238
|
-
decompressedFormatted = new Int32Array(decoded.buffer); break;
|
|
239
|
-
case 'float32':
|
|
240
|
-
decompressedFormatted = new Float32Array(decoded.buffer); break;
|
|
241
|
-
case 'float64':
|
|
242
|
-
decompressedFormatted = new Float64Array(decoded.buffer); break;
|
|
243
|
-
default: decompressedFormatted = null;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// console.log(decompressedFormatted)
|
|
247
|
-
|
|
248
|
-
// const { meshMaxError, bounds, elevationDecoder } = this.options;
|
|
249
|
-
|
|
250
|
-
decompressed = await this.geo.getMap({
|
|
251
|
-
rasters: [decompressedFormatted],
|
|
252
|
-
width: this.tileSize,
|
|
253
|
-
height: this.tileSize,
|
|
254
|
-
bounds,
|
|
255
|
-
}, this.options, meshMaxError);
|
|
256
|
-
|
|
257
|
-
// console.log(decompressed.length)
|
|
258
|
-
|
|
259
|
-
return decompressed;
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
getFormat(sampleFormat: number[]|number, bitsPerSample:number[]|number) {
|
|
265
|
-
// TO DO: what if there are different channels formats
|
|
266
|
-
let uniqueSampleFormat = sampleFormat;
|
|
267
|
-
let uniqueBitsPerSample = bitsPerSample;
|
|
268
|
-
if (Array.isArray(sampleFormat)) { [uniqueSampleFormat] = sampleFormat; }
|
|
269
|
-
if (Array.isArray(bitsPerSample)) { [uniqueBitsPerSample] = bitsPerSample; }
|
|
270
|
-
|
|
271
|
-
let dataType;
|
|
272
|
-
switch (uniqueSampleFormat) {
|
|
273
|
-
case 1: // Unsigned integer
|
|
274
|
-
switch (uniqueBitsPerSample) {
|
|
275
|
-
case 8: dataType = 'uint8'; break;
|
|
276
|
-
case 16: dataType = 'uint16'; break;
|
|
277
|
-
case 32: dataType = 'uint32'; break;
|
|
278
|
-
default: dataType = null;
|
|
279
|
-
}
|
|
280
|
-
break;
|
|
281
|
-
case 2: // Signed integer
|
|
282
|
-
switch (uniqueBitsPerSample) {
|
|
283
|
-
case 8: dataType = 'int8'; break;
|
|
284
|
-
case 16: dataType = 'int16'; break;
|
|
285
|
-
case 32: dataType = 'int32'; break;
|
|
286
|
-
default: dataType = null;
|
|
287
|
-
}
|
|
288
|
-
break;
|
|
289
|
-
case 3: // Floating point
|
|
290
|
-
switch (uniqueBitsPerSample) {
|
|
291
|
-
case 32: dataType = 'float32'; break;
|
|
292
|
-
case 64: dataType = 'float64'; break;
|
|
293
|
-
default: dataType = null;
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
default:
|
|
297
|
-
throw new Error('Unknown data format.');
|
|
298
|
-
}
|
|
299
|
-
// console.log('Data type is: ', dataType)
|
|
300
|
-
return dataType;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
getNoDataValue(tags) {
|
|
304
|
-
if (tags.has(42113)) {
|
|
305
|
-
const noDataValue = tags.get(42113).value;
|
|
306
|
-
if (typeof noDataValue === 'string' || noDataValue instanceof String) {
|
|
307
|
-
const parsedValue = noDataValue.replace(/[\0\s]/g, '');
|
|
308
|
-
return Number(parsedValue);
|
|
309
|
-
}
|
|
310
|
-
return Number.isNaN(Number(noDataValue)) ? undefined : Number(noDataValue);
|
|
311
|
-
}
|
|
312
|
-
return undefined;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export default CogTiles;
|
package/src/cogtiles/lzw.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-mixed-operators */
|
|
2
|
-
/* eslint-disable max-len */
|
|
3
|
-
/* eslint-disable no-bitwise */
|
|
4
|
-
/* eslint-disable no-param-reassign */
|
|
5
|
-
/* eslint-disable no-plusplus */
|
|
6
|
-
/* eslint-disable max-classes-per-file */
|
|
7
|
-
/* eslint 'max-len': [1, { code: 100, comments: 999, ignoreStrings: true, ignoreUrls: true }] */
|
|
8
|
-
|
|
9
|
-
// LITERALLY STOLEN CODE FROM GITHUB
|
|
10
|
-
// NOT MY RESPONSIBILITY
|
|
11
|
-
|
|
12
|
-
function decodeRowAcc(row, stride) {
|
|
13
|
-
let length = row.length - stride;
|
|
14
|
-
let offset = 0;
|
|
15
|
-
do {
|
|
16
|
-
for (let i = stride; i > 0; i--) {
|
|
17
|
-
row[offset + stride] += row[offset];
|
|
18
|
-
offset++;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
length -= stride;
|
|
22
|
-
} while (length > 0);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function decodeRowFloatingPoint(row, stride, bytesPerSample) {
|
|
26
|
-
let index = 0;
|
|
27
|
-
let count = row.length;
|
|
28
|
-
const wc = count / bytesPerSample;
|
|
29
|
-
|
|
30
|
-
while (count > stride) {
|
|
31
|
-
for (let i = stride; i > 0; --i) {
|
|
32
|
-
row[index + stride] += row[index];
|
|
33
|
-
++index;
|
|
34
|
-
}
|
|
35
|
-
count -= stride;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const copy = row.slice();
|
|
39
|
-
for (let i = 0; i < wc; ++i) {
|
|
40
|
-
for (let b = 0; b < bytesPerSample; ++b) {
|
|
41
|
-
row[(bytesPerSample * i) + b] = copy[((bytesPerSample - b - 1) * wc) + i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function applyPredictor(
|
|
47
|
-
block,
|
|
48
|
-
predictor,
|
|
49
|
-
width,
|
|
50
|
-
height,
|
|
51
|
-
bitsPerSample,
|
|
52
|
-
planarConfiguration,
|
|
53
|
-
) {
|
|
54
|
-
if (!predictor || predictor === 1) {
|
|
55
|
-
return block;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < bitsPerSample.length; ++i) {
|
|
59
|
-
if (bitsPerSample[i] % 8 !== 0) {
|
|
60
|
-
throw new Error('When decoding with predictor, only multiple of 8 bits are supported.');
|
|
61
|
-
}
|
|
62
|
-
if (bitsPerSample[i] !== bitsPerSample[0]) {
|
|
63
|
-
throw new Error('When decoding with predictor, all samples must have the same size.');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const bytesPerSample = bitsPerSample[0] / 8;
|
|
68
|
-
const stride = planarConfiguration === 2 ? 1 : bitsPerSample.length;
|
|
69
|
-
|
|
70
|
-
for (let i = 0; i < height; ++i) {
|
|
71
|
-
// Last strip will be truncated if height % stripHeight != 0
|
|
72
|
-
if (i * stride * width * bytesPerSample >= block.byteLength) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
let row;
|
|
76
|
-
if (predictor === 2) { // horizontal prediction
|
|
77
|
-
switch (bitsPerSample[0]) {
|
|
78
|
-
case 8:
|
|
79
|
-
row = new Uint8Array(block, i * stride * width * bytesPerSample, stride * width * bytesPerSample);
|
|
80
|
-
break;
|
|
81
|
-
case 16:
|
|
82
|
-
row = new Uint16Array(block, i * stride * width * bytesPerSample, stride * width * bytesPerSample / 2);
|
|
83
|
-
break;
|
|
84
|
-
case 32:
|
|
85
|
-
row = new Uint32Array(block, i * stride * width * bytesPerSample, stride * width * bytesPerSample / 4);
|
|
86
|
-
break;
|
|
87
|
-
default:
|
|
88
|
-
throw new Error(`Predictor 2 not allowed with ${bitsPerSample[0]} bits per sample.`);
|
|
89
|
-
}
|
|
90
|
-
decodeRowAcc(row, stride, bytesPerSample);
|
|
91
|
-
} else if (predictor === 3) { // horizontal floating point
|
|
92
|
-
row = new Uint8Array(block, i * stride * width * bytesPerSample, stride * width * bytesPerSample);
|
|
93
|
-
decodeRowFloatingPoint(row, stride, bytesPerSample);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return block;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
class BaseDecoder {
|
|
100
|
-
async decode(fileDirectory, buffer) {
|
|
101
|
-
const decoded = await this.decodeBlock(buffer);
|
|
102
|
-
const predictor = fileDirectory.Predictor || 1;
|
|
103
|
-
if (predictor !== 1) {
|
|
104
|
-
const isTiled = !fileDirectory.StripOffsets;
|
|
105
|
-
const tileWidth = isTiled ? fileDirectory.TileWidth : fileDirectory.ImageWidth;
|
|
106
|
-
const tileHeight = isTiled
|
|
107
|
-
? fileDirectory.TileLength
|
|
108
|
-
: (
|
|
109
|
-
fileDirectory.RowsPerStrip || fileDirectory.ImageLength
|
|
110
|
-
);
|
|
111
|
-
return applyPredictor(
|
|
112
|
-
decoded,
|
|
113
|
-
predictor,
|
|
114
|
-
tileWidth,
|
|
115
|
-
tileHeight,
|
|
116
|
-
fileDirectory.BitsPerSample,
|
|
117
|
-
fileDirectory.PlanarConfiguration,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
return decoded;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const MIN_BITS = 9;
|
|
125
|
-
const CLEAR_CODE = 256; // clear code
|
|
126
|
-
const EOI_CODE = 257; // end of information
|
|
127
|
-
const MAX_BYTELENGTH = 12;
|
|
128
|
-
|
|
129
|
-
function getByte(array, position, length) {
|
|
130
|
-
const d = position % 8;
|
|
131
|
-
const a = Math.floor(position / 8);
|
|
132
|
-
const de = 8 - d;
|
|
133
|
-
const ef = (position + length) - ((a + 1) * 8);
|
|
134
|
-
let fg = (8 * (a + 2)) - (position + length);
|
|
135
|
-
const dg = ((a + 2) * 8) - position;
|
|
136
|
-
fg = Math.max(0, fg);
|
|
137
|
-
if (a >= array.length) {
|
|
138
|
-
console.warn('ran off the end of the buffer before finding EOI_CODE (end on input code)');
|
|
139
|
-
return EOI_CODE;
|
|
140
|
-
}
|
|
141
|
-
let chunk1 = array[a] & ((2 ** (8 - d)) - 1);
|
|
142
|
-
chunk1 <<= (length - de);
|
|
143
|
-
let chunks = chunk1;
|
|
144
|
-
if (a + 1 < array.length) {
|
|
145
|
-
let chunk2 = array[a + 1] >>> fg;
|
|
146
|
-
chunk2 <<= Math.max(0, (length - dg));
|
|
147
|
-
chunks += chunk2;
|
|
148
|
-
}
|
|
149
|
-
if (ef > 8 && a + 2 < array.length) {
|
|
150
|
-
const hi = ((a + 3) * 8) - (position + length);
|
|
151
|
-
const chunk3 = array[a + 2] >>> hi;
|
|
152
|
-
chunks += chunk3;
|
|
153
|
-
}
|
|
154
|
-
return chunks;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function appendReversed(dest, source) {
|
|
158
|
-
for (let i = source.length - 1; i >= 0; i--) {
|
|
159
|
-
dest.push(source[i]);
|
|
160
|
-
}
|
|
161
|
-
return dest;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function decompress(input) {
|
|
165
|
-
const dictionaryIndex = new Uint16Array(4093);
|
|
166
|
-
const dictionaryChar = new Uint8Array(4093);
|
|
167
|
-
for (let i = 0; i <= 257; i++) {
|
|
168
|
-
dictionaryIndex[i] = 4096;
|
|
169
|
-
dictionaryChar[i] = i;
|
|
170
|
-
}
|
|
171
|
-
let dictionaryLength = 258;
|
|
172
|
-
let byteLength = MIN_BITS;
|
|
173
|
-
let position = 0;
|
|
174
|
-
|
|
175
|
-
function initDictionary() {
|
|
176
|
-
dictionaryLength = 258;
|
|
177
|
-
byteLength = MIN_BITS;
|
|
178
|
-
}
|
|
179
|
-
function getNext(array) {
|
|
180
|
-
const byte = getByte(array, position, byteLength);
|
|
181
|
-
position += byteLength;
|
|
182
|
-
return byte;
|
|
183
|
-
}
|
|
184
|
-
function addToDictionary(i, c) {
|
|
185
|
-
dictionaryChar[dictionaryLength] = c;
|
|
186
|
-
dictionaryIndex[dictionaryLength] = i;
|
|
187
|
-
dictionaryLength++;
|
|
188
|
-
return dictionaryLength - 1;
|
|
189
|
-
}
|
|
190
|
-
function getDictionaryReversed(n) {
|
|
191
|
-
const rev = [];
|
|
192
|
-
for (let i = n; i !== 4096; i = dictionaryIndex[i]) {
|
|
193
|
-
rev.push(dictionaryChar[i]);
|
|
194
|
-
}
|
|
195
|
-
return rev;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const result = [];
|
|
199
|
-
initDictionary();
|
|
200
|
-
const array = new Uint8Array(input);
|
|
201
|
-
let code = getNext(array);
|
|
202
|
-
let oldCode;
|
|
203
|
-
while (code !== EOI_CODE) {
|
|
204
|
-
if (code === CLEAR_CODE) {
|
|
205
|
-
initDictionary();
|
|
206
|
-
code = getNext(array);
|
|
207
|
-
while (code === CLEAR_CODE) {
|
|
208
|
-
code = getNext(array);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (code === EOI_CODE) {
|
|
212
|
-
break;
|
|
213
|
-
} else if (code > CLEAR_CODE) {
|
|
214
|
-
throw new Error(`corrupted code at scanline ${code}`);
|
|
215
|
-
} else {
|
|
216
|
-
const val = getDictionaryReversed(code);
|
|
217
|
-
appendReversed(result, val);
|
|
218
|
-
oldCode = code;
|
|
219
|
-
}
|
|
220
|
-
} else if (code < dictionaryLength) {
|
|
221
|
-
const val = getDictionaryReversed(code);
|
|
222
|
-
appendReversed(result, val);
|
|
223
|
-
addToDictionary(oldCode, val[val.length - 1]);
|
|
224
|
-
oldCode = code;
|
|
225
|
-
} else {
|
|
226
|
-
const oldVal = getDictionaryReversed(oldCode);
|
|
227
|
-
if (!oldVal) {
|
|
228
|
-
throw new Error(
|
|
229
|
-
`Bogus entry. Not in dictionary,
|
|
230
|
-
${oldCode} / ${dictionaryLength},
|
|
231
|
-
position: ${position}`,
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
appendReversed(result, oldVal);
|
|
235
|
-
result.push(oldVal[oldVal.length - 1]);
|
|
236
|
-
addToDictionary(oldCode, oldVal[oldVal.length - 1]);
|
|
237
|
-
oldCode = code;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (dictionaryLength + 1 >= (2 ** byteLength)) {
|
|
241
|
-
if (byteLength === MAX_BYTELENGTH) {
|
|
242
|
-
oldCode = undefined;
|
|
243
|
-
} else {
|
|
244
|
-
byteLength++;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
code = getNext(array);
|
|
248
|
-
}
|
|
249
|
-
return new Uint8Array(result);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export default class LZWDecoder extends BaseDecoder {
|
|
253
|
-
decodeBlock(buffer) {
|
|
254
|
-
return decompress(buffer, false).buffer;
|
|
255
|
-
}
|
|
256
|
-
}
|
package/src/geoimage/README.md
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# Geoimage
|
|
2
|
-
##### A Javascript library for rendering bitmaps and terrain out of **geoTIFF** files.
|
|
3
|
-
<img src = "/images/example0crop1.png" width = "100%">
|
|
4
|
-
|
|
5
|
-
### Features
|
|
6
|
-
##### Color texture generation
|
|
7
|
-
- Create RGB pictures out of RGB geoTIFF data.
|
|
8
|
-
- Generate pictures out of non-RGB geoTIFF data with different processing options.
|
|
9
|
-
|
|
10
|
-
##### Terrain texture generation
|
|
11
|
-
- Generate heightmaps out of single-channel geoTIFF elevation data.
|
|
12
|
-
- Create tiled mesh layer which represents height values fron geoTIFF without any compression to height PNG.
|
|
13
|
-
- Created mesh is TIN generated by [martini algorithm](https://github.com/mapbox/martini).
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
##### Data visualisation options
|
|
17
|
-
- Color
|
|
18
|
-
- Transparency
|
|
19
|
-
- Heatmap (custom color scale example [here](../cogbitmaplayer/README.md#custom-heatmap-color-scale))
|
|
20
|
-
- Data slice
|
|
21
|
-
- Automatic data range
|
|
22
|
-
- Manual data range
|
|
23
|
-
- Assign color to specific data value (example [here](../cogbitmaplayer/README.md#assigning-color-to-specific-data-value))
|
|
24
|
-
|
|
25
|
-
### Data processing options
|
|
26
|
-
- `useAutoRange : boolean` - set automatic range of color gradient **(default false)**
|
|
27
|
-
- `useDataForOpacity : boolean` - visualise data with opacity of each pixel according to its value **(default false)**
|
|
28
|
-
- `alpha : number` - visualise entire image with specified opacity **(if useDataOpacity is false)**, values 0-100 **(default 100)**
|
|
29
|
-
- `useHeatMap : boolean` - generate data as a color heatmap **(default true)**
|
|
30
|
-
- `useChannel : number | null` - specify a single channel to use; first channel is equal to 1, etc... for RGB(A) imagery leave it to `null` **(default null)**
|
|
31
|
-
- `multiplier : number ` - multiplies each value **(default 1.00)**
|
|
32
|
-
- `clipLow : number | null`- generate only data greater than this **(default null)**
|
|
33
|
-
|
|
34
|
-
- `clipHigh : number | null`- generate only data less than this **(default null)**
|
|
35
|
-
- `clippedColor: chroma.Color` - set color for clipped values when using `clipLow` or `clipHigh`, **(default [0, 0, 0, 0])**
|
|
36
|
-
- `colorScale:chroma.Color[]` - array of colors, supports chroma.js color definition (more below)
|
|
37
|
-
- `colorScaleValueRange: number[]` - set min and max range values or set any array of values to set exact colors to values, **if useAutoRange is false**, **(default [0,255])**
|
|
38
|
-
- `useColorsBasedOnValues: boolean` - assign pixels colors based on defined data values **(default false)**
|
|
39
|
-
- `colorsBasedOnValues : [number, chroma.Color][]` - array of value-color pairs, used **if useColorsBasedOnValues is true**, supports chroma.js color definition such as `'red'`, `[255,0,0]`, `'#FF0000'`, etc.
|
|
40
|
-
- `useColorClasses: boolean` - determines whether pixel colors are assigned based on predefined data classes (intervals) **(default false)**
|
|
41
|
-
- `colorClasses : [chroma.Color, [number, number], [boolean, boolean]?][]` - array of color-interval(-intervalBounds) triples, where the color is defined as chroma.js color; interval is defined as [min, max] array; and optional inteval bound as [boolean, boolean] array (default is [true, false] for all intervals except the last one which is [false, true]; used **if useColorClasses is true**, the values that don't belong to any interval are visualized as `unidentifiedColor`
|
|
42
|
-
- `unidentifiedColor: chroma.Color` - set color for not identified values **if useColorsBasedOnValues or useColorClasses is true**, **(default [0, 0, 0, 0])**
|
|
43
|
-
- `nullColor : chroma.Color` - set color for noData values **(default [0, 0, 0, 0])**
|
|
44
|
-
- `useSingleColor : boolean` - display data values only with single color **(default false)**
|
|
45
|
-
- `color : chroma.Color` - set color when **if useSingleColor is true**, **(default [255, 0, 255, 255])**
|
|
46
|
-
- `blurredTexture : boolean` - define blurring behaviour for textures when zoomed in = magnification filter parameter (`gl.TEXTURE_MAG_FILTER`). Default is `true` for blurry textures (corresponds to `GL.LINEAR`), to not blur textures use `false` (corresponds to `GL.NEAREST`)
|
|
47
|
-
|
|
48
|
-
#### Chroma.Color definition
|
|
49
|
-
Type `chroma.Color` means any color definition that is supported by chroma.js such as `'red'`, `[255,0,0]`, `[255,0,0, 180]`, `'#FF0000'`,
|
|
50
|
-
etc. and [Color Brewer pallete names](https://www.datanovia.com/en/wp-content/uploads/dn-tutorials/ggplot2/figures/0101-rcolorbrewer-palette-rcolorbrewer-palettes-colorblind-friendly-1.png)
|
|
51
|
-
in this format: `chroma.brewer.Greens`
|
|
52
|
-
|
|
53
|
-
#### Additional terrain processing options
|
|
54
|
-
- `terrainMinValue: number` - noData value retrieved from input file's metadata is substitute by this value **(default 0)**
|
|
55
|
-
- `terrainSkirtHeight: number` - defines height of individual tiles edges, so there are no white spaces between individual 3D tiles **(default 100)**
|
|
56
|
-
|
|
57
|
-
[//]: # (- `terrainColor: chroma.Color` - color of terrain model **(default [133, 133, 133, 255])**)
|
|
58
|
-
|
|
59
|
-
- Setting **opacity for terrain layers**: Terrayin layer is ordinary Deck.gl layer instance, so opacity is common prop.
|
|
60
|
-
|
|
61
|
-
### Return options
|
|
62
|
-
**Method returns Image DataUrl**
|
|
63
|
-
|
|
64
|
-
- `getMap(returnFormat : "image" | "terrain", input : string | { width : number, height : number, rasters : any[] }, options?: { opacity : number })`
|
|
65
|
-
|
|
66
|
-
If `returnFormat` = `"image"` - If the input has 3 or 4 color channels, return standard RGB or RGBA image. If the input has 1 channel, data gets processed according to data processing options.
|
|
67
|
-
|
|
68
|
-
If `returnFormat` = `"terrain"` - Ignores all options except `multiplier` and returns [Mapbox Terrain-RGB](https://docs.mapbox.com/data/tilesets/guides/access-elevation-data/#decode-data)
|
|
69
|
-
|
|
70
|
-
### Basic example
|
|
71
|
-
##### Initialize the library
|
|
72
|
-
```typescript
|
|
73
|
-
import GeoImage from 'geoimage';
|
|
74
|
-
|
|
75
|
-
const g = new GeoImage();
|
|
76
|
-
```
|
|
77
|
-
##### Get bitmap
|
|
78
|
-
```typescript
|
|
79
|
-
const bitmap = await g.getMap("image", 'image.tif');
|
|
80
|
-
```
|
|
81
|
-
```typescript
|
|
82
|
-
const bitmap = await g.getMap("image", { width : 512, height : 512, rasters : [[...data]] });
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
##### Get heightmap
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
const heightmap = await g.getMap("terrain", 'image.tif');
|
|
91
|
-
```
|
|
92
|
-
```typescript
|
|
93
|
-
const bitmap = await g.getMap("terrain", { width : 512, height : 512, rasters : [[...data]] });
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Advanced example
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
//Import the library and initiate GeoImage object:
|
|
100
|
-
import GeoImage from 'geoimage';
|
|
101
|
-
|
|
102
|
-
const g = new GeoImage();
|
|
103
|
-
|
|
104
|
-
//Single-channel geotiff as a transparent heatmap with auto-rage:
|
|
105
|
-
g.useAutoRange(true);
|
|
106
|
-
g.useHeatMap(true);
|
|
107
|
-
g.alpha(100);
|
|
108
|
-
const firstImage = await g.getMap("image", 'image.tif');
|
|
109
|
-
|
|
110
|
-
//Single-channel geotiff as a transparent heatmap with manual range in meters:
|
|
111
|
-
g.useAutoRange(false);
|
|
112
|
-
g.useDataRange(0,250); //Blue at 0m, red at 250m
|
|
113
|
-
g.useHeatMap(true);
|
|
114
|
-
g.alpha(80);
|
|
115
|
-
const secondImage = await g.getBitmap("image", 'image.tif');
|
|
116
|
-
|
|
117
|
-
//Single-channel geotiff with data as transparency:
|
|
118
|
-
g.useAutoRange(true);
|
|
119
|
-
g.useHeatMap(false);
|
|
120
|
-
g.useDataForOpacity(true);
|
|
121
|
-
const thirdImage = await g.getBitmap("image", 'image.tif');
|
|
122
|
-
|
|
123
|
-
//Single-channel geotiff with data slice from 350m to 360m in custom color:
|
|
124
|
-
g.clipLow(350); //generate only data between 350m and 360m
|
|
125
|
-
g.clipHigh(360);
|
|
126
|
-
g.useHeatMap(false);
|
|
127
|
-
g.color[0,255,100];
|
|
128
|
-
const fourthImage = await g.getBitmap("image", 'image.tif');
|
|
129
|
-
```
|