From 0fd3321283b9202a93295ee9ddded42ce38bcfca Mon Sep 17 00:00:00 2001 From: Viktor Belomestnov Date: Tue, 19 Sep 2023 09:20:24 +0200 Subject: [PATCH 1/2] feat(tile-converter): select metadata class from EXT_structural_metadata (#2647) --- modules/gltf/src/index.ts | 2 +- .../src/lib/extensions/EXT_mesh_features.ts | 2 + .../lib/extensions/EXT_structural_metadata.ts | 12 ++--- .../gltf-ext-structural-metadata-schema.ts | 2 +- .../helpers/batch-ids-extensions.ts | 28 +----------- .../helpers/geometry-converter.ts | 45 ++----------------- .../helpers/preprocess-3d-tiles.ts | 28 +++++++++--- 7 files changed, 40 insertions(+), 79 deletions(-) diff --git a/modules/gltf/src/index.ts b/modules/gltf/src/index.ts index 3f400ecc65..b1b0a9ebf2 100644 --- a/modules/gltf/src/index.ts +++ b/modules/gltf/src/index.ts @@ -44,7 +44,7 @@ export type { GLTF_EXT_feature_metadata_FeatureIdTextureAccessor } from './lib/types/gltf-json-schema'; -export type {GLTF_EXT_structural_metadata} from './lib/types/gltf-ext-structural-metadata-schema'; +export type {GLTF_EXT_structural_metadata_GLTF} from './lib/types/gltf-ext-structural-metadata-schema'; export type { GLTF_EXT_mesh_features, diff --git a/modules/gltf/src/lib/extensions/EXT_mesh_features.ts b/modules/gltf/src/lib/extensions/EXT_mesh_features.ts index 1b2d5fbc39..39af8f9fa7 100644 --- a/modules/gltf/src/lib/extensions/EXT_mesh_features.ts +++ b/modules/gltf/src/lib/extensions/EXT_mesh_features.ts @@ -1,3 +1,5 @@ +// GLTF EXTENSION: EXT_mesh_features +// https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features /* eslint-disable camelcase */ import type {GLTF, GLTFMeshPrimitive} from '../types/gltf-json-schema'; import {GLTFLoaderOptions} from '../../gltf-loader'; diff --git a/modules/gltf/src/lib/extensions/EXT_structural_metadata.ts b/modules/gltf/src/lib/extensions/EXT_structural_metadata.ts index 039d0a47d3..fa307bf96a 100644 --- a/modules/gltf/src/lib/extensions/EXT_structural_metadata.ts +++ b/modules/gltf/src/lib/extensions/EXT_structural_metadata.ts @@ -1,3 +1,5 @@ +// GLTF EXTENSION: EXT_structural_metadata +// https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata /* eslint-disable camelcase */ import type {BigTypedArray, TypedArray} from '@loaders.gl/schema'; import type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema'; @@ -7,7 +9,7 @@ import type { GLTF_EXT_structural_metadata_Enum, GLTF_EXT_structural_metadata_EnumValue, GLTF_EXT_structural_metadata_PropertyTable, - GLTF_EXT_structural_metadata, + GLTF_EXT_structural_metadata_GLTF, GLTF_EXT_structural_metadata_PropertyTexture, GLTF_EXT_structural_metadata_PropertyTable_Property, GLTF_EXT_structural_metadata_Primitive @@ -100,7 +102,7 @@ export function getPropertyTablePopulated( scenegraph: GLTFScenegraph, propertyTableIndex: number ): GLTF_EXT_structural_metadata_PropertyTable { - const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension( + const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension( EXT_STRUCTURAL_METADATA_NAME ); const propertyTable = extension?.propertyTables?.[propertyTableIndex]; @@ -119,7 +121,7 @@ export function getPropertyTablePopulated( * @param options - loader options. */ function decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void { - const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension( + const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension( EXT_STRUCTURAL_METADATA_NAME ); if (!extension?.schema) { @@ -180,7 +182,7 @@ function processPrimitivePropertyTextures( scenegraph: GLTFScenegraph, propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[], primitive: GLTFMeshPrimitive, - extension: GLTF_EXT_structural_metadata + extension: GLTF_EXT_structural_metadata_GLTF ): void { if (!propertyTextures) { return; @@ -210,7 +212,7 @@ function processPrimitivePropertyTexture( scenegraph: GLTFScenegraph, propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture, primitive: GLTFMeshPrimitive, - extension: GLTF_EXT_structural_metadata + extension: GLTF_EXT_structural_metadata_GLTF ): void { if (!propertyTexture.properties) { return; diff --git a/modules/gltf/src/lib/types/gltf-ext-structural-metadata-schema.ts b/modules/gltf/src/lib/types/gltf-ext-structural-metadata-schema.ts index ab54314c45..f6f373841b 100644 --- a/modules/gltf/src/lib/types/gltf-ext-structural-metadata-schema.ts +++ b/modules/gltf/src/lib/types/gltf-ext-structural-metadata-schema.ts @@ -5,7 +5,7 @@ import {GLTFTextureInfoMetadata} from './gltf-json-schema'; /** * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json */ -export type GLTF_EXT_structural_metadata = { +export type GLTF_EXT_structural_metadata_GLTF = { /** An object defining classes and enums. */ schema?: GLTF_EXT_structural_metadata_Schema; /** A uri to an external schema file. */ diff --git a/modules/tile-converter/src/i3s-converter/helpers/batch-ids-extensions.ts b/modules/tile-converter/src/i3s-converter/helpers/batch-ids-extensions.ts index f4ae09a787..2199b105fe 100644 --- a/modules/tile-converter/src/i3s-converter/helpers/batch-ids-extensions.ts +++ b/modules/tile-converter/src/i3s-converter/helpers/batch-ids-extensions.ts @@ -3,8 +3,7 @@ import type {NumericArray} from '@loaders.gl/loader-utils'; import type { GLTF_EXT_feature_metadata_FeatureIdTexture, GLTF_EXT_feature_metadata_GLTF, - GLTF_EXT_feature_metadata_Primitive, - GLTF_EXT_structural_metadata + GLTF_EXT_feature_metadata_Primitive } from '@loaders.gl/gltf'; import type {GLTF_EXT_mesh_features} from '@loaders.gl/gltf'; @@ -12,7 +11,7 @@ import type {GLTF_EXT_mesh_features} from '@loaders.gl/gltf'; import {TypedArray} from '@math.gl/core'; import {TextureImageProperties} from '../types'; import {emod} from '@loaders.gl/math'; -import {EXT_STRUCTURAL_METADATA, EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf'; +import {EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf'; import {Tiles3DTileContent} from '@loaders.gl/3d-tiles'; /** @@ -75,12 +74,6 @@ export function handleBatchIdsExtensions( ); case EXT_MESH_FEATURES: return handleExtMeshFeaturesExtension(attributes, extensionData as GLTF_EXT_mesh_features); - case EXT_STRUCTURAL_METADATA: - return handleExtStructuralMetadataExtension( - attributes, - extensionData as GLTF_EXT_structural_metadata - ); - default: return []; } @@ -89,23 +82,6 @@ export function handleBatchIdsExtensions( return []; } -function handleExtStructuralMetadataExtension( - attributes: { - [key: string]: GLTFAccessorPostprocessed; - }, - extStructuralMetadata: GLTF_EXT_structural_metadata -): NumericArray { - // Take only first extension object to get batchIds attribute name. - const dataAttributeNames = extStructuralMetadata?.dataAttributeNames; - if (dataAttributeNames?.length) { - // Let's use the first element of the array - // TODO: What to do with others if any? - const batchIdsAttribute = attributes[dataAttributeNames[0]]; - return batchIdsAttribute.value; - } - return []; -} - /** * Getting batchIds from EXT_mesh_features extensions. * @param attributes - gltf accessors diff --git a/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts b/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts index d81f029407..42f49e6722 100644 --- a/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts +++ b/modules/tile-converter/src/i3s-converter/helpers/geometry-converter.ts @@ -1,7 +1,7 @@ import type {FeatureTableJson, Tiles3DTileContent} from '@loaders.gl/3d-tiles'; import type { GLTF_EXT_mesh_features, - GLTF_EXT_structural_metadata, + GLTF_EXT_structural_metadata_GLTF, GLTFAccessorPostprocessed, GLTFMaterialPostprocessed, GLTFNodePostprocessed, @@ -1625,16 +1625,9 @@ export function getPropertyTable( const {extensionName, extension} = getPropertyTableExtension(tileContent); switch (extensionName) { - case EXT_MESH_FEATURES: { - propertyTable = getPropertyTableFromExtMeshFeatures( - extension as GLTF_EXT_mesh_features, - metadataClass - ); - return propertyTable; - } case EXT_STRUCTURAL_METADATA: { propertyTable = getPropertyTableFromExtStructuralMetadata( - extension as GLTF_EXT_structural_metadata, + extension as GLTF_EXT_structural_metadata_GLTF, metadataClass ); return propertyTable; @@ -1660,7 +1653,7 @@ function getPropertyTableExtension(tileContent: Tiles3DTileContent): { extension: | string | GLTF_EXT_feature_metadata_GLTF - | GLTF_EXT_structural_metadata + | GLTF_EXT_structural_metadata_GLTF | GLTF_EXT_mesh_features | null; } { @@ -1759,7 +1752,7 @@ function getPropertyTableFromExtFeatureMetadata( * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly. */ function getPropertyTableFromExtStructuralMetadata( - extension: GLTF_EXT_structural_metadata, + extension: GLTF_EXT_structural_metadata_GLTF, metadataClass?: string ): FeatureTableJson | null { if (extension?.propertyTables) { @@ -1803,33 +1796,3 @@ function getPropertyTableFromExtStructuralMetadata( ); return null; } - -/** - * Handle EXT_mesh_features to get property table - * @param extension - global level of EXT_MESH_FEATURES extension - * @param metadataClass - user selected feature metadata class name - * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly. - */ -function getPropertyTableFromExtMeshFeatures( - extension: GLTF_EXT_mesh_features, - metadataClass?: string -): FeatureTableJson | null { - if (extension?.featureIds) { - const firstFeatureId = extension?.featureIds[0]; - const propertyTableWithData = {}; - - // When firstFeatureId.propertyTable is defined, the property data will be taken from EXT_structural_metadata extension - if (!firstFeatureId.propertyTable) { - console.warn( - 'Should be implemented as we have the tileset with Ext_mesh_features not linked with EXT_structural_metadata extension' - ); - } - - return propertyTableWithData; - } - - console.warn( - "The I3S converter couldn't handle EXT_mesh_features extension: There is no featureIds in the extension." - ); - return null; -} diff --git a/modules/tile-converter/src/i3s-converter/helpers/preprocess-3d-tiles.ts b/modules/tile-converter/src/i3s-converter/helpers/preprocess-3d-tiles.ts index 0b677a2e45..bc4f96216a 100644 --- a/modules/tile-converter/src/i3s-converter/helpers/preprocess-3d-tiles.ts +++ b/modules/tile-converter/src/i3s-converter/helpers/preprocess-3d-tiles.ts @@ -1,6 +1,12 @@ import {Tiles3DTileContent} from '@loaders.gl/3d-tiles'; import {GLTFPrimitiveModeString, PreprocessData} from '../types'; -import {GLTF, GLTFLoader, GLTF_EXT_feature_metadata_GLTF} from '@loaders.gl/gltf'; +import { + EXT_STRUCTURAL_METADATA, + GLTF, + GLTFLoader, + GLTF_EXT_feature_metadata_GLTF, + GLTF_EXT_structural_metadata_GLTF +} from '@loaders.gl/gltf'; import {parse} from '@loaders.gl/core'; import {EXT_FEATURE_METADATA} from '@loaders.gl/gltf'; @@ -81,11 +87,23 @@ const getMeshTypesFromGLTF = (gltfJson: GLTF): Set => { const getMetadataClassesFromGLTF = (gltfJson: GLTF): Set => { const result: Set = new Set(); - const classes = (gltfJson.extensions?.[EXT_FEATURE_METADATA] as GLTF_EXT_feature_metadata_GLTF) - ?.schema?.classes; + // Try to parse from EXT_feature_metadata + const extFeatureMetadataClasses = ( + gltfJson.extensions?.[EXT_FEATURE_METADATA] as GLTF_EXT_feature_metadata_GLTF + )?.schema?.classes; - if (classes) { - for (const classKey of Object.keys(classes)) { + if (extFeatureMetadataClasses) { + for (const classKey of Object.keys(extFeatureMetadataClasses)) { + result.add(classKey); + } + } + + // Try to parse from EXT_structural_metadata + const extStructuralMetadataClasses = ( + gltfJson.extensions?.[EXT_STRUCTURAL_METADATA] as GLTF_EXT_structural_metadata_GLTF + )?.schema?.classes; + if (extStructuralMetadataClasses) { + for (const classKey of Object.keys(extStructuralMetadataClasses)) { result.add(classKey); } } From fef5d929e6f1ec4f682666c5ca68de4a6c2a0881 Mon Sep 17 00:00:00 2001 From: Ib Green Date: Tue, 19 Sep 2023 10:35:16 -0400 Subject: [PATCH 2/2] chore(twkb): Add TWKBLoader tests (#2653) --- .../parquet/src/lib/geo/decode-geo-column.ts | 1 + modules/wkt/src/index.ts | 22 ++++---- modules/wkt/src/lib/parse-twkb.ts | 28 +++------- modules/wkt/src/lib/utils/binary-reader.ts | 2 +- modules/wkt/src/twkb-loader.ts | 8 +-- modules/wkt/test/twkb-loader.spec.ts | 56 ++++++++++++------- modules/wkt/test/wkb-loader.spec.ts | 3 +- 7 files changed, 64 insertions(+), 56 deletions(-) diff --git a/modules/parquet/src/lib/geo/decode-geo-column.ts b/modules/parquet/src/lib/geo/decode-geo-column.ts index 885b8c6de5..def482d5ef 100644 --- a/modules/parquet/src/lib/geo/decode-geo-column.ts +++ b/modules/parquet/src/lib/geo/decode-geo-column.ts @@ -41,6 +41,7 @@ function parseGeometry(geometry: any, columnMetadata: GeoColumnMetadata): Geomet case 'wkb': default: const binaryGeometry = WKBLoader.parseSync?.(geometry); + // @ts-ignore return binaryGeometry ? binaryToGeometry(binaryGeometry) : null; } } diff --git a/modules/wkt/src/index.ts b/modules/wkt/src/index.ts index 3c8269c16c..ca88c9aaae 100644 --- a/modules/wkt/src/index.ts +++ b/modules/wkt/src/index.ts @@ -1,23 +1,25 @@ // loaders.gl, MIT license +export {WKTCRSLoader} from './wkt-crs-loader'; +export {WKTCRSWriter} from './wkt-crs-writer'; + +export {WKTLoader, WKTWorkerLoader} from './wkt-loader'; +export {WKTWriter} from './wkt-writer'; + export {WKBLoader, WKBWorkerLoader} from './wkb-loader'; export {WKBWriter} from './wkb-writer'; -export {TWKBLoader} from './twkb-loader'; -export {TWKBWriter} from './twkb-writer'; - export {HexWKBLoader} from './hex-wkb-loader'; -export {WKTLoader, WKTWorkerLoader} from './wkt-loader'; -export {WKTWriter} from './wkt-writer'; - -export {WKTCRSLoader} from './wkt-crs-loader'; -export {WKTCRSWriter} from './wkt-crs-writer'; +export {TWKBLoader} from './twkb-loader'; +export {TWKBWriter} from './twkb-writer'; // EXPERIMENTAL APIs -export type {WKBHeader} from './lib/parse-wkb-header'; +export {isWKT} from './lib/parse-wkt'; + export {isWKB, parseWKBHeader} from './lib/parse-wkb-header'; +export type {WKBHeader} from './lib/parse-wkb-header'; -export {isWKT} from './lib/parse-wkt'; +export {isTWKB} from './lib/parse-twkb'; export {encodeHex, decodeHex} from './lib/utils/hex-transcoder'; diff --git a/modules/wkt/src/lib/parse-twkb.ts b/modules/wkt/src/lib/parse-twkb.ts index 5c5433428a..adcbfde1c4 100644 --- a/modules/wkt/src/lib/parse-twkb.ts +++ b/modules/wkt/src/lib/parse-twkb.ts @@ -1,7 +1,7 @@ // loaders.gl, MIT license // Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz -import type {BinaryGeometry, Geometry, GeometryCollection} from '@loaders.gl/schema'; +import type {Geometry, GeometryCollection} from '@loaders.gl/schema'; import type {Point, LineString, Polygon} from '@loaders.gl/schema'; import type {MultiPoint, MultiLineString, MultiPolygon} from '@loaders.gl/schema'; import {BinaryReader} from './utils/binary-reader'; @@ -26,14 +26,6 @@ export function isTWKB(arrayBuffer: ArrayBuffer): boolean { return true; } -/** - * Parse a TWKB encoded array buffer - * @param arrayBuffer - */ -export function parseTWKB(arrayBuffer: ArrayBuffer): BinaryGeometry { - throw new Error('not implemented'); -} - /** State passed around between parsing functions, extracted from the header */ type ParseTWKBState = { hasBoundingBox: boolean; @@ -158,7 +150,7 @@ function parsePoint(reader: BinaryReader, context: ParseTWKBState): Point { return {type: 'Point', coordinates: []}; } - return {type: 'Point', coordinates: parsePointCoordinates(reader, context)}; + return {type: 'Point', coordinates: readFirstPoint(reader, context)}; } function parseLineString(reader: BinaryReader, context: ParseTWKBState): LineString { @@ -185,14 +177,12 @@ function parsePolygon(reader: BinaryReader, context: ParseTWKBState): Polygon { const ringCount = reader.readVarInt(); - const polygons: number[][][] = []; - const previousPoint = makePreviousPoint(context); - const exteriorRingCount = reader.readVarInt(); + const exteriorRingLength = reader.readVarInt(); const exteriorRing: number[][] = []; - for (let i = 0; i < exteriorRingCount; i++) { + for (let i = 0; i < exteriorRingLength; i++) { exteriorRing.push(parseNextPoint(reader, context, previousPoint)); } @@ -208,7 +198,7 @@ function parsePolygon(reader: BinaryReader, context: ParseTWKBState): Polygon { polygon.push(interiorRing); } - return {type: 'Polygon', coordinates: polygons}; + return {type: 'Polygon', coordinates: polygon}; } function parseMultiPoint(reader: BinaryReader, context: ParseTWKBState): MultiPoint { @@ -269,14 +259,14 @@ function parseMultiPolygon(reader: BinaryReader, context: ParseTWKBState): Multi exteriorRing.push(parseNextPoint(reader, context, previousPoint)); } - const polygon: number[][][] = [exteriorRing]; + const polygon: number[][][] = exteriorRing ? [exteriorRing] : []; for (let j = 1; j < ringCount; j++) { const interiorRing: number[][] = []; - const interiorRingCount = reader.readVarInt(); + const interiorRingLength = reader.readVarInt(); - for (let k = 0; k < interiorRingCount; k++) { + for (let k = 0; k < interiorRingLength; k++) { interiorRing.push(parseNextPoint(reader, context, previousPoint)); } @@ -330,7 +320,7 @@ function makePreviousPoint(context: ParseTWKBState): number[] { return makePointCoordinates(0, 0, context.hasZ ? 0 : undefined, context.hasM ? 0 : undefined); } -function parsePointCoordinates(reader: BinaryReader, context: ParseTWKBState): number[] { +function readFirstPoint(reader: BinaryReader, context: ParseTWKBState): number[] { const x = zigZagDecode(reader.readVarInt()) / context.precisionFactor; const y = zigZagDecode(reader.readVarInt()) / context.precisionFactor; const z = context.hasZ ? zigZagDecode(reader.readVarInt()) / context.zPrecisionFactor : undefined; diff --git a/modules/wkt/src/lib/utils/binary-reader.ts b/modules/wkt/src/lib/utils/binary-reader.ts index cd41e6e579..94d1a23582 100644 --- a/modules/wkt/src/lib/utils/binary-reader.ts +++ b/modules/wkt/src/lib/utils/binary-reader.ts @@ -60,7 +60,7 @@ export class BinaryReader { let nextByte; do { // TODO - this needs to be accessed via data view? - nextByte = this.arrayBuffer[this.byteOffset + bytesRead]; + nextByte = this.dataView.getUint8(this.byteOffset + bytesRead); result += (nextByte & 0x7f) << (7 * bytesRead); bytesRead++; } while (nextByte >= 0x80); diff --git a/modules/wkt/src/twkb-loader.ts b/modules/wkt/src/twkb-loader.ts index 2f17422a4e..8ed973fa99 100644 --- a/modules/wkt/src/twkb-loader.ts +++ b/modules/wkt/src/twkb-loader.ts @@ -3,7 +3,7 @@ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils'; import {BinaryGeometry, Geometry} from '@loaders.gl/schema'; import {VERSION} from './lib/utils/version'; -import {parseTWKB, isTWKB} from './lib/parse-twkb'; +import {parseTWKBGeometry, isTWKB} from './lib/parse-twkb'; export type WKBLoaderOptions = LoaderOptions & { wkb?: { @@ -14,7 +14,7 @@ export type WKBLoaderOptions = LoaderOptions & { /** * Worker loader for WKB (Well-Known Binary) */ -export const TWKBWorkerLoader: Loader = { +export const TWKBWorkerLoader: Loader = { name: 'TWKB (Tiny Well-Known Binary)', id: 'twkb', module: 'wkt', @@ -37,6 +37,6 @@ export const TWKBWorkerLoader: Loader = { ...TWKBWorkerLoader, - parse: async (arrayBuffer: ArrayBuffer) => parseTWKB(arrayBuffer), - parseSync: parseTWKB + parse: async (arrayBuffer: ArrayBuffer) => parseTWKBGeometry(arrayBuffer), + parseSync: parseTWKBGeometry }; diff --git a/modules/wkt/test/twkb-loader.spec.ts b/modules/wkt/test/twkb-loader.spec.ts index 7f2d19c16d..a5106c7e94 100644 --- a/modules/wkt/test/twkb-loader.spec.ts +++ b/modules/wkt/test/twkb-loader.spec.ts @@ -1,40 +1,56 @@ -/** - * import test from 'tape-promise/tape'; +import test from 'tape-promise/tape'; import {fetchFile, parseSync} from '@loaders.gl/core'; -import {WKBLoader} from '@loaders.gl/wkt'; +import {TWKBLoader, isTWKB} from '@loaders.gl/wkt'; import {parseTestCases} from './utils/parse-test-cases'; -import {isWKB} from '../src/lib/parse-wkb-header'; const WKB_2D_TEST_CASES = '@loaders.gl/wkt/test/data/wkb-testdata2d.json'; -const WKB_Z_TEST_CASES = '@loaders.gl/wkt/test/data/wkb-testdataZ.json'; +// const WKB_Z_TEST_CASES = '@loaders.gl/wkt/test/data/wkb-testdataZ.json'; -test.only('WKBLoader#2D', async (t) => { +test('TWKBLoader#2D', async (t) => { const response = await fetchFile(WKB_2D_TEST_CASES); const TEST_CASES = parseTestCases(await response.json()); // TODO parseWKB outputs TypedArrays; testCase contains regular arrays for (const testCase of Object.values(TEST_CASES)) { + if (testCase.geoJSON.type === 'GeometryCollection') { + continue; + } + // Big endian if (testCase.twkb && testCase.binary) { - t.ok(isWKB(testCase.twkb), 'isWKB(2D)'); - t.deepEqual(parseSync(testCase.twkb, WKBLoader), testCase.binary); + t.ok(isTWKB(testCase.twkb), 'isTWKB(2D)'); + const geometry = {...testCase.geoJSON}; + // TODO - Weird empty geometry case, is that coorrect per spec? + if ( + geometry.coordinates.length === 1 && + // @ts-ignore + geometry.coordinates[0].length === 1 && + // @ts-ignore + geometry.coordinates[0][0].length === 0 + ) { + geometry.coordinates = []; + } + t.deepEqual(parseSync(testCase.twkb, TWKBLoader), geometry); } } t.end(); }); -test('WKBLoader#Z', async (t) => { - const response = await fetchFile(WKB_Z_TEST_CASES); - const TEST_CASES = parseTestCases(await response.json()); +// test('TWKBLoader#Z', async (t) => { +// const response = await fetchFile(WKB_Z_TEST_CASES); +// const TEST_CASES = parseTestCases(await response.json()); - // TODO parseWKB outputs TypedArrays; testCase contains regular arrays - for (const testCase of Object.values(TEST_CASES)) { - if (testCase.wkbXdr && testCase.binary && testCase.geoJSON) { - t.deepEqual(parseSync(testCase.wkbXdr, WKBLoader, {wkb: {shape: 'geometry'}}), testCase.geoJSON); - } - } +// // TODO parseWKB outputs TypedArrays; testCase contains regular arrays +// for (const testCase of Object.values(TEST_CASES)) { +// if (testCase.geoJSON.type === 'GeometryCollection') { +// continue; +// } - t.end(); -}); -*/ +// if (testCase.wkbXdr && testCase.binary && testCase.geoJSON) { +// t.deepEqual(parseSync(testCase.twkbXdr, TWKBLoader, {wkb: {shape: 'geometry'}}), testCase.geoJSON); +// } +// } + +// t.end(); +// }); diff --git a/modules/wkt/test/wkb-loader.spec.ts b/modules/wkt/test/wkb-loader.spec.ts index 228ae56799..65fa6b3a93 100644 --- a/modules/wkt/test/wkb-loader.spec.ts +++ b/modules/wkt/test/wkb-loader.spec.ts @@ -1,8 +1,7 @@ import test from 'tape-promise/tape'; import {fetchFile, parseSync} from '@loaders.gl/core'; -import {WKBLoader} from '@loaders.gl/wkt'; +import {WKBLoader, isWKB} from '@loaders.gl/wkt'; import {parseTestCases} from './utils/parse-test-cases'; -import {isWKB} from '../src/lib/parse-wkb-header'; const WKB_2D_TEST_CASES = '@loaders.gl/wkt/test/data/wkb-testdata2d.json'; const WKB_Z_TEST_CASES = '@loaders.gl/wkt/test/data/wkb-testdataZ.json';