s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
75 lines • 2.58 kB
TypeScript
import type { DataBaseFile } from './dbf';
import type { Transformer } from '../../proj4';
import type { BBox3D, FeatureCollection, MValue, Properties, VectorFeature } from '../../geometry';
import type { FeatureIterator, Reader, ReaderInputs } from '..';
/** 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
*
* NOTE: It's recommended to not parse the shapefile directly but instead:
* - `import { shapefileFromURL } from 's2-tools';`
* - `import { shapefileFromPath } from 's2-tools/file';`
*
* This ensures the other files paired with the shapefile are loaded to properly handle the
* projection and properties data.
*
* ## Usage
* ```ts
* import { ShapeFileReader, DataBaseFile, Transformer } from 's2-tools';
* import { FileReader } from 's2-tools/file';
*
* 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);
* }
* ```
*/
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<FeatureCollection<M, D, P>>;
/**
* Iterate over all features in the shapefile
* @yields {VectorFeature}
*/
[Symbol.asyncIterator](): AsyncGenerator<VectorFeature<M, D, P>>;
}
//# sourceMappingURL=shp.d.ts.map