UNPKG

@loaders.gl/geoarrow

Version:

GeoArrow columnar geometry encoding and decoding

40 lines (39 loc) 1.78 kB
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import * as arrow from 'apache-arrow'; import { getDataTypeFromArray, deserializeArrowType } from '@loaders.gl/schema-utils'; export function isFixedSizeList(vector) { return vector.type instanceof arrow.FixedSizeList; } export function getFixedSizeListSize(vector) { return vector.type instanceof arrow.FixedSizeList ? vector.type.listSize : 1; } /** Get Arrow FixedSizeList vector from a typed array */ export function getFixedSizeListVector(typedArray, stride) { const data = getFixedSizeListData(typedArray, stride); return new arrow.Vector([data]); } /** Get Arrow FixedSizeList vector from a typed array */ export function getFixedSizeListData(typedArray, stride) { const listType = getFixedSizeListType(typedArray, stride); const nestedType = listType.children[0].type; const buffers = { // valueOffsets: undefined, [arrow.BufferType.DATA]: typedArray // values // nullBitmap: undefined, // typeIds: undefined }; // Note: The contiguous array of data is held by the nested "primitive type" column const nestedData = new arrow.Data(nestedType, 0, typedArray.length, 0, buffers); // Wrapped in a FixedSizeList column that provides a "strided" view of the data const data = new arrow.Data(listType, 0, typedArray.length / stride, 0, undefined, [nestedData]); return data; } /** Get Arrow FixedSizeList vector from a typed array */ export function getFixedSizeListType(typedArray, stride) { const { type } = getDataTypeFromArray(typedArray); const arrowType = deserializeArrowType(type); const listType = new arrow.FixedSizeList(stride, new arrow.Field('value', arrowType)); return listType; }