s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
138 lines • 5.73 kB
TypeScript
import { NadGridStore } from '../readers/nadgrid';
import type { MValue, VectorPoint } from '../geometry';
import type { ProjectionParams, ProjectionTransform, ProjectionTransformDefinition } from './projections';
/**
* # PROJ4 Transformer
*
* ## Description
*
* A Transformer class contains all projections necessary for converting coordinates from one
* projection to another. This is a modular class that can be extended to add new projections
* as needed to reduce code size and improve performance.
* Both forward and inverse projections are default set to wgs84.
*
* Extends the {@link NadGridStore} class to support grid lookups
*
* ## Usage
*
* ### Full Example
*
* ```ts
* import { Transformer, injectAllDefinitions, injectAllEPSGCodes } from 's2-tools';
*
* // Create a transform using a source and destination projection
* const transform = new Transformer();
* // inject all default definition projections. This is not memory efficient but ensures all
* // projections are available
* injectAllDefinitions(transform);
* // inject all common EPSG codes. This is not memory efficient but ensures all EPSG codes are available
* injectAllEPSGCodes(transform);
* // If the transform requires a grid, this is how you add it.
* transform.addGridFromReader(
* 'BETA2007.gsb',
* new MMapReader(`${__dirname}/fixtures/BETA2007.gsb`),
* );
* // Set the source and destination projections
* transform.setSource('EPSG_31466');
* transform.setDestination('EPSG_25832');
* // example forward projection
* const forward = transform.forward({ x: 2559552, y: 5670982 });
* // example inverse projection
* const inverse = transform.inverse({ x: 349757.381712518, y: 5671004.06504954 });
* ```
*
* ### Minimal Example only adding the Oblique Mercator
*
* ```ts
* import { Transformer, HotineObliqueMercator, EPSG_8803 } from 's2-tools';
*
* const transform = new Transformer();
* transform.insertDefinition(HotineObliqueMercator);
* transform.insertEPSGCode('EPSG_8803', EPSG_8803);
*
* transform.setDestination('EPSG_8803');
*
* const forward = transform.forward({ x: 60.8, y: -132.2 });
* ```
*/
export declare class Transformer extends NadGridStore {
#private;
epsgs: Map<string, string>;
definitions: Map<string, typeof import("./projections").ProjectionBase>;
wgs84: ProjectionTransform;
source: ProjectionTransform;
destination: ProjectionTransform;
/**
* Prepares default definitions, source transform, and destination transform
* @param sourceCode - convenience: if provided, we run `this.setSource(sourceCode)` immediately
* @param destCode - convenience: if provided, we run `this.setDestination(destCode)` immediately
*/
constructor(sourceCode?: string | ProjectionParams, destCode?: string | ProjectionParams);
/**
* Set the source projection
* @param sourceCode - can be a name or a coded definition
*/
setSource(sourceCode: string | ProjectionParams): void;
/**
* Set the destination projection
* @param destCode - can be a name or a coded definition
*/
setDestination(destCode: string | ProjectionParams): void;
/**
* Insert a projection definition
* ```ts
* import { HotineObliqueMercator } from 's2-tools';
* const transformer = new Transformer();
* transformer.insertDefinition(HotineObliqueMercator);
* ```
* @param def - a class that may be instatiated with future setSource and setDestination
* @param names - optionally add projection reference names to add lookups to the definition
*/
insertDefinition(def: ProjectionTransformDefinition, names?: string[]): void;
/**
* Insert an EPSG code definition
* ```ts
* import { EPSG_4326 } from 's2-tools';
* const transformer = new Transformer();
* transformer.insertEPSGCode('EPSG_4326', EPSG_4326);
* ```
* @param code - EPSG code to insert e.g. "EPSG_4326" (uses underscore instead of colon)
* @param value - the EPSG definition which is either a WKT string object or proj4 encoded string
*/
insertEPSGCode(code: string, value: string): void;
/**
* Forward projection from src projection to dest projection
* ```ts
* const transformer = new Transformer();
* transformer.setSource('EPSG_4326');
* const point = transformer.forward({ x: 0, y: 0 });
* ```
* @param p - vector point currently in the "source" projection
* @param enforceAxis - enforce axis ensures axis consistency relative to the final projection
* @returns - vector point in the "destination" projection
*/
forward<D extends MValue>(p: VectorPoint<D>, enforceAxis?: boolean): VectorPoint<D>;
/**
* Inverse projection from dest projection to src projection
* ```ts
* const transformer = new Transformer();
* transformer.setSource('EPSG_4326');
* const point = transformer.inverse({ x: 0, y: 0 });
* ```
* @param p - vector point currently in the "destination" projection
* @param enforceAxis - enforce axis ensures axis consistency relative to the final projection
* @returns - vector point in the "source" projection
*/
inverse<D extends MValue>(p: VectorPoint<D>, enforceAxis?: boolean): VectorPoint<D>;
}
/**
* Inject all default definitions into the transformer
* @param transformer - projection transformer
*/
export declare function injectAllDefinitions(transformer: Transformer): void;
/**
* Inject all EPSG codes into the transformer
* @param transformer - the transformer to inject EPSG codes to
*/
export declare function injectAllEPSGCodes(transformer: Transformer): void;
//# sourceMappingURL=transformer.d.ts.map