Tinshift module to transform coordinates using TIN mesh.
Minimal 2D Triangulated Irregular Network based transformation implementation based on input structure of https://proj.org/en/9.3/operations/transformations/tinshift.html
This package is hosted on npm so you can install it with npm
npm i tinshift
Import module class and function
import {TinShift, sliceIntoChunks} from 'tinshift';
Create configuration object based on the Proj Tinshift. the example below uses triangles created in the Delaunator package:
const tinshift_config = {name: "tinshift",
fallback_strategy: "nearest_side",
transformed_components: [ "horizontal" ],
vertices_columns: [ "source_x", "source_y", "target_x", "target_y" ],
triangles_columns: [ "idx_vertex1", "idx_vertex2", "idx_vertex3"],
vertices: vertices,
triangles: sliceIntoChunks(delaunay.triangles)} ;
Create the tinshift transformer
const transformer = new TinShift(tinshift_config);
Use the transformer to convert coordinates ([x, y]
) from source system to target system
transformer.forward([2, 49]);
// [2.1, 49.1]
The TinShift
class creates two OpenLayers Vector Sources (using source and target vertices) and uses the R-Tree spatial index to find the relevant triangle for a given coordinate. The barymetric coordinates are then calculated for this point and used together with the target triangle vertices to interpolate the target coodinate. The transformer also offers an inverse version which uses the target coordinate to find the equivalent coordinate in the source sytem.
This is the first working version of my first NPM/JS package, created for use with the OpenLayers extension Tinmap.
It will be continually tested and improved. Open to hints and tips from the community.