UNPKG

gis-tools-ts

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

83 lines 2.82 kB
import type { DataBaseFile } from './dbf.js'; import type { Transformer } from '../../proj4/index.js'; import type { BBox3D, MValue, Properties, VectorFeature, VectorFeatureCollection } from '../../geometry/index.js'; import type { FeatureIterator, Reader, ReaderInputs } from '../index.js'; /** A Shapefile Header describing the internal data */ export interface SHPHeader { length: number; version: number; shpCode: number; bbox: BBox3D; } /** A Shapefile Row explaining how to read the feature */ export interface SHPRow { id: number; len: number; type: number; data: DataView; } /** * # The Shapefile Reader * * ## Description * Reads data from a shapefile implementing the {@link FeatureIterator} interface * * ## Usage * * NOTE: It's recommended to not parse the shapefile directly but instead: * - `import { shapefileFromURL } from 'gis-tools-ts';` * - `import { shapefileFromPath } from 'gis-tools-ts/file';` * * This ensures the other files paired with the shapefile are loaded to properly handle the * projection and properties data. * * ## Direct Usage * * ```ts * import { ShapeFileReader, DataBaseFile, Transformer } from 'gis-tools-ts'; * import { FileReader } from 'gis-tools-ts/file'; * // or use the MMapReader if using Bun: * // import { MMapReader } from 'gis-tools-ts/mmap'; * * const transform = new Transformer(); * const dbf = new DataBaseFile(new FileReader('./data.dbf'), 'utf-8'); * const reader = new ShapeFileReader(new FileReader('./data.shp'), dbf, transform); * * // read all the features * for await (const feature of reader) { * console.log(feature); * } * ``` * * ## Links * - https://en.wikipedia.org/wiki/Shapefile */ export declare class ShapeFileReader<M = Record<string, unknown>, D extends MValue = MValue, P extends Properties = Properties> implements FeatureIterator<M, D, P> { #private; dbf?: DataBaseFile | undefined; transform?: Transformer | undefined; reader: Reader; rows: number[]; /** * @param input - the input data structure to parse * @param dbf - the dbf file * @param transform - transform mechanics if they exist */ constructor(input: ReaderInputs, dbf?: DataBaseFile | undefined, transform?: Transformer | undefined); /** * Return a shallow copy of the header data * @returns - a shallow copy of the header data */ getHeader(): SHPHeader; /** * Return all the features in the shapefile * @returns - a collection of VectorFeatures */ getFeatureCollection(): Promise<VectorFeatureCollection<M, D, P>>; /** * Iterate over all features in the shapefile * @yields {VectorFeature} */ [Symbol.asyncIterator](): AsyncGenerator<VectorFeature<M, D, P>>; } //# sourceMappingURL=shp.d.ts.map