UNPKG

gis-tools-ts

Version:

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

68 lines 2.68 kB
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 'gis-tools-ts'; * import { FileReader } from 'gis-tools-ts/file'; * * const fileReader = new FileReader(`${__dirname}/fixtures/basic3D.csv`); * const csvReader = new CSVReader(fileReader, { * // set options, completely optional, but the values you see are the default. * delimiter: ',', // how the CSV document separates values * lineDelimiter: '\n', // the line delimiter, sometimes "\r\n" or some specializ unicode character * lonKey: 'Longitude', // the key to use to store the longitude * latKey: 'Latitude', // the key to use to store the latitude * heightKey: 'height', // the key to use for the height or "z-value" * }); * * // read the features * for await (const feature of csvReader) { * console.log(feature); * } * ``` * * ## Links * - https://en.wikipedia.org/wiki/Comma-separated_values * - https://cesium.com/blog/2015/04/07/quadtree-cheatseet/ */ 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