Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix: improve pmtile vector tile type detection (#3415)

Igor Dykhta00883b190a7f
diff --git a/src/table/src/tileset/vector-tile-utils.spec.ts b/src/table/src/tileset/vector-tile-utils.spec.ts
index 06c1e2422..f9a659dff 100644
--- a/src/table/src/tileset/vector-tile-utils.spec.ts
+++ b/src/table/src/tileset/vector-tile-utils.spec.ts
@@ -6,7 +6,11 @@ import {DATA_TYPES} from 'type-analyzer';
import {ALL_FIELD_TYPES, FILTER_TYPES} from '@kepler.gl/constants';
import {getTileUrl, getMetaUrl, parseVectorMetadata as parseMetadata} from './vector-tile-utils';
-import {PMTILES_METADATA, MVT_METADATA} from '../../../../test/fixtures/tile-metadata';
+import {
+ PMTILES_METADATA,
+ PMTILES_METADATA_NUMERIC_TYPES,
+ MVT_METADATA
+} from '../../../../test/fixtures/tile-metadata';
describe('getTileUrl', () => {
[
@@ -161,6 +165,86 @@ test('parseMetadata, PMTiles from PMTileSource', () => {
});
});
+test('parseMetadata, PMTiles with numeric type aliases (float64, int32, uint64, bool)', () => {
+ const result = parseMetadata(PMTILES_METADATA_NUMERIC_TYPES, {
+ tileUrl: 'https://example.com/numeric_types.pmtiles'
+ });
+
+ expect(result).toEqual({
+ attributions: [],
+ name: 'Numeric Types Tiles',
+ description: 'Tiles with various numeric type aliases',
+ metaJson: null,
+ bounds: [-180, -90, 180, 90],
+ center: [0, 0, 3],
+ maxZoom: 10,
+ minZoom: 0,
+ fields: [
+ {
+ id: 'score',
+ name: 'score',
+ format: '',
+ type: ALL_FIELD_TYPES.real,
+ analyzerType: DATA_TYPES.FLOAT,
+ filterProps: {
+ domain: [0, 100],
+ value: [0, 100],
+ type: FILTER_TYPES.range,
+ typeOptions: [FILTER_TYPES.range],
+ gpu: true,
+ step: 0.01
+ }
+ },
+ {
+ id: 'count',
+ name: 'count',
+ format: '',
+ type: ALL_FIELD_TYPES.integer,
+ analyzerType: DATA_TYPES.INT,
+ filterProps: {
+ domain: [1, 999],
+ value: [1, 999],
+ type: FILTER_TYPES.range,
+ typeOptions: [FILTER_TYPES.range],
+ gpu: true,
+ step: 1
+ }
+ },
+ {
+ id: 'big_id',
+ name: 'big_id',
+ format: '',
+ type: ALL_FIELD_TYPES.integer,
+ analyzerType: DATA_TYPES.INT,
+ filterProps: {
+ domain: [0, 1000000],
+ value: [0, 1000000],
+ type: FILTER_TYPES.range,
+ typeOptions: [FILTER_TYPES.range],
+ gpu: true,
+ step: 1
+ }
+ },
+ {
+ id: 'active',
+ name: 'active',
+ format: '',
+ type: ALL_FIELD_TYPES.boolean,
+ analyzerType: DATA_TYPES.BOOLEAN,
+ filterProps: {
+ domain: [0, 1],
+ value: [0, 1],
+ type: FILTER_TYPES.range,
+ typeOptions: [FILTER_TYPES.range],
+ gpu: true,
+ step: 1
+ }
+ }
+ ],
+ pmtilesType: 'mvt'
+ });
+});
+
test('parseMetadata, empty input', () => {
expect(parseMetadata({})).toEqual({
attributions: [],
diff --git a/src/table/src/tileset/vector-tile-utils.ts b/src/table/src/tileset/vector-tile-utils.ts
index d570254c1..9550362f3 100644
--- a/src/table/src/tileset/vector-tile-utils.ts
+++ b/src/table/src/tileset/vector-tile-utils.ts
@@ -354,12 +354,24 @@ function getTimeAnimationDomain(mappedValue: number[]): {
return {domain, timeSteps, duration: clamped, mappedValue};
}
-const pmTileTypeToAttrMap = {
+const pmTileTypeToAttrMap: Record<string, string> = {
float32: 'number',
+ float64: 'number',
+ float: 'number',
+ number: 'number',
+ numeric: 'number',
string: 'string',
utf8: 'string',
int: 'int',
- boolean: 'boolean'
+ int32: 'int',
+ int64: 'int',
+ int4: 'int',
+ uint8: 'int',
+ uint16: 'int',
+ uint32: 'int',
+ uint64: 'int',
+ boolean: 'boolean',
+ bool: 'boolean'
};
/**
@@ -372,9 +384,10 @@ function pmTilesLayerToTippecanoeLayer(layers: TileJSON['layers']): TippecanoeLa
for (const layer of layers) {
const {fields = []} = layer || {};
for (const pmField of fields) {
+ const mappedType = pmTileTypeToAttrMap[pmField.type];
const attribute = {
attribute: pmField.name,
- type: pmTileTypeToAttrMap[pmField.type],
+ type: mappedType || pmField.type || 'string',
count: pmField.uniqueValueCount,
values: (pmField.values ?? []) as number[] | string[],
min: pmField.min,
@@ -738,8 +751,8 @@ export const getFieldsFromTile = async ({
metadata.fields = updatedFields;
}
- } catch {
- // ignore, as this is experimental fallback
+ } catch (err) {
+ // field extraction from tile is best-effort
}
};
diff --git a/test/fixtures/tile-metadata.ts b/test/fixtures/tile-metadata.ts
index 718a62418..8ceb2d45c 100644
--- a/test/fixtures/tile-metadata.ts
+++ b/test/fixtures/tile-metadata.ts
@@ -84,3 +84,74 @@ export const PMTILES_METADATA = {
]
}
};
+
+export const PMTILES_METADATA_NUMERIC_TYPES = {
+ name: 'Numeric Types Tiles',
+ format: 'pmtiles' as const,
+ formatVersion: 3,
+ attributions: [],
+ tileMIMEType: 'application/vnd.mapbox-vector-tile' as const,
+ minZoom: 0,
+ maxZoom: 10,
+ boundingBox: [
+ [-180, -90],
+ [180, 90]
+ ] as [[number, number], [number, number]],
+ center: [0, 0],
+ centerZoom: 3,
+ tilejson: {
+ name: 'Numeric Types Tiles',
+ description: 'Tiles with various numeric type aliases',
+ generator: 'tippecanoe v2.37.1',
+ generatorOptions: '',
+ boundingBox: [
+ [-180, -90],
+ [180, 90]
+ ],
+ center: null,
+ maxZoom: null,
+ minZoom: null,
+ layers: [
+ {
+ name: 'test_layer',
+ id: 'test_layer',
+ description: '',
+ minzoom: 0,
+ maxzoom: 10,
+ dominantGeometry: 'Point',
+ fields: [
+ {
+ name: 'score',
+ type: 'float64',
+ min: 0,
+ max: 100,
+ uniqueValueCount: 50,
+ values: [0, 100]
+ },
+ {
+ name: 'count',
+ type: 'int32',
+ min: 1,
+ max: 999,
+ uniqueValueCount: 100,
+ values: [1, 999]
+ },
+ {
+ name: 'big_id',
+ type: 'uint64',
+ min: 0,
+ max: 1000000,
+ uniqueValueCount: 500,
+ values: [0, 1000000]
+ },
+ {
+ name: 'active',
+ type: 'bool',
+ uniqueValueCount: 2,
+ values: [0, 1]
+ }
+ ]
+ }
+ ]
+ }
+};