@developmentseed/raster-reproject 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/affine.d.ts +18 -0
- package/dist/affine.d.ts.map +1 -0
- package/dist/affine.js +42 -0
- package/dist/affine.js.map +1 -0
- package/dist/delatin.d.ts +96 -0
- package/dist/delatin.d.ts.map +1 -0
- package/dist/delatin.js +558 -0
- package/dist/delatin.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/src/affine.d.ts +18 -0
- package/dist/src/affine.d.ts.map +1 -0
- package/dist/src/affine.js +42 -0
- package/dist/src/affine.js.map +1 -0
- package/dist/src/delatin.d.ts +96 -0
- package/dist/src/delatin.d.ts.map +1 -0
- package/dist/src/delatin.js +558 -0
- package/dist/src/delatin.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/example.test.d.ts +2 -0
- package/dist/tests/example.test.d.ts.map +1 -0
- package/dist/tests/example.test.js +110 -0
- package/dist/tests/example.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Development Seed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/affine.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type GeoTransform = [number, number, number, number, number, number];
|
|
2
|
+
/**
|
|
3
|
+
* Find the inverse of this GeoTransform.
|
|
4
|
+
*
|
|
5
|
+
* Ported from rasterio/affine:
|
|
6
|
+
* https://github.com/rasterio/affine/blob/a7a916fc7012f8afeb6489246ada61a76ccb8bc7/src/affine.py#L671-L692
|
|
7
|
+
* under the BSD-3-Clause License.
|
|
8
|
+
*
|
|
9
|
+
* @param {GeoTransform} gt Geotransform.
|
|
10
|
+
*
|
|
11
|
+
* @return {GeoTransform} Inverse of the geotransform.
|
|
12
|
+
*/
|
|
13
|
+
export declare function invertGeoTransform(gt: GeoTransform): GeoTransform;
|
|
14
|
+
/**
|
|
15
|
+
* Apply a GeoTransform to a coordinate.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyAffine(x: number, y: number, gt: [number, number, number, number, number, number]): [number, number];
|
|
18
|
+
//# sourceMappingURL=affine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine.d.ts","sourceRoot":"","sources":["../src/affine.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,YAAY,GAAG,YAAY,CAgBjE;AAWD;;GAEG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GACnD,CAAC,MAAM,EAAE,MAAM,CAAC,CAGlB"}
|
package/dist/affine.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the inverse of this GeoTransform.
|
|
3
|
+
*
|
|
4
|
+
* Ported from rasterio/affine:
|
|
5
|
+
* https://github.com/rasterio/affine/blob/a7a916fc7012f8afeb6489246ada61a76ccb8bc7/src/affine.py#L671-L692
|
|
6
|
+
* under the BSD-3-Clause License.
|
|
7
|
+
*
|
|
8
|
+
* @param {GeoTransform} gt Geotransform.
|
|
9
|
+
*
|
|
10
|
+
* @return {GeoTransform} Inverse of the geotransform.
|
|
11
|
+
*/
|
|
12
|
+
export function invertGeoTransform(gt) {
|
|
13
|
+
if (isDegenerate(gt)) {
|
|
14
|
+
throw new Error("Cannot invert degenerate transform");
|
|
15
|
+
}
|
|
16
|
+
const idet = 1.0 / determinant(gt);
|
|
17
|
+
const [sa, sb, sc, sd, se, sf] = gt;
|
|
18
|
+
const ra = se * idet;
|
|
19
|
+
const rb = -sb * idet;
|
|
20
|
+
const rd = -sd * idet;
|
|
21
|
+
const re = sa * idet;
|
|
22
|
+
// prettier-ignore
|
|
23
|
+
return [
|
|
24
|
+
ra, rb, -sc * ra - sf * rb,
|
|
25
|
+
rd, re, -sc * rd - sf * re,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
function isDegenerate(gt) {
|
|
29
|
+
return determinant(gt) === 0;
|
|
30
|
+
}
|
|
31
|
+
function determinant(gt) {
|
|
32
|
+
const [a, b, _c, d, e, _f] = gt;
|
|
33
|
+
return a * e - b * d;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Apply a GeoTransform to a coordinate.
|
|
37
|
+
*/
|
|
38
|
+
export function applyAffine(x, y, gt) {
|
|
39
|
+
const [a, b, c, d, e, f] = gt;
|
|
40
|
+
return [a * x + b * y + c, d * x + e * y + f];
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=affine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affine.js","sourceRoot":"","sources":["../src/affine.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAgB;IACjD,IAAI,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACrB,kBAAkB;IAClB,OAAO;QACH,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;QAC1B,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,EAAgB;IACpC,OAAO,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,WAAW,CAAC,EAAgB;IACnC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,CAAS,EACT,CAAS,EACT,EAAoD;IAEpD,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define [**uv coordinates**](https://en.wikipedia.org/wiki/UV_mapping) as a float-valued image-local coordinate space where the top left is `(0, 0)` and the bottom right is `(1, 1)`.
|
|
3
|
+
*
|
|
4
|
+
* Define [**Barycentric coordinates**](https://en.wikipedia.org/wiki/Barycentric_coordinate_system) as float-valued triangle-local coordinates, represented as a 3-tuple of floats, where the tuple must add up to 1. The coordinate represents "how close to each vertex" a point in the interior of a triangle is. I.e. `(0, 0, 1)`, `(0, 1, 0)`, and `(1, 0, 0)` are all valid barycentric coordinates that define one of the three vertices. `(1/3, 1/3, 1/3)` represents the centroid of a triangle. `(1/2, 1/2, 0)` represents a point that is halfway between vertices `a` and `b` and has "none" of vertex `c`.
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* ## Changes
|
|
8
|
+
*
|
|
9
|
+
* - Delatin coordinates are in terms of pixel space whereas here we use uv space.
|
|
10
|
+
*
|
|
11
|
+
* Originally copied from https://github.com/mapbox/delatin under the ISC
|
|
12
|
+
* license, then subject to further modifications.
|
|
13
|
+
*/
|
|
14
|
+
export interface ReprojectionFns {
|
|
15
|
+
/**
|
|
16
|
+
* Convert from UV coordinates to input CRS coordinates.
|
|
17
|
+
*
|
|
18
|
+
* This is the affine geotransform from the input image.
|
|
19
|
+
*/
|
|
20
|
+
pixelToInputCRS(x: number, y: number): [number, number];
|
|
21
|
+
/**
|
|
22
|
+
* Convert from input CRS coordinates back to UV coordinates.
|
|
23
|
+
*
|
|
24
|
+
* Inverse of the affine geotransform from the input image.
|
|
25
|
+
*/
|
|
26
|
+
inputCRSToPixel(x: number, y: number): [number, number];
|
|
27
|
+
/**
|
|
28
|
+
* Apply the forward projection from input CRS to output CRS.
|
|
29
|
+
*/
|
|
30
|
+
forwardReproject(x: number, y: number): [number, number];
|
|
31
|
+
/**
|
|
32
|
+
* Apply the inverse projection from output CRS back to input CRS.
|
|
33
|
+
*/
|
|
34
|
+
inverseReproject(x: number, y: number): [number, number];
|
|
35
|
+
}
|
|
36
|
+
export declare class RasterReprojector {
|
|
37
|
+
reprojectors: ReprojectionFns;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
/**
|
|
41
|
+
* UV vertex coordinates (x, y), i.e.
|
|
42
|
+
* [x0, y0, x1, y1, ...]
|
|
43
|
+
*
|
|
44
|
+
* These coordinates are floats that range from [0, 1] in both X and Y.
|
|
45
|
+
*/
|
|
46
|
+
uvs: number[];
|
|
47
|
+
/**
|
|
48
|
+
* XY Positions in output CRS, computed via exact forward reprojection.
|
|
49
|
+
*/
|
|
50
|
+
exactOutputPositions: number[];
|
|
51
|
+
/**
|
|
52
|
+
* triangle vertex indices
|
|
53
|
+
*/
|
|
54
|
+
triangles: number[];
|
|
55
|
+
private _halfedges;
|
|
56
|
+
/**
|
|
57
|
+
* The UV texture coordinates of candidates found from
|
|
58
|
+
* `findReprojectionCandidate`.
|
|
59
|
+
*
|
|
60
|
+
* Maybe in the future we'll want to store the barycentric coordinates instead
|
|
61
|
+
* of just the uv coordinates?
|
|
62
|
+
*/
|
|
63
|
+
private _candidatesUV;
|
|
64
|
+
private _queueIndices;
|
|
65
|
+
private _queue;
|
|
66
|
+
private _errors;
|
|
67
|
+
private _pending;
|
|
68
|
+
private _pendingLen;
|
|
69
|
+
constructor(reprojectors: ReprojectionFns, width: number, height?: number);
|
|
70
|
+
run(maxError?: number): void;
|
|
71
|
+
refine(): void;
|
|
72
|
+
getMaxError(): number;
|
|
73
|
+
private _flush;
|
|
74
|
+
/**
|
|
75
|
+
* Conversion of upstream's `_findCandidate` for reprojection error handling.
|
|
76
|
+
*
|
|
77
|
+
* @param {number} t The index (into `this.triangles`) of the pending triangle to process.
|
|
78
|
+
*
|
|
79
|
+
* @return {void} Doesn't return; instead modifies internal state.
|
|
80
|
+
*/
|
|
81
|
+
private _findReprojectionCandidate;
|
|
82
|
+
private _step;
|
|
83
|
+
private _addPoint;
|
|
84
|
+
_addTriangle(a: number, b: number, c: number, ab: number, bc: number, ca: number, e?: number): number;
|
|
85
|
+
private _legalize;
|
|
86
|
+
private _handleCollinear;
|
|
87
|
+
private _queuePush;
|
|
88
|
+
private _queuePop;
|
|
89
|
+
private _queuePopBack;
|
|
90
|
+
private _queueRemove;
|
|
91
|
+
private _queueLess;
|
|
92
|
+
private _queueSwap;
|
|
93
|
+
private _queueUp;
|
|
94
|
+
private _queueDown;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=delatin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delatin.d.ts","sourceRoot":"","sources":["../src/delatin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiBH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE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