s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
154 lines • 4.84 kB
TypeScript
import type { FeatureCollection, VectorFeature, VectorMultiPoint, VectorPoint } from '../geometry';
import type { FeatureIterator, Reader, ReaderInputs } from '.';
/** A Subgrid contained inside a NadGrid */
export interface NadSubGrid {
cvs: VectorMultiPoint;
ll: VectorPoint;
del: VectorPoint;
lim: VectorPoint;
count: number;
}
/** A grid wrapper around a parsed .gsb file */
export interface NadGridDefinition {
name: string;
mandatory: boolean;
grid?: NadGridReader;
isNull: boolean;
}
/**
* # NAD Grid V2 Reader
*
* ## Description
* Store Grids from a NTv2 file (.gsb)
*
* ## Usage
* ```ts
* import { NadGridReader } from 's2-tools';
* import { MMapReader } from 's2-tools/mmap';
*
* const store = new NadGridStore();
*
* store.addGridFromReader('BETA2007.gsb', new MMapReader(`${__dirname}/fixtures/BETA2007.gsb`));
*
* const grid = store.getGrid('BETA2007.gsb');
* ```
*/
export declare class NadGridStore {
grids: Map<string, NadGridReader>;
/**
* Insert a new NadGrid into the store
* @param grid - a nadgrid class to store
*/
addGrid(grid: NadGridReader): void;
/**
* Get a grid from the store given a key or name
* @param key - the key or name of the grid
* @returns - the grid
*/
getGrid(key: string): NadGridReader | undefined;
/**
* Add a grid given a data input
* @param key - the key or name of the grid
* @param input - the input data to parse
*/
addGridFromReader(key: string, input: ReaderInputs): void;
/**
* Get grid definitions from a string name
* @param keys - complex string of grid keys to test against
* @returns - an array of grid definitions
*/
getGridsFromString(keys?: string): NadGridDefinition[];
/**
* Get a grid definition from a string
* @param name - a single grid name to test against
* @returns - a grid definition
*/
getGridFromString(name: string): undefined | NadGridDefinition;
}
/** The header of a NTv2 file */
export interface NadGridHeader {
nFields: number;
nSubgridFields: number;
nSubgrids: number;
shiftType: string;
fromSemiMajorAxis: number;
fromSemiMinorAxis: number;
toSemiMajorAxis: number;
toSemiMinorAxis: number;
}
/** Each subgrid has it's own data on how to decode the points inside the subgrid */
export interface NadSubGridHeader {
name: string;
parent: string;
lowerLatitude: number;
upperLatitude: number;
lowerLongitude: number;
upperLongitude: number;
latitudeInterval: number;
longitudeInterval: number;
gridNodeCount: number;
}
/** A single Node describing how to decode the point */
export interface GridNode {
latitudeShift: number;
longitudeShift: number;
latitudeAccuracy: number;
longitudeAccuracy: number;
}
/** The metadata inside each vector feature */
export interface NadGridMetadata {
lowerLonLat: VectorPoint;
lonLatInterval: VectorPoint;
lonLatColumnCount: VectorPoint;
count: number;
}
/**
* # NAD Grid Reader
*
* ## Description
* Loads/reads a binary NTv2 file (.gsb) implementing the {@link FeatureIterator} interface
*
* It should be noted that a proj4 Transformer usually uses this class internally. But if you want
* to manually parse a .gsb file, you can use this class directly.
*
* ## Usage
*
* ```ts
* import { NadGridReader } from 's2-tools'
* // mmap is a Bun exclusive feature, consider using `s2-tools/file`'s `FileReader` instead.
* import { MMapReader } from 's2-tools/mmap';
*
* const reader = new NadGridReader('BETA2007.gsb', new MMapReader('./BETA2007.gsb'));
*
* // access all the vector features
* const data = await Array.fromAsync(reader);
* ```
*
* ## Links
* - https://web.archive.org/web/20140127204822if_/http://www.mgs.gov.on.ca:80/stdprodconsume/groups/content/@mgs/@iandit/documents/resourcelist/stel02_047447.pdf
* - http://mimaka.com/help/gs/html/004_NTV2%20Data%20Format.htm
*/
export declare class NadGridReader implements FeatureIterator<NadGridMetadata> {
#private;
key: string;
reader: Reader;
subgrids: NadSubGrid[];
/**
* @param key - the key or name of the grid
* @param input - the input data to parse
*/
constructor(key: string, input: ReaderInputs);
/** @returns - The header describing how to decode the feature */
get header(): NadGridHeader;
/**
* Return all the features in the shapefile
* @returns - a collection of VectorFeatures
*/
getFeatureCollection(): FeatureCollection<NadGridMetadata>;
/**
* Iterate over all features in the shapefile
* @yields {VectorFeature<NadGridMetadata>}
*/
[Symbol.asyncIterator](): AsyncGenerator<VectorFeature<NadGridMetadata>>;
}
//# sourceMappingURL=nadgrid.d.ts.map