gis-tools-ts - v0.6.0
    Preparing search index...

    Class Transformer

    PROJ4 Transformer

    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 NadGridStore class to support grid lookups

    import { Transformer, injectAllDefinitions, injectAllEPSGCodes } from 'gis-tools-ts';

    // 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);
    // Or add a specific projection
    transform.insertDefinition(HotineObliqueMercator);
    // inject all common EPSG codes. This is not memory efficient but ensures all EPSG codes are available
    injectAllEPSGCodes(transform);
    // Or add a specific EPSG code
    transform.insertEPSGCode('EPSG_4326', EPSG_4326);
    // 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 });
    import { Transformer, HotineObliqueMercator, EPSG_8803 } from 'gis-tools-ts';

    const transform = new Transformer(undefined, 'EPSG_8803', [HotineObliqueMercator], { EPSG_8803 });
    // example moving from WGS84 to EPSG:8803
    const forward = transform.forward({ x: 60.8, y: -132.2 });

    Hierarchy (View Summary)

    Index

    Constructors

    • Prepares default definitions, source transform, and destination transform

      Parameters

      • OptionalsourceCode: string | ProjectionParams

        convenience: if provided, we run this.setSource(sourceCode) immediately

      • OptionaldestCode: string | ProjectionParams

        convenience: if provided, we run this.setDestination(destCode) immediately

      • definitions: typeof ProjectionBase[] = []

        an array of projection definitions for the transformer if needed

      • epsgCodes: Record<string, string> = {}

        a record of EPSG codes to use for the transformer if needed

      • gridStore: GridReader[] = []

        the grid readers

      Returns Transformer

    Methods

    • Forward projection from src projection to dest projection

      const transformer = new Transformer();
      transformer.setSource('EPSG_4326');
      const point = transformer.forward({ x: 0, y: 0 });

      Type Parameters

      • D extends Properties

      Parameters

      • p: VectorPoint<D>

        vector point currently in the "source" projection

      • OptionalenforceAxis: boolean

        enforce axis ensures axis consistency relative to the final projection

      Returns VectorPoint<D>

      • vector point in the "destination" projection
    • Forward projection from src projection to dest projection

      const transformer = new Transformer();
      transformer.setSource('EPSG_4326');
      const point = transformer.forward({ x: 0, y: 0 });

      Type Parameters

      • D extends Properties

      Parameters

      • p: VectorPointM<D>

        vector point currently in the "source" projection

      • OptionalenforceAxis: boolean

        enforce axis ensures axis consistency relative to the final projection

      Returns VectorPointM<D>

      • vector point in the "destination" projection
    • Insert a projection definition

      import { Transformer, HotineObliqueMercator } from 'gis-tools-ts';
      const transformer = new Transformer();
      transformer.insertDefinition(HotineObliqueMercator);

      Parameters

      • def: typeof ProjectionBase

        a class that may be instatiated with future setSource and setDestination

      • names: string[] = []

        optionally add projection reference names to add lookups to the definition

      Returns void

    • Insert an EPSG code definition

      import { Transformer, EPSG_4326 } from 'gis-tools-ts';
      const transformer = new Transformer();
      transformer.insertEPSGCode('EPSG_4326', EPSG_4326);

      Parameters

      • code: string

        EPSG code to insert e.g. "EPSG_4326" (uses underscore instead of colon)

      • value: string

        the EPSG definition which is either a WKT string object or proj4 encoded string

      Returns void

    • Inverse projection from dest projection to src projection

      const transformer = new Transformer();
      transformer.setSource('EPSG_4326');
      const point = transformer.inverse({ x: 0, y: 0 });

      Type Parameters

      • D extends Properties

      Parameters

      • p: VectorPoint<D>

        vector point currently in the "destination" projection

      • OptionalenforceAxis: boolean

        enforce axis ensures axis consistency relative to the final projection

      Returns VectorPoint<D>

      • vector point in the "source" projection
    • Inverse projection from dest projection to src projection

      const transformer = new Transformer();
      transformer.setSource('EPSG_4326');
      const point = transformer.inverse({ x: 0, y: 0 });

      Type Parameters

      • D extends Properties

      Parameters

      • p: VectorPointM<D>

        vector point currently in the "destination" projection

      • OptionalenforceAxis: boolean

        enforce axis ensures axis consistency relative to the final projection

      Returns VectorPointM<D>

      • vector point in the "source" projection
    • Set the destination projection

      Parameters

      Returns void

    • Set the source projection

      Parameters

      Returns void