-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CARTO: Support gzip compression in RasterLayer (#9352)
- Loading branch information
1 parent
622f328
commit 9f44a6c
Showing
13 changed files
with
193 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
import {GZipCompression} from '@loaders.gl/compression'; | ||
|
||
type ReadPackedOptions = { | ||
compression: null | 'gzip'; | ||
}; | ||
|
||
// Optimized (100X speed improvement) reading function for binary data | ||
export function readPackedTypedArray(TypedArray, pbf, obj) { | ||
export function readPackedTypedArray(TypedArray, pbf, obj, options?: ReadPackedOptions) { | ||
const end = pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1; | ||
obj.value = new TypedArray(pbf.buf.buffer.slice(pbf.pos, end)); | ||
const data = pbf.buf.buffer.slice(pbf.pos, end); | ||
|
||
if (options?.compression === 'gzip') { | ||
const compression = new GZipCompression(); | ||
const decompressedData = compression.decompressSync(data); | ||
obj.value = new TypedArray(decompressedData); | ||
} else { | ||
obj.value = new TypedArray(data); | ||
} | ||
|
||
pbf.pos = end; | ||
return obj.value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/modules/carto/layers/schema/carto-properties-tile-loader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import test from 'tape-promise/tape'; | ||
import CartoPropertiesTileLoader from '@deck.gl/carto/layers/schema/carto-properties-tile-loader'; | ||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
|
||
test('CartoPropertiesTileLoader', t => { | ||
const loader = CartoPropertiesTileLoader as LoaderWithParser; | ||
|
||
t.ok(loader, 'CartoPropertiesTileLoader should be defined'); | ||
t.equals(loader.name, 'CARTO Properties Tile', 'Should have correct name'); | ||
t.equals(typeof loader.parse, 'function', 'Should have parse method'); | ||
t.equals(typeof loader.parseSync, 'function', 'Should have parseSync method'); | ||
t.equals(loader.worker, true, 'worker property should be true'); | ||
t.end(); | ||
}); |
39 changes: 39 additions & 0 deletions
39
test/modules/carto/layers/schema/carto-raster-tile-loader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import test from 'tape-promise/tape'; | ||
import CartoRasterTileLoader from '@deck.gl/carto/layers/schema/carto-raster-tile-loader'; | ||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
import {BAND, COMPRESSED_BAND, TEST_DATA} from './carto-raster-tile.spec'; | ||
|
||
test('CartoRasterTileLoader', t => { | ||
const loader = CartoRasterTileLoader as LoaderWithParser; | ||
|
||
t.ok(loader, 'CartoRasterTileLoader should be defined'); | ||
t.equals(loader.name, 'CARTO Raster Tile', 'Should have correct name'); | ||
t.equals(typeof loader.parse, 'function', 'Should have parse method'); | ||
t.equals(typeof loader.parseSync, 'function', 'Should have parseSync method'); | ||
t.equals(CartoRasterTileLoader.worker, true, 'worker property should be true'); | ||
|
||
const result = loader.parseSync!(TEST_DATA, {cartoRasterTile: {metadata: {compression: null}}}); | ||
t.equals(result.blockSize, 256, 'Should return correct blockSize'); | ||
t.ok(result.cells, 'Should return cells'); | ||
t.ok(result.cells.numericProps, 'Should return numericProps'); | ||
t.deepEqual( | ||
result.cells.numericProps.band1.value, | ||
COMPRESSED_BAND, | ||
'Should return compressed band' | ||
); | ||
|
||
// Repeat with compressed data | ||
const result2 = loader.parseSync!(TEST_DATA, { | ||
cartoRasterTile: {metadata: {compression: 'gzip'}} | ||
}); | ||
t.equals(result2.blockSize, 256, 'Should return correct blockSize'); | ||
t.ok(result2.cells, 'Should return cells'); | ||
t.ok(result2.cells.numericProps, 'Should return numericProps'); | ||
t.deepEqual(result2.cells.numericProps.band1.value, BAND, 'Should return uncompressed band'); | ||
|
||
t.end(); | ||
}); |
55 changes: 55 additions & 0 deletions
55
test/modules/carto/layers/schema/carto-raster-tile.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import test from 'tape-promise/tape'; | ||
import {TileReader} from '@deck.gl/carto/layers/schema/carto-raster-tile'; | ||
import Pbf from 'pbf'; | ||
|
||
// GZIP compressed data for [1, 2, 3, 4] | ||
export const BAND = [1, 2, 3, 4]; | ||
export const COMPRESSED_BAND = [ | ||
31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 99, 100, 98, 102, 1, 0, 205, 251, 60, 182, 4, 0, 0, 0 | ||
]; | ||
const buffer = new Pbf(); | ||
buffer.writeVarintField(1, 256); // blockSize | ||
buffer.writeMessage(2, (_, pbf) => { | ||
// bands | ||
pbf.writeStringField(1, 'band1'); | ||
pbf.writeStringField(2, 'uint8'); | ||
pbf.writeBytesField(3, new Uint8Array(COMPRESSED_BAND)); | ||
}); | ||
export const TEST_DATA = buffer.finish(); | ||
|
||
/** | ||
* syntax = "proto3"; | ||
* package carto; | ||
* | ||
* message Band { | ||
* string name = 1; | ||
* string type = 2; | ||
* bytes data = 3; | ||
* } | ||
* | ||
* message Tile { | ||
* uint32 blockSize = 1; | ||
* repeated Band bands = 2; | ||
* } | ||
*/ | ||
test('TileReader', t => { | ||
const tile = TileReader.read(new Pbf(TEST_DATA), TEST_DATA.byteLength); | ||
t.equals(tile.blockSize, 256, 'Should read blockSize correctly'); | ||
t.equals(tile.bands.length, 1, 'Should have one band'); | ||
t.equals(tile.bands[0].name, 'band1', 'Band should have correct name'); | ||
t.deepEqual(tile.bands[0].data.value, COMPRESSED_BAND, 'Band should have compressed data'); | ||
|
||
// Repeat with compressed data | ||
TileReader.compression = 'gzip'; | ||
const tile2 = TileReader.read(new Pbf(TEST_DATA), TEST_DATA.byteLength); | ||
t.equals(tile.blockSize, 256, 'Should read blockSize correctly'); | ||
t.equals(tile.bands.length, 1, 'Should have one band'); | ||
t.equals(tile.bands[0].name, 'band1', 'Band should have correct name'); | ||
t.deepEqual(tile2.bands[0].data.value, BAND, 'Band should have decompressed data'); | ||
|
||
t.end(); | ||
}); |
18 changes: 18 additions & 0 deletions
18
test/modules/carto/layers/schema/carto-spatial-tile-loader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import test from 'tape-promise/tape'; | ||
import CartoSpatialTileLoader from '@deck.gl/carto/layers/schema/carto-spatial-tile-loader'; | ||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
|
||
test('CartoSpatialTileLoader', t => { | ||
const loader = CartoSpatialTileLoader as LoaderWithParser; | ||
|
||
t.ok(loader, 'CartoSpatialTileLoader should be defined'); | ||
t.equals(loader.name, 'CARTO Spatial Tile', 'Should have correct name'); | ||
t.equals(typeof loader.parse, 'function', 'Should have parse method'); | ||
t.equals(typeof loader.parseSync, 'function', 'Should have parseSync method'); | ||
t.equals(loader.worker, true, 'worker property should be true'); | ||
t.end(); | ||
}); |
18 changes: 18 additions & 0 deletions
18
test/modules/carto/layers/schema/carto-vector-tile-loader.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import test from 'tape-promise/tape'; | ||
import CartoVectorTileLoader from '@deck.gl/carto/layers/schema/carto-vector-tile-loader'; | ||
import type {LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
|
||
test('CartoVectorTileLoader', t => { | ||
const loader = CartoVectorTileLoader as LoaderWithParser; | ||
|
||
t.ok(loader, 'CartoVectorTileLoader should be defined'); | ||
t.equals(loader.name, 'CARTO Vector Tile', 'Should have correct name'); | ||
t.equals(typeof loader.parse, 'function', 'Should have parse method'); | ||
t.equals(typeof loader.parseSync, 'function', 'Should have parseSync method'); | ||
t.equals(loader.worker, true, 'worker property should be true'); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters