New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@allmaps/transform

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allmaps/transform - npm Package Compare versions

Comparing version 1.0.0-beta.31 to 1.0.0-beta.32

4

dist/shared/helmert.js

@@ -50,4 +50,4 @@ import { Matrix, pseudoInverse } from 'ml-matrix';

this.helmertParametersMatrix.get(1, 0) +
this.helmertParametersMatrix.get(3, 0) * newSourcePoint[0] +
this.helmertParametersMatrix.get(2, 0) * newSourcePoint[1]
this.helmertParametersMatrix.get(2, 0) * newSourcePoint[1] +
this.helmertParametersMatrix.get(3, 0) * newSourcePoint[0]
];

@@ -54,0 +54,0 @@ return newDestinationPoint;

@@ -11,3 +11,4 @@ // TODO: consider implementing these functions in this module instead of using dependencies

destinationIsGeographic: false,
sourceIsGeographic: false
sourceIsGeographic: false,
differentHandedness: false
};

@@ -26,2 +27,5 @@ if (options && options.maxDepth !== undefined) {

}
if (options && options.differentHandedness !== undefined) {
mergedOptions.differentHandedness = options.differentHandedness;
}
return mergedOptions;

@@ -28,0 +32,0 @@ }

@@ -19,4 +19,5 @@ import type { Point, GeojsonPoint } from '@allmaps/types';

maxDepth: number;
sourceIsGeographic: boolean;
destinationIsGeographic: boolean;
sourceIsGeographic: boolean;
differentHandedness: boolean;
};

@@ -29,2 +30,3 @@ export type PartialTransformOptions = Partial<TransformOptions>;

destinationPoints: Point[];
options?: PartialTransformOptions;
pointCount: number;

@@ -31,0 +33,0 @@ interpolate(point: Point): Point;

@@ -0,3 +1,3 @@

import type { Point, LineString, Polygon, Gcp, GeojsonPoint, GeojsonLineString, GeojsonPolygon, GeojsonGeometry, SvgGeometry } from '@allmaps/types';
import type { TransformGcp, TransformationType, PartialTransformOptions, GcpTransformerInterface, Transformation } from './shared/types.js';
import type { Point, LineString, Polygon, Gcp, GeojsonPoint, GeojsonLineString, GeojsonPolygon, GeojsonGeometry, SvgGeometry } from '@allmaps/types';
/**

@@ -13,2 +13,3 @@ * A Ground Control Point Transformer, containing a forward and backward transformation and

type: TransformationType;
options?: PartialTransformOptions;
forwardTransformation?: Transformation;

@@ -20,3 +21,4 @@ backwardTransformation?: Transformation;

* @param {TransformationType} [type='polynomial'] - The transformation type
*/ constructor(gcps: TransformGcp[] | Gcp[], type?: TransformationType);
*/ constructor(gcps: TransformGcp[] | Gcp[], type?: TransformationType, options?: PartialTransformOptions);
assureEqualHandedness(point: Point): Point;
transformForward(input: Point | GeojsonPoint, options?: PartialTransformOptions): Point;

@@ -23,0 +25,0 @@ transformForward(input: LineString | GeojsonLineString, options?: PartialTransformOptions): LineString;

@@ -7,2 +7,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {

var _GcpTransformer_instances, _GcpTransformer_createForwardTransformation, _GcpTransformer_createBackwardTransformation, _GcpTransformer_createTransformation;
import { convertPointToGeojsonPoint, convertLineStringToGeojsonLineString, convertPolygonToGeojsonPolygon, convertGeojsonPointToPoint, convertGeojsonLineStringToLineString, convertGeojsonPolygonToPolygon, isPoint, isLineString, isPolygon, isGeojsonPoint, isGeojsonLineString, isGeojsonPolygon, flipY } from '@allmaps/stdlib';
import Helmert from './shared/helmert.js';

@@ -15,3 +16,2 @@ import Polynomial from './shared/polynomial.js';

import { transformLineStringForwardToLineString, transformLineStringBackwardToLineString, transformPolygonForwardToPolygon, transformPolygonBackwardToPolygon } from './shared/transform-helper-functions.js';
import { convertPointToGeojsonPoint, convertLineStringToGeojsonLineString, convertPolygonToGeojsonPolygon, convertGeojsonPointToPoint, convertGeojsonLineStringToLineString, convertGeojsonPolygonToPolygon, isPoint, isLineString, isPolygon, isGeojsonPoint, isGeojsonLineString, isGeojsonPolygon } from '@allmaps/stdlib';
/**

@@ -26,4 +26,7 @@ * A Ground Control Point Transformer, containing a forward and backward transformation and

* @param {TransformationType} [type='polynomial'] - The transformation type
*/ constructor(gcps, type = 'polynomial') {
*/ constructor(gcps, type = 'polynomial', options) {
_GcpTransformer_instances.add(this);
if (options) {
this.options = options;
}
if (gcps.length == 0) {

@@ -50,2 +53,5 @@ throw new Error('No control points.');

}
assureEqualHandedness(point) {
return this.options?.differentHandedness ? flipY(point) : point;
}
/**

@@ -67,3 +73,3 @@ * Transforms a Geometry or a GeoJSON geometry forward to a Geometry

}
return this.forwardTransformation.interpolate(input);
return this.forwardTransformation.interpolate(this.assureEqualHandedness(input));
}

@@ -163,3 +169,3 @@ else if (isGeojsonPoint(input)) {

}
return this.backwardTransformation.interpolate(input);
return this.assureEqualHandedness(this.backwardTransformation.interpolate(input));
}

@@ -431,5 +437,5 @@ else if (isGeojsonPoint(input)) {

_GcpTransformer_instances = new WeakSet(), _GcpTransformer_createForwardTransformation = function _GcpTransformer_createForwardTransformation() {
return __classPrivateFieldGet(this, _GcpTransformer_instances, "m", _GcpTransformer_createTransformation).call(this, this.sourcePoints, this.destinationPoints);
return __classPrivateFieldGet(this, _GcpTransformer_instances, "m", _GcpTransformer_createTransformation).call(this, this.sourcePoints.map((point) => this.assureEqualHandedness(point)), this.destinationPoints);
}, _GcpTransformer_createBackwardTransformation = function _GcpTransformer_createBackwardTransformation() {
return __classPrivateFieldGet(this, _GcpTransformer_instances, "m", _GcpTransformer_createTransformation).call(this, this.destinationPoints, this.sourcePoints);
return __classPrivateFieldGet(this, _GcpTransformer_instances, "m", _GcpTransformer_createTransformation).call(this, this.destinationPoints, this.sourcePoints.map((point) => this.assureEqualHandedness(point)));
}, _GcpTransformer_createTransformation = function _GcpTransformer_createTransformation(sourcePoints, destinationPoints) {

@@ -436,0 +442,0 @@ if (this.type === 'helmert') {

{
"name": "@allmaps/transform",
"version": "1.0.0-beta.31",
"version": "1.0.0-beta.32",
"contributors": [

@@ -45,3 +45,3 @@ {

"dependencies": {
"@allmaps/stdlib": "^1.0.0-beta.21",
"@allmaps/stdlib": "^1.0.0-beta.22",
"@turf/distance": "^6.3.0",

@@ -52,3 +52,3 @@ "@turf/midpoint": "^6.3.0",

"devDependencies": {
"@allmaps/types": "^1.0.0-beta.8",
"@allmaps/types": "^1.0.0-beta.9",
"@types/geojson": "^7946.0.10",

@@ -82,3 +82,3 @@ "@typescript-eslint/eslint-plugin": "^5.45.0",

"license": "GPL-3.0-or-later",
"gitHead": "05c825e6e25518732176f92bc4ee9782ad144894"
"gitHead": "7c78af0bfc5772991eda9a4ed8c256f5321daa87"
}

@@ -75,6 +75,18 @@ # @allmaps/transform

### Refined transfromation of LineStrings and Polygons
### Handedness
For some transformations, it is important that the source and destination planes have the same *handedness*.
There are two types of handedness: a Cartesian plane with the positive x-axis pointing right and the positive y-axis pointing up (and the x-axis being the "first" and the y-axis the "second" axis) is said to have *right-handed* orientation (also called *standard*, *positive* or *counter-clockwise*). This is for example the case in the equirectangular projection - at least if the coordinate order is (lon, lat). Alternatively, if the y-axis points downwards, we say the orientation is *left-handed* (or *negative* or *clock-wise*). This is for example the case for typical pixel coordinates.
The handedness of the source and destination can differ, for example if the source are pixels of an image and the destination are (lon, lat) coordinates (which is the typical case for Allmaps). For many transformations, it does not matter whether the source and destination have the same handedness, since a separate transformation is computed for both axes. For some transformations, like the Helmert transformation, the transformation of X and Y coordinates are computed jointly (they are said to be 'coupled') and the difference matters.
In case the handedness differs one can set the `differentHandedness` parameter to `true`. This will flip the y-axis of the source in the control points (and new points) so as to align the handedness of both during computation.
### Refined transformation of LineStrings and Polygons
When transforming a line or polygon, it can happen that simply transforming every point is not sufficient. Two factors are at play which may require a more granular transformation: the transformation (which can be non-shape preserving, as is the case with all transformation in this package except for Helmert and 1st degree polynomial) or the geographic nature of the coordinates (where lines are generally meant as 'great arcs' but could be interpreted as lon-lat cartesian lines). An algorithm will therefore recursively add midpoints in each segment (i.e. between two points) to make the line more granular. A midpoint is added at the transformed middle point of the original segment on the condition that the ratio of (the distance between the middle point of the transformed segment and the transformed middle point of the original segment) to the length of the transformed segment, is larger then a given ratio. The following options specify if and with what degree of detail such extra points should be added.
### Transformation options
| Option | Description | Default |

@@ -86,2 +98,3 @@ | :------------------------ | :----------------------------------------------------------------------- | :------------------------------------------- |

| `destinationIsGeographic` | Use geographic distances and midpoints for lon-lat destination points | `false` (`true` when destination is GeoJSON) |
| `differentHandedness` | Whether one of the axes should be flipped while computing the transformation parameters. Should be true if the handedness differs between the source and destination. | `false` |

@@ -302,2 +315,3 @@ ## Installation

* `type` **TransformationType** The transformation type (optional, default `'polynomial'`)
* `options` &#x20;

@@ -304,0 +318,0 @@ #### transformForward

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc