s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
62 lines • 2.2 kB
TypeScript
import type { FeatureIterator, Reader, ReaderInputs } from '..';
import type { MValue, Properties, VectorFeature } from '../../geometry';
/** User defined options on how to parse the CSV file */
export interface CSVReaderOptions {
/** The delimiter to use to separate lines [Default=','] */
delimiter?: string;
/** The lineDelimiter to use to separate lines [Default='\n'] */
lineDelimiter?: string;
/** If provided the lookup of the longitude [Default='lon'] */
lonKey?: string;
/** If provided the lookup of the latitude [Default='lat'] */
latKey?: string;
/** If provided the lookup for the height value [Default=undefined] */
heightKey?: string;
}
/**
* # CSV Reader
*
* ## Description
* Parse (Geo|S2)JSON from a file that is in the CSV format
* Implements the {@link FeatureIterator} interface
*
* ## Usage
* ```ts
* import { CSVReader } from 's2-tools';
* import { FileReader } from 's2-tools/file';
*
* const fileReader = new FileReader(`${__dirname}/fixtures/basic3D.csv`);
* const csvReader = new CSVReader(fileReader, {
* delimiter: ',',
* lineDelimiter: '\n',
* lonKey: 'Longitude',
* latKey: 'Latitude',
* heightKey: 'height',
* });
* // read the features
* for await (const feature of reader) {
* console.log(feature);
* }
* ```
*/
export declare class CSVReader<M = Record<string, unknown>, D extends MValue = MValue, P extends Properties = Properties> implements FeatureIterator<M, D, P> {
#private;
reader: Reader;
/**
* @param input - the input data to parse from
* @param options - user defined options on how to parse the CSV file
*/
constructor(input: ReaderInputs, options?: CSVReaderOptions);
/**
* Generator to iterate over each (Geo|S2)JSON object in the file
* @yields {VectorFeature}
*/
[Symbol.asyncIterator](): AsyncGenerator<VectorFeature<M, D, P>>;
}
/**
* Parse CSV data into a record
* @param source - the source of the CSV data
* @returns - an object with key-value pairs whose keys and values are both strings
*/
export declare function parseCSVAsRecord<T = Record<string, string>>(source: string): T[];
//# sourceMappingURL=index.d.ts.map