UNPKG

open-vector-tile

Version:

This library reads/writes Open Vector Tiles

208 lines 8.94 kB
import type { BBox, BBox3D } from 's2json-spec'; import type { PbfReader, Pbf as Protobuf } from 'pbf-ts'; import type { Point, Point3D, VectorPoints, VectorPoints3D } from '../vectorTile.spec.js'; /** * Column Types take up 3 bits. * ColumnNames define various common data structures to be stored in a column fashion */ export declare const enum OColumnName { /** stores string values */ string = 1, /** * Note: IDs are stored in unsigned * Number types are sorted prior to storing */ unsigned = 2, /** Number types are sorted prior to storing */ signed = 3, /** * Floating precision helps ensure only 32 bit cost * Number types are sorted prior to storing */ float = 4, /** * worst case, no compression * Number types are sorted prior to storing */ double = 5, /** * points is an array of { x: number, y: number } * points also stores lines. * if a line is stored, note that it has an acompanying offset and potentially mValues * Polygons are stored as a collection of lines. * The points feature type that has more than one will be stored here as well. */ points = 6, /** * points3D is an array of { x: number, y: number, z: number } * points3D also stores lines. * if a line is stored, note that it has an acompanying offset and potentially mValues * Polygons are stored as a collection of lines. * The points 3D feature type that has more than one will be stored here as well. */ points3D = 7, /** * store M-Value, Shape, and Value encodings * store geometry shapes. * store geometry indices. */ indices = 8, /** Shapes describe how to rebuild objects */ shapes = 9, /** * BBox - specially compressed to reduce byte cost. each value is only 3 bytes worst case * BBox3D - specially compressed to reduce byte cost. each value is only 3 bytes worst case. * The z values are stored as floats and cost 4 bytes. */ bbox = 10 } /** Just the number types in the store */ export type OColumnNumbers = OColumnName.signed | OColumnName.unsigned | OColumnName.float | OColumnName.double; /** * Represents a reference to the position in the protobuf to deserialize. * @param pos - The position in the protobuf data. */ export interface PositionReference { pos: number; } /** * Represents a reference to the position in the protobuf to deserialize. * @param pos - The position in the protobuf data. */ export interface RawData<T> { data: T; } /** * note: base1 type allows you to decode as needed for each grouping of data. * for instance OColumnString is an array of strings, but you may only need a few strings on use. * Store either data itself or a reference to the position in the protobuf to deserialize * @template T - Any Type * @param data - the data parsed and available. Kept to reduce fetch duplication * @param pos - the position in the protobuf to fetch the data */ export type ColumnValueRead<T> = Array<RawData<T> | PositionReference>; /** * Store either data itself or a reference to the position in the protobuf to deserialize * @template T - Any Type; the raw data parsed and available. Kept to reduce fetch duplication */ export type ColumnValueReadSimple<T> = Array<T | PositionReference>; /** * Column Cache Reader * Stores all data in a column format. * Upon construction, all columns are decoded from the protobuf. * This allows for quick and easy access to data in a column format. */ export declare class ColumnCacheReader { #private; /** strings are stored in a column of strings */ [OColumnName.string]: ColumnValueReadSimple<string>; /** unsigned whole numbers are stored in unsigned */ [OColumnName.unsigned]: ColumnValueReadSimple<number>; /** negative numbers are stored in signed */ [OColumnName.signed]: ColumnValueReadSimple<number>; /** non-whole 32-bit numbers are stored in float */ [OColumnName.float]: ColumnValueReadSimple<number>; /** non-whole numbers greater than 32-bit are stored in double */ [OColumnName.double]: ColumnValueReadSimple<number>; /** for geometry types each column is individually weaved and delta encoded */ [OColumnName.points]: ColumnValueReadSimple<VectorPoints>; /** for geometry types each column is individually weaved and delta encoded */ [OColumnName.points3D]: ColumnValueReadSimple<VectorPoints3D>; /** store M-Value indices, geometry indices, and geometry shapes */ [OColumnName.indices]: ColumnValueReadSimple<number>; /** shapes and possibly value indices are stored in a number[] to be decoded by readShape */ [OColumnName.shapes]: ColumnValueRead<number[]>; /** Stores both BBox and BBox3D in a single column */ [OColumnName.bbox]: ColumnValueRead<BBox | BBox3D>; /** * @param pbf - the pbf protocol we are reading from * @param end - the position to stop at */ constructor(pbf: PbfReader, end?: number); /** * @param col - the column to read/store the parsed data * @param index - the index in the column to read/store the parsed data * @returns - the parsed data */ getColumn<T>(col: OColumnName, index: number): T; } /** * Numbers track their own index for sorting purposes */ export type OColumnBaseChunk<T> = { /** The column type */ col: OColumnName; /** The raw data in the column */ data: T; /** * The index in the column. Will be updated during the writing phase when converted * from a map to an array */ index: number; /** track how many times this chunk is reused */ count: number; }; /** * All columns are stored as an object to be able to reference them later. * Some columns will use this to sort, others will simply be used to store the raw data. */ export type ColumnValueRef = OColumnBaseChunk<unknown>; /** * A value is a collection of lookup devices. A number is decoded by the appropriate function, * but the object is a reference to one of the number columns. * Number types are eventually sorted, so we track the column and index with the data. */ export type ColumnValue = number | ColumnValueRef; /** A building block for all column types. */ export type OColumnBaseWrite<K, V = K> = Map<K, OColumnBaseChunk<V>>; /** * The cache where all data is stored in a column format. * Each column type has its own array of data. * Number types maintain their own index for sorting purposes. */ export declare class ColumnCacheWriter { /** strings are grouped by their bytes. */ [OColumnName.string]: Map<string, OColumnBaseChunk<string>>; /** Unsigned integers are sorted prior to storing */ [OColumnName.unsigned]: Map<number, OColumnBaseChunk<number>>; /** Signed integers are sorted prior to storing */ [OColumnName.signed]: Map<number, OColumnBaseChunk<number>>; /** 32-bit partial values are sorted prior to storing */ [OColumnName.float]: Map<number, OColumnBaseChunk<number>>; /** 64-bit partial values are sorted prior to storing */ [OColumnName.double]: Map<number, OColumnBaseChunk<number>>; /** for geometry types each column is individually weaved and delta encoded */ [OColumnName.points]: Map<string, OColumnBaseChunk<Point[]>>; /** for geometry types each column is individually weaved and delta encoded */ [OColumnName.points3D]: Map<string, OColumnBaseChunk<Point3D[]>>; /** Indices track geometry indices, geometry shapes, or other indexing data */ [OColumnName.indices]: Map<string, OColumnBaseChunk<number[]>>; /** Contains number arrays of how to rebuild objects */ [OColumnName.shapes]: Map<string, OColumnBaseChunk<ColumnValue[]>>; /** Features should be sorted by id prior to building a column */ [OColumnName.bbox]: Map<string, OColumnBaseChunk<BBox | BBox3D>>; /** * @template T - one of the column types * @param col - the column to add the value to * @param value - the value to add * @returns - the index of the value */ addColumnData<T>(col: OColumnName, value: T): number; /** * This function is specifically designed for number types as they will be sorted later * for better compression. * @param value - the number * @param cType - the column type if we already know its classification * @returns - the ColumnValue reference which contains the index and data. * Will be sorted before stored. */ addNumber(value: number, cType?: OColumnNumbers): ColumnValue; /** * The whole column cache is a message at the tile level. * all columns are stored as fields in the message * @param column - the column cache we want to write from * @param pbf - the pbf protocol we are writing to */ static write(column: ColumnCacheWriter, pbf: Protobuf): void; } //# sourceMappingURL=columnCache.d.ts.map