3D Tiles批处理表(Batch Table)数据格式标准规范

导航


引

官网文档

概述

批处理表是瓦片二进制体的一个组成部分,包含瓦片中每个要素的应用程序特定属性。在运行时查询这些属性以声明样式和任何应用程序特定的用法,例如填充 UI 或发出 REST API 请求。一些示例批处理表属性是建筑物高度,地理坐标和数据库主键。

批处理表用于以下数据格式:


文件结构

批处理表由两部分组成:JSON 头和可选的小端字节序二进制主体。JSON 描述了属性,这些属性的值可以直接在 JSON 中定义为数组,也可以引用二进制主体中的部分。将长数字数组存储在二进制体中的效率更高。下图显示了批处理表布局:

当瓦片数据包含批处理表时,批处理表将紧随瓦片的要素表之后。文件头还将包含 batchTableJSONByteLength 和 batchTableBinaryByteLength 的 uint32 字段,可用于提取批处理表的各个部分。


结构填充

JSON 头必须以 8 个字节为界结束,否则,在 JSON 头尾部填充空格(0x20)以满足此要求。

二进制体必须以 8 个字节为界开始和结束。为了满足此要求,可以用任意值填充空白部分。

二进制属性必须以一个字节偏移量开始,该字节偏移量是必须是属性隐含类型大小的倍数。例如,组件的某个元素有 4 个字节长度的属性 FLOAT ,因此必须以 4 的倍数计算偏移量。为了满足此要求,可以用任意值填充空白部分。


JSON 头

批处理表值可以两种不同的方式在 JSON 标头中表示:

  1. 值的数组,例如,"name" : ['name1', 'name2', 'name3']或"height" : [10.0, 20.0, 15.0]。

    • 数组元素可以是任何有效的 JSON 数据类型,包括对象和数组。元素可能是null。

    • 每个数组的长度等于 batchLength,以每种数据格式指定。这是数据中要素的数量。例如,batchLength 可以是 b3dm 数据中的模型数,i3dm 数据中的实例数,或 pnts 数据中的点数(或对象数)。

  2. 引用数据的二进制体,通过byteOffset表示对象,componentType 和 type 属性,例如,"height" : { "byteOffset" : 24, "componentType" : "FLOAT", "type" : "SCALAR"}。

    • byteOffset 指定相对于二进制主体从零开始的偏移量。 byteOffset 的值必须是该属性componentType字节大小的倍数 ,例如,属性具有组件类型 FLOAT 的 byteOffset 的值必须是4的倍数。
    • componentType 是组件特定的数据类型。允许的值是"BYTE","UNSIGNED_BYTE","SHORT","UNSIGNED_SHORT","INT","UNSIGNED_INT","FLOAT",和"DOUBLE"。
    • type 指定属性是标量还是向量。允许的值是"SCALAR","VEC2","VEC3",和"VEC4"。

批处理表 JSON 是 UTF-8 的 JSON 字符串。

注意:在 JavaScript 中,可以使用ArrayBuffer的TextDecoderJavaScript API 来提取 Batch Table JSON,并使用JSON.parse转换为 JavaScript 对象。

batchId用于访问每个数组中的元素并提取相应的属性。例如,以下批处理表有两个要素的一批属性:

{
  "id": ["unique id", "another unique id"],
  "displayName": ["Building name", "Another building name"],
  "yearBuilt": [1999, 2015],
  "address": [
    { "street": "Main Street", "houseNumber": "1" },
    { "street": "Main Street", "houseNumber": "2" }
  ]
}

要素batchId = 0的属性是:

id[0] = 'unique id'
displayName[0] = 'Building name'
yearBuilt[0] = 1999
address[0] = { street: 'Main Street', houseNumber: '1' }

要素batchId = 1的属性是:

id[1] = 'another unique id'
displayName[1] = 'Another building name'
yearBuilt[1] = 2015
address[1] = { street: 'Main Street', houseNumber: '2' }

完整的 JSON 头定义,详见属性参考。以下是一个完整的 JSON 格式。

JSON:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "id": "batchTable.schema.json",
  "title": "Batch Table",
  "type": "object",
  "description": "A set of properties defining application-specific metadata for features in a tile.",
  "properties": {
    "extensions": {
      "$ref": "extension.schema.json"
    },
    "extras": {
      "$ref": "extras.schema.json"
    }
  },
  "additionalProperties": {
    "$ref": "#/definitions/property"
  },
  "definitions": {
    "binaryBodyReference": {
      "title": "BinaryBodyReference",
      "type": "object",
      "description": "An object defining the reference to a section of the binary body of the batch table where the property values are stored if not defined directly in the JSON.",
      "properties": {
        "byteOffset": {
          "type": "number",
          "description": "The offset into the buffer in bytes.",
          "minimum": 0
        },
        "componentType": {
          "type": "string",
          "description": "The datatype of components in the property.",
          "enum": [
            "BYTE",
            "UNSIGNED_BYTE",
            "SHORT",
            "UNSIGNED_SHORT",
            "INT",
            "UNSIGNED_INT",
            "FLOAT",
            "DOUBLE"
          ]
        },
        "type": {
          "type": "string",
          "description": "Specifies if the property is a scalar or vector.",
          "enum": ["SCALAR", "VEC2", "VEC3", "VEC4"]
        }
      },
      "required": ["byteOffset", "componentType", "type"]
    },
    "property": {
      "title": "Property",
      "description": "A user-defined property which specifies per-feature application-specific metadata in a tile. Values either can be defined directly in the JSON as an array, or can refer to sections in the binary body with a `BinaryBodyReference` object.",
      "oneOf": [
        { "$ref": "#/definitions/binaryBodyReference" },
        { "type": "array" }
      ]
    }
  }
}

二进制体

当 JSON 头包含对二进制部分的引用时,所提供的 byteOffset 用于索引数据,如下图所示:

可以使用要素长度来数据值batchLength;所需的批量表 IDbatchId; componentType 和 type 定义在 JSON 头中。

下表可用于计算属性的字节大小。

componentType 字节大小
"BYTE" 1
"UNSIGNED_BYTE" 1
"SHORT" 2
"UNSIGNED_SHORT" 2
"INT" 4
"UNSIGNED_INT" 4
"FLOAT" 4
"DOUBLE" 8

type 部件数
"SCALAR" 1
"VEC2" 2
"VEC3" 3
"VEC4" 4

扩展

以下扩展可以应用于批处理表。

3DTILES_batch_table_hierarchy


实例

本节是非规范性的

以下示例访问批处理表 JSON 的"height"和"geographic"的值batchLength的长度是 10:

{
  "height": {
    "byteOffset": 0,
    "componentType": "FLOAT",
    "type": "SCALAR"
  },
  "geographic": {
    "byteOffset": 40,
    "componentType": "DOUBLE",
    "type": "VEC3"
  }
}

获得"height"的值:

var height = batchTableJSON.height
var byteOffset = height.byteOffset
var componentType = height.componentType
var type = height.type

var heightArrayByteLength =
  batchLength * sizeInBytes(componentType) * numberOfComponents(type) // 10 * 4 * 1
var heightArray = new Float32Array(
  batchTableBinary.buffer,
  byteOffset,
  heightArrayByteLength
)
var heightOfFeature = heightArray[batchId]

获得"geographic"的值:

var geographic = batchTableJSON.geographic
var byteOffset = geographic.byteOffset
var componentType = geographic.componentType
var type = geographic.type
var componentSizeInBytes = sizeInBytes(componentType)
var numberOfComponents = numberOfComponents(type)

var geographicArrayByteLength =
  batchLength * componentSizeInBytes * numberOfComponents // 10 * 8 * 3
var geographicArray = new Float64Array(
  batchTableBinary.buffer,
  byteOffset,
  geographicArrayByteLength
)
var geographicOfFeature = positionArray.subarray(
  batchId * numberOfComponents,
  batchId * numberOfComponents + numberOfComponents
) // Using subarray creates a view into the array, and not a new array.

CesiumJS 的 3D Tiles 实现了读取批量表的功能,Cesium3DTileBatchTable.js。


属性参考

批处理表
二进制体引用
属性


批处理表

一组属性,用于定义数据中要素的应用程序特定元数据。

类型 描述 是否必须
extensions object 特定扩展对象的字典对象 No
extras any 应用程序的特定数据 No

允许其他属性。


二进制体引用

一个对象,用于定义对要素表的二进制主体部分的引用,如果未在 JSON 头中直接定义属性值,则在该部分存储。

类型 描述 是否必须
byteOffset number 缓冲区的偏移量(以字节为单位) ✅ Yes
componentType string 属性所属部分的数据类型 ✅ Yes
type string 指定属性是标量还是向量 ✅ Yes

允许其他属性。


属性

用户定义的属性,用于在数据中指定每个功能的特定于应用程序的元数据。值可以直接在 JSON 中定义为数组,也可以使用 二进制体引用 对象引用二进制主体中的部分。

JSON 参考,见上面。



版权声明:
除非注明,本博文章均为原创,转载请以链接形式标明本文地址。



赏

   转载规则


《3D Tiles批处理表(Batch Table)数据格式标准规范》 由 Jackie Tang(唐浩桀) 采用 知识共享署名 4.0 国际许可协议 进行许可。
 上一篇
3D Tiles样式数据格式标准规范 3D Tiles样式数据格式标准规范
导航 引 概述 概念 要素样式 条件表达式 定义变量 元属性 表达式 语法 运算符 数据类型 Number String vec Color RegExp 运算规则 类型转换 字符转换 常量 变量 内置函数 特殊说明 点云 文件
下一篇 
3D Tiles要素表(Feature Table)数据格式标准规范 3D Tiles要素表(Feature Table)数据格式标准规范
导航 引 概述 文件结构 结构填充 JSON 头 二进制体 实例 属性参考 引官网文档 概述要素表(Feature Table)是瓦片的实例二进制组件,用户描述每一个瓦片在 渲染 时的位置和外观属性。而批处理表(Batch T
  目录