@spacexr/geodesy 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ The format is based on Keep a Changelog and this project follows Semantic Versio
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.0] - 2026-10-05
10
+
11
+ ### Added
12
+
13
+ - `TransverseMercatorProjection`, an ellipsoidal transverse Mercator projection using the sixth-order Kruger series, with forward and inverse conversions in degrees or radians.
14
+ - `UtmProjection`, `utmCentralMeridianDegrees` and `utmZoneFromDegrees`, including the Norway and Svalbard zone exceptions.
15
+ - `IProjectedCoordinates` for easting and northing values in metres.
16
+
9
17
  ## [0.1.0] - 2026-10-05
10
18
 
11
19
  ### Added
package/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -120,6 +120,26 @@ NED is the local navigation convention commonly used in aviation and inertial na
120
120
 
121
121
  This model replaces the mutable ENU state and event dependency that existed in the original SpaceXR implementation. Applications can create a new local frame when their floating origin changes without mutating the planetary reference system.
122
122
 
123
+ ## Transverse Mercator and UTM
124
+
125
+ `TransverseMercatorProjection` implements the ellipsoidal transverse Mercator projection with the sixth-order Kruger series described by Karney (2011). The error stays below one millimetre across a UTM zone. `UtmProjection` specializes it with the UTM scale factor of 0.9996, a false easting of 500,000 m and a southern false northing of 10,000,000 m.
126
+
127
+ ```ts
128
+ import { Ellipsoid, GeodeticSystem, UtmProjection, utmZoneFromDegrees } from "@spacexr/geodesy";
129
+
130
+ // NAD83 / UTM zone 18N (EPSG:26918) uses the GRS80 ellipsoid.
131
+ const utm = new UtmProjection(18, "N", Ellipsoid.GRS80);
132
+
133
+ const geodetic = utm.projectedToGeodeticDegrees(438705.189, 5830304.72, 254.085);
134
+ const projected = utm.geodeticDegreesToProjected(geodetic.latitude, geodetic.longitude);
135
+
136
+ const ecef = new GeodeticSystem(Ellipsoid.GRS80).geodeticDegreesToEcef(geodetic.latitude, geodetic.longitude, geodetic.height);
137
+
138
+ const zone = utmZoneFromDegrees(52.6, -75.9); // 18
139
+ ```
140
+
141
+ Pass the ellipsoid of the horizontal datum: WGS84 for WGS 84, GRS80 for NAD83, NAD83(CSRS) and ETRS89. The projection does not perform datum transformations, and the height argument is copied unchanged, so an orthometric elevation remains orthometric.
142
+
123
143
  ## Migration from SpaceXR Core
124
144
 
125
145
  The package preserves the useful concepts while making units and state explicit:
@@ -44,6 +44,18 @@ interface ILocalTangentBasis {
44
44
  /** Unit vector normal to the ellipsoid and pointing up. */
45
45
  up: ICartesian3;
46
46
  }
47
+ /**
48
+ * Mutable projected map coordinate.
49
+ *
50
+ * Eastings increase toward the east and northings toward the north. Both are
51
+ * expressed in metres and include any false easting or false northing.
52
+ */
53
+ interface IProjectedCoordinates {
54
+ /** Easting in metres. */
55
+ easting: number;
56
+ /** Northing in metres. */
57
+ northing: number;
58
+ }
47
59
 
48
60
  /**
49
61
  * Immutable geodetic reference system backed by one reference ellipsoid.
@@ -254,4 +266,4 @@ declare class LocalTangentPlane {
254
266
  enuToGeodeticDegrees(position: ICartesian3, target?: IGeodeticCoordinates): IGeodeticCoordinates;
255
267
  }
256
268
 
257
- export { GeodeticSystem as G, type ICartesian3 as I, LocalTangentPlane as L, type IGeodeticCoordinates as a, type ILocalTangentBasis as b };
269
+ export { GeodeticSystem as G, type IProjectedCoordinates as I, LocalTangentPlane as L, type IGeodeticCoordinates as a, type ICartesian3 as b, type ILocalTangentBasis as c };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { Ellipsoid } from './ellipsoid.js';
2
- export { G as GeodeticSystem, I as ICartesian3, a as IGeodeticCoordinates, b as ILocalTangentBasis, L as LocalTangentPlane } from './geodetic-system-DRpWY8qG.js';
1
+ import { Ellipsoid } from './ellipsoid.js';
2
+ import { I as IProjectedCoordinates, a as IGeodeticCoordinates } from './geodetic-system-BKhOCDNU.js';
3
+ export { G as GeodeticSystem, b as ICartesian3, c as ILocalTangentBasis, L as LocalTangentPlane } from './geodetic-system-BKhOCDNU.js';
3
4
 
4
5
  /** Number of radians in one degree. */
5
6
  declare const DEGREES_TO_RADIANS: number;
@@ -36,4 +37,143 @@ declare function normalizeLongitudeRadians(longitudeRadians: number): number;
36
37
  */
37
38
  declare function normalizeLongitudeDegrees(longitudeDegrees: number): number;
38
39
 
39
- export { DEGREES_TO_RADIANS, RADIANS_TO_DEGREES, TWO_PI, normalizeLongitudeDegrees, normalizeLongitudeRadians, toDegrees, toRadians };
40
+ /**
41
+ * Options describing a transverse Mercator projection.
42
+ */
43
+ interface ITransverseMercatorOptions {
44
+ /** Reference ellipsoid. Defaults to WGS84. */
45
+ ellipsoid?: Ellipsoid;
46
+ /** Longitude of the central meridian in radians east of the reference meridian. */
47
+ centralMeridianRadians: number;
48
+ /** Scale factor on the central meridian. Defaults to 1. */
49
+ scaleFactor?: number;
50
+ /** Value added to every easting, in metres. Defaults to 0. */
51
+ falseEasting?: number;
52
+ /** Value added to every northing, in metres. Defaults to 0. */
53
+ falseNorthing?: number;
54
+ }
55
+ /**
56
+ * Ellipsoidal transverse Mercator projection.
57
+ *
58
+ * The implementation uses the Kruger series to sixth order in the third
59
+ * flattening, as described by Karney (2011), "Transverse Mercator with an
60
+ * accuracy of a few nanometers". The error stays below one millimetre within
61
+ * several thousand kilometres of the central meridian, which covers every UTM
62
+ * zone with a wide margin.
63
+ *
64
+ * Eastings increase toward the east and northings toward the north, both in
65
+ * metres. Geodetic coordinates use geodetic latitude and longitude east of the
66
+ * reference meridian.
67
+ */
68
+ declare class TransverseMercatorProjection {
69
+ /** Reference ellipsoid of the projection. */
70
+ readonly ellipsoid: Ellipsoid;
71
+ /** Longitude of the central meridian in radians. */
72
+ readonly centralMeridianRadians: number;
73
+ /** Scale factor on the central meridian. */
74
+ readonly scaleFactor: number;
75
+ /** False easting in metres. */
76
+ readonly falseEasting: number;
77
+ /** False northing in metres. */
78
+ readonly falseNorthing: number;
79
+ private readonly eccentricity;
80
+ /** Rectifying radius multiplied by the central scale factor, in metres. */
81
+ private readonly scaledRectifyingRadius;
82
+ private readonly alpha;
83
+ private readonly beta;
84
+ /**
85
+ * Creates a transverse Mercator projection.
86
+ *
87
+ * @param options - Projection parameters.
88
+ * @throws RangeError When a parameter is not finite or the scale factor is not positive.
89
+ */
90
+ constructor(options: ITransverseMercatorOptions);
91
+ /**
92
+ * Projects geodetic coordinates in radians.
93
+ *
94
+ * @param latitudeRadians - Geodetic latitude in radians, within `[-PI/2, PI/2]`.
95
+ * @param longitudeRadians - Longitude in radians east of the reference meridian.
96
+ * @param target - Optional mutable output object, used to avoid an allocation.
97
+ * @returns The target populated with easting and northing in metres.
98
+ * @throws RangeError When an input is not finite or the latitude is out of range.
99
+ */
100
+ geodeticRadiansToProjected(latitudeRadians: number, longitudeRadians: number, target?: IProjectedCoordinates): IProjectedCoordinates;
101
+ /**
102
+ * Projects geodetic coordinates in degrees.
103
+ *
104
+ * @param latitudeDegrees - Geodetic latitude in degrees, within `[-90, 90]`.
105
+ * @param longitudeDegrees - Longitude in degrees east of the reference meridian.
106
+ * @param target - Optional mutable output object, used to avoid an allocation.
107
+ * @returns The target populated with easting and northing in metres.
108
+ */
109
+ geodeticDegreesToProjected(latitudeDegrees: number, longitudeDegrees: number, target?: IProjectedCoordinates): IProjectedCoordinates;
110
+ /**
111
+ * Converts projected coordinates to geodetic coordinates in radians.
112
+ *
113
+ * @param easting - Easting in metres, including the false easting.
114
+ * @param northing - Northing in metres, including the false northing.
115
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
116
+ * @param target - Optional mutable output object, used to avoid an allocation.
117
+ * @returns The target populated with geodetic latitude and longitude in radians, longitude normalized to `[-PI, PI)`.
118
+ * @throws RangeError When an input is not finite.
119
+ */
120
+ projectedToGeodeticRadians(easting: number, northing: number, height?: number, target?: IGeodeticCoordinates): IGeodeticCoordinates;
121
+ /**
122
+ * Converts projected coordinates to geodetic coordinates in degrees.
123
+ *
124
+ * @param easting - Easting in metres, including the false easting.
125
+ * @param northing - Northing in metres, including the false northing.
126
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
127
+ * @param target - Optional mutable output object, used to avoid an allocation.
128
+ * @returns The target populated with geodetic latitude and longitude in degrees, longitude normalized to `[-180, 180)`.
129
+ */
130
+ projectedToGeodeticDegrees(easting: number, northing: number, height?: number, target?: IGeodeticCoordinates): IGeodeticCoordinates;
131
+ }
132
+
133
+ /** Hemisphere of a UTM zone. `N` uses a false northing of 0 m and `S` a false northing of 10,000,000 m. */
134
+ type UtmHemisphere = "N" | "S";
135
+ /** Scale factor on the central meridian of every UTM zone. */
136
+ declare const UTM_SCALE_FACTOR = 0.9996;
137
+ /** False easting of every UTM zone in metres. */
138
+ declare const UTM_FALSE_EASTING = 500000;
139
+ /** False northing of southern UTM zones in metres. */
140
+ declare const UTM_SOUTH_FALSE_NORTHING = 10000000;
141
+ /**
142
+ * Universal Transverse Mercator projection for one zone and hemisphere.
143
+ *
144
+ * Zone `z` is centred on longitude `-183 + 6z` degrees. The ellipsoid must be
145
+ * the one of the horizontal datum: WGS84 for WGS 84, GRS80 for NAD83 and
146
+ * ETRS89. This class does not perform datum transformations.
147
+ */
148
+ declare class UtmProjection extends TransverseMercatorProjection {
149
+ readonly zone: number;
150
+ readonly hemisphere: UtmHemisphere;
151
+ /**
152
+ * Creates the projection of a UTM zone.
153
+ *
154
+ * @param zone - UTM zone number from 1 to 60.
155
+ * @param hemisphere - `N` for the northern hemisphere or `S` for the southern hemisphere.
156
+ * @param ellipsoid - Ellipsoid of the horizontal datum. Defaults to WGS84.
157
+ * @throws RangeError When the zone or hemisphere is invalid.
158
+ */
159
+ constructor(zone: number, hemisphere: UtmHemisphere, ellipsoid?: Ellipsoid);
160
+ }
161
+ /**
162
+ * Returns the central meridian of a UTM zone.
163
+ *
164
+ * @param zone - UTM zone number from 1 to 60.
165
+ * @returns Central meridian longitude in degrees.
166
+ */
167
+ declare function utmCentralMeridianDegrees(zone: number): number;
168
+ /**
169
+ * Returns the standard UTM zone containing a geodetic position.
170
+ *
171
+ * Applies the Norway and Svalbard exceptions of the UTM grid.
172
+ *
173
+ * @param latitudeDegrees - Geodetic latitude in degrees.
174
+ * @param longitudeDegrees - Longitude in degrees east of the reference meridian.
175
+ * @returns UTM zone number from 1 to 60.
176
+ */
177
+ declare function utmZoneFromDegrees(latitudeDegrees: number, longitudeDegrees: number): number;
178
+
179
+ export { DEGREES_TO_RADIANS, Ellipsoid, IGeodeticCoordinates, IProjectedCoordinates, type ITransverseMercatorOptions, RADIANS_TO_DEGREES, TWO_PI, TransverseMercatorProjection, UTM_FALSE_EASTING, UTM_SCALE_FACTOR, UTM_SOUTH_FALSE_NORTHING, type UtmHemisphere, UtmProjection, normalizeLongitudeDegrees, normalizeLongitudeRadians, toDegrees, toRadians, utmCentralMeridianDegrees, utmZoneFromDegrees };
package/dist/index.js CHANGED
@@ -1,4 +1,221 @@
1
+ import { normalizeLongitudeRadians, DEGREES_TO_RADIANS, RADIANS_TO_DEGREES, normalizeLongitudeDegrees } from './chunk-WYCQOUE7.js';
1
2
  export { DEGREES_TO_RADIANS, GeodeticSystem, LocalTangentPlane, RADIANS_TO_DEGREES, TWO_PI, normalizeLongitudeDegrees, normalizeLongitudeRadians, toDegrees, toRadians } from './chunk-WYCQOUE7.js';
3
+ import { Ellipsoid } from './chunk-RJFTT4KI.js';
2
4
  export { Ellipsoid } from './chunk-RJFTT4KI.js';
5
+
6
+ // src/transverse-mercator.ts
7
+ var TAU_TOLERANCE = 1e-12;
8
+ var MAX_ITERATIONS = 10;
9
+ function validateFinite(value, name) {
10
+ if (!Number.isFinite(value)) throw new RangeError(`${name} must be a finite number.`);
11
+ }
12
+ function conformalTangent(tau, eccentricity) {
13
+ const sigma = Math.sinh(eccentricity * Math.atanh(eccentricity * tau / Math.hypot(1, tau)));
14
+ return tau * Math.hypot(1, sigma) - sigma * Math.hypot(1, tau);
15
+ }
16
+ var TransverseMercatorProjection = class {
17
+ /** Reference ellipsoid of the projection. */
18
+ ellipsoid;
19
+ /** Longitude of the central meridian in radians. */
20
+ centralMeridianRadians;
21
+ /** Scale factor on the central meridian. */
22
+ scaleFactor;
23
+ /** False easting in metres. */
24
+ falseEasting;
25
+ /** False northing in metres. */
26
+ falseNorthing;
27
+ eccentricity;
28
+ /** Rectifying radius multiplied by the central scale factor, in metres. */
29
+ scaledRectifyingRadius;
30
+ alpha;
31
+ beta;
32
+ /**
33
+ * Creates a transverse Mercator projection.
34
+ *
35
+ * @param options - Projection parameters.
36
+ * @throws RangeError When a parameter is not finite or the scale factor is not positive.
37
+ */
38
+ constructor(options) {
39
+ this.ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84;
40
+ this.centralMeridianRadians = options.centralMeridianRadians;
41
+ this.scaleFactor = options.scaleFactor ?? 1;
42
+ this.falseEasting = options.falseEasting ?? 0;
43
+ this.falseNorthing = options.falseNorthing ?? 0;
44
+ validateFinite(this.centralMeridianRadians, "Central meridian");
45
+ validateFinite(this.falseEasting, "False easting");
46
+ validateFinite(this.falseNorthing, "False northing");
47
+ if (!Number.isFinite(this.scaleFactor) || this.scaleFactor <= 0)
48
+ throw new RangeError("Scale factor must be a positive finite number.");
49
+ const flattening = this.ellipsoid.flattening;
50
+ const n = flattening / (2 - flattening);
51
+ const n2 = n * n;
52
+ const n3 = n2 * n;
53
+ const n4 = n3 * n;
54
+ const n5 = n4 * n;
55
+ const n6 = n5 * n;
56
+ this.eccentricity = this.ellipsoid.eccentricity;
57
+ const rectifyingRadius = this.ellipsoid.semiMajorAxis / (1 + n) * (1 + n2 / 4 + n4 / 64 + n6 / 256);
58
+ this.scaledRectifyingRadius = this.scaleFactor * rectifyingRadius;
59
+ this.alpha = [
60
+ n / 2 - 2 / 3 * n2 + 5 / 16 * n3 + 41 / 180 * n4 - 127 / 288 * n5 + 7891 / 37800 * n6,
61
+ 13 / 48 * n2 - 3 / 5 * n3 + 557 / 1440 * n4 + 281 / 630 * n5 - 1983433 / 1935360 * n6,
62
+ 61 / 240 * n3 - 103 / 140 * n4 + 15061 / 26880 * n5 + 167603 / 181440 * n6,
63
+ 49561 / 161280 * n4 - 179 / 168 * n5 + 6601661 / 7257600 * n6,
64
+ 34729 / 80640 * n5 - 3418889 / 1995840 * n6,
65
+ 212378941 / 319334400 * n6
66
+ ];
67
+ this.beta = [
68
+ n / 2 - 2 / 3 * n2 + 37 / 96 * n3 - 1 / 360 * n4 - 81 / 512 * n5 + 96199 / 604800 * n6,
69
+ 1 / 48 * n2 + 1 / 15 * n3 - 437 / 1440 * n4 + 46 / 105 * n5 - 1118711 / 3870720 * n6,
70
+ 17 / 480 * n3 - 37 / 840 * n4 - 209 / 4480 * n5 + 5569 / 90720 * n6,
71
+ 4397 / 161280 * n4 - 11 / 504 * n5 - 830251 / 7257600 * n6,
72
+ 4583 / 161280 * n5 - 108847 / 3991680 * n6,
73
+ 20648693 / 638668800 * n6
74
+ ];
75
+ }
76
+ /**
77
+ * Projects geodetic coordinates in radians.
78
+ *
79
+ * @param latitudeRadians - Geodetic latitude in radians, within `[-PI/2, PI/2]`.
80
+ * @param longitudeRadians - Longitude in radians east of the reference meridian.
81
+ * @param target - Optional mutable output object, used to avoid an allocation.
82
+ * @returns The target populated with easting and northing in metres.
83
+ * @throws RangeError When an input is not finite or the latitude is out of range.
84
+ */
85
+ geodeticRadiansToProjected(latitudeRadians, longitudeRadians, target = { easting: 0, northing: 0 }) {
86
+ validateFinite(latitudeRadians, "Latitude");
87
+ validateFinite(longitudeRadians, "Longitude");
88
+ if (Math.abs(latitudeRadians) > Math.PI / 2) throw new RangeError("Latitude must be within [-PI/2, PI/2] radians.");
89
+ const deltaLongitude = normalizeLongitudeRadians(longitudeRadians - this.centralMeridianRadians);
90
+ const cosLongitude = Math.cos(deltaLongitude);
91
+ const sinLongitude = Math.sin(deltaLongitude);
92
+ const tau = Math.tan(latitudeRadians);
93
+ const tauPrime = conformalTangent(tau, this.eccentricity);
94
+ const xiPrime = Math.atan2(tauPrime, cosLongitude);
95
+ const etaPrime = Math.asinh(sinLongitude / Math.hypot(tauPrime, cosLongitude));
96
+ let xi = xiPrime;
97
+ let eta = etaPrime;
98
+ for (let j = 1; j <= 6; j++) {
99
+ const coefficient = this.alpha[j - 1];
100
+ xi += coefficient * Math.sin(2 * j * xiPrime) * Math.cosh(2 * j * etaPrime);
101
+ eta += coefficient * Math.cos(2 * j * xiPrime) * Math.sinh(2 * j * etaPrime);
102
+ }
103
+ target.easting = this.falseEasting + this.scaledRectifyingRadius * eta;
104
+ target.northing = this.falseNorthing + this.scaledRectifyingRadius * xi;
105
+ return target;
106
+ }
107
+ /**
108
+ * Projects geodetic coordinates in degrees.
109
+ *
110
+ * @param latitudeDegrees - Geodetic latitude in degrees, within `[-90, 90]`.
111
+ * @param longitudeDegrees - Longitude in degrees east of the reference meridian.
112
+ * @param target - Optional mutable output object, used to avoid an allocation.
113
+ * @returns The target populated with easting and northing in metres.
114
+ */
115
+ geodeticDegreesToProjected(latitudeDegrees, longitudeDegrees, target) {
116
+ return this.geodeticRadiansToProjected(latitudeDegrees * DEGREES_TO_RADIANS, longitudeDegrees * DEGREES_TO_RADIANS, target);
117
+ }
118
+ /**
119
+ * Converts projected coordinates to geodetic coordinates in radians.
120
+ *
121
+ * @param easting - Easting in metres, including the false easting.
122
+ * @param northing - Northing in metres, including the false northing.
123
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
124
+ * @param target - Optional mutable output object, used to avoid an allocation.
125
+ * @returns The target populated with geodetic latitude and longitude in radians, longitude normalized to `[-PI, PI)`.
126
+ * @throws RangeError When an input is not finite.
127
+ */
128
+ projectedToGeodeticRadians(easting, northing, height = 0, target = { latitude: 0, longitude: 0, height: 0 }) {
129
+ validateFinite(easting, "Easting");
130
+ validateFinite(northing, "Northing");
131
+ validateFinite(height, "Height");
132
+ const eta = (easting - this.falseEasting) / this.scaledRectifyingRadius;
133
+ const xi = (northing - this.falseNorthing) / this.scaledRectifyingRadius;
134
+ let xiPrime = xi;
135
+ let etaPrime = eta;
136
+ for (let j = 1; j <= 6; j++) {
137
+ const coefficient = this.beta[j - 1];
138
+ xiPrime -= coefficient * Math.sin(2 * j * xi) * Math.cosh(2 * j * eta);
139
+ etaPrime -= coefficient * Math.cos(2 * j * xi) * Math.sinh(2 * j * eta);
140
+ }
141
+ const sinhEtaPrime = Math.sinh(etaPrime);
142
+ const sinXiPrime = Math.sin(xiPrime);
143
+ const cosXiPrime = Math.cos(xiPrime);
144
+ const tauPrime = sinXiPrime / Math.hypot(sinhEtaPrime, cosXiPrime);
145
+ const oneMinusE2 = 1 - this.eccentricity * this.eccentricity;
146
+ let tau = tauPrime;
147
+ for (let iteration = 0; iteration < MAX_ITERATIONS; iteration++) {
148
+ const tauIPrime = conformalTangent(tau, this.eccentricity);
149
+ const delta = (tauPrime - tauIPrime) / Math.hypot(1, tauIPrime) * ((1 + oneMinusE2 * tau * tau) / (oneMinusE2 * Math.hypot(1, tau)));
150
+ tau += delta;
151
+ if (Math.abs(delta) <= TAU_TOLERANCE * Math.max(1, Math.abs(tau))) break;
152
+ }
153
+ target.latitude = Math.atan(tau);
154
+ target.longitude = normalizeLongitudeRadians(this.centralMeridianRadians + Math.atan2(sinhEtaPrime, cosXiPrime));
155
+ target.height = height;
156
+ return target;
157
+ }
158
+ /**
159
+ * Converts projected coordinates to geodetic coordinates in degrees.
160
+ *
161
+ * @param easting - Easting in metres, including the false easting.
162
+ * @param northing - Northing in metres, including the false northing.
163
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
164
+ * @param target - Optional mutable output object, used to avoid an allocation.
165
+ * @returns The target populated with geodetic latitude and longitude in degrees, longitude normalized to `[-180, 180)`.
166
+ */
167
+ projectedToGeodeticDegrees(easting, northing, height = 0, target) {
168
+ const result = this.projectedToGeodeticRadians(easting, northing, height, target);
169
+ result.latitude *= RADIANS_TO_DEGREES;
170
+ result.longitude *= RADIANS_TO_DEGREES;
171
+ return result;
172
+ }
173
+ };
174
+
175
+ // src/utm.ts
176
+ var UTM_SCALE_FACTOR = 0.9996;
177
+ var UTM_FALSE_EASTING = 5e5;
178
+ var UTM_SOUTH_FALSE_NORTHING = 1e7;
179
+ var UtmProjection = class extends TransverseMercatorProjection {
180
+ /**
181
+ * Creates the projection of a UTM zone.
182
+ *
183
+ * @param zone - UTM zone number from 1 to 60.
184
+ * @param hemisphere - `N` for the northern hemisphere or `S` for the southern hemisphere.
185
+ * @param ellipsoid - Ellipsoid of the horizontal datum. Defaults to WGS84.
186
+ * @throws RangeError When the zone or hemisphere is invalid.
187
+ */
188
+ constructor(zone, hemisphere, ellipsoid = Ellipsoid.WGS84) {
189
+ if (!Number.isInteger(zone) || zone < 1 || zone > 60) throw new RangeError("UTM zone must be an integer from 1 to 60.");
190
+ if (hemisphere !== "N" && hemisphere !== "S") throw new RangeError("UTM hemisphere must be N or S.");
191
+ super({
192
+ ellipsoid,
193
+ centralMeridianRadians: utmCentralMeridianDegrees(zone) * DEGREES_TO_RADIANS,
194
+ scaleFactor: UTM_SCALE_FACTOR,
195
+ falseEasting: UTM_FALSE_EASTING,
196
+ falseNorthing: hemisphere === "S" ? UTM_SOUTH_FALSE_NORTHING : 0
197
+ });
198
+ this.zone = zone;
199
+ this.hemisphere = hemisphere;
200
+ }
201
+ zone;
202
+ hemisphere;
203
+ };
204
+ function utmCentralMeridianDegrees(zone) {
205
+ return -183 + 6 * zone;
206
+ }
207
+ function utmZoneFromDegrees(latitudeDegrees, longitudeDegrees) {
208
+ const longitude = normalizeLongitudeDegrees(longitudeDegrees);
209
+ if (latitudeDegrees >= 56 && latitudeDegrees < 64 && longitude >= 3 && longitude < 12) return 32;
210
+ if (latitudeDegrees >= 72 && latitudeDegrees < 84 && longitude >= 0 && longitude < 42) {
211
+ if (longitude < 9) return 31;
212
+ if (longitude < 21) return 33;
213
+ if (longitude < 33) return 35;
214
+ return 37;
215
+ }
216
+ return Math.floor((longitude + 180) / 6) + 1;
217
+ }
218
+
219
+ export { TransverseMercatorProjection, UTM_FALSE_EASTING, UTM_SCALE_FACTOR, UTM_SOUTH_FALSE_NORTHING, UtmProjection, utmCentralMeridianDegrees, utmZoneFromDegrees };
3
220
  //# sourceMappingURL=index.js.map
4
221
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../src/transverse-mercator.ts","../src/utm.ts"],"names":[],"mappings":";;;;;;AAKA,IAAM,aAAA,GAAgB,KAAA;AAEtB,IAAM,cAAA,GAAiB,EAAA;AAkBvB,SAAS,cAAA,CAAe,OAAe,IAAA,EAAoB;AACvD,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,QAAS,IAAI,UAAA,CAAW,CAAA,EAAG,IAAI,CAAA,yBAAA,CAA2B,CAAA;AACxF;AAGA,SAAS,gBAAA,CAAiB,KAAa,YAAA,EAA8B;AACjE,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,IAAA,CAAK,YAAA,GAAe,IAAA,CAAK,KAAA,CAAO,YAAA,GAAe,GAAA,GAAO,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,GAAG,CAAC,CAAC,CAAA;AAC5F,EAAA,OAAO,GAAA,GAAM,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,KAAK,IAAI,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,GAAG,CAAA;AACjE;AAeO,IAAM,+BAAN,MAAmC;AAAA;AAAA,EAEtB,SAAA;AAAA;AAAA,EAEA,sBAAA;AAAA;AAAA,EAEA,WAAA;AAAA;AAAA,EAEA,YAAA;AAAA;AAAA,EAEA,aAAA;AAAA,EAEC,YAAA;AAAA;AAAA,EAEA,sBAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQV,YAAY,OAAA,EAAqC;AACpD,IAAA,IAAA,CAAK,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,SAAA,CAAU,KAAA;AAChD,IAAA,IAAA,CAAK,yBAA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A,IAAI,mBAAmB,EAAA,IAAM,eAAA,GAAkB,MAAM,SAAA,IAAa,CAAA,IAAK,YAAY,EAAA,EAAI;AACnF,IAAA,IAAI,SAAA,GAAY,GAAG,OAAO,EAAA;AAC1B,IAAA,IAAI,SAAA,GAAY,IAAI,OAAO,EAAA;AAC3B,IAAA,IAAI,SAAA,GAAY,IAAI,OAAO,EAAA;AAC3B,IAAA,OAAO,EAAA;AAAA,EACX;AACA,EAAA,OAAO,IAAA,CAAK,KAAA,CAAA,CAAO,SAAA,GAAY,GAAA,IAAO,CAAC,CAAA,GAAI,CAAA;AAC/C","file":"index.js","sourcesContent":["import { DEGREES_TO_RADIANS, RADIANS_TO_DEGREES, normalizeLongitudeRadians } from \"./angles\";\nimport { Ellipsoid } from \"./ellipsoid\";\nimport type { IGeodeticCoordinates, IProjectedCoordinates } from \"./types\";\n\n/** Convergence threshold of the inverse conformal latitude iteration, applied to the latitude tangent. */\nconst TAU_TOLERANCE = 1e-12;\n/** Upper bound on inverse iterations. Convergence normally takes two or three steps. */\nconst MAX_ITERATIONS = 10;\n\n/**\n * Options describing a transverse Mercator projection.\n */\nexport interface ITransverseMercatorOptions {\n /** Reference ellipsoid. Defaults to WGS84. */\n ellipsoid?: Ellipsoid;\n /** Longitude of the central meridian in radians east of the reference meridian. */\n centralMeridianRadians: number;\n /** Scale factor on the central meridian. Defaults to 1. */\n scaleFactor?: number;\n /** Value added to every easting, in metres. Defaults to 0. */\n falseEasting?: number;\n /** Value added to every northing, in metres. Defaults to 0. */\n falseNorthing?: number;\n}\n\nfunction validateFinite(value: number, name: string): void {\n if (!Number.isFinite(value)) throw new RangeError(`${name} must be a finite number.`);\n}\n\n/** Conformal latitude tangent from the geodetic latitude tangent. */\nfunction conformalTangent(tau: number, eccentricity: number): number {\n const sigma = Math.sinh(eccentricity * Math.atanh((eccentricity * tau) / Math.hypot(1, tau)));\n return tau * Math.hypot(1, sigma) - sigma * Math.hypot(1, tau);\n}\n\n/**\n * Ellipsoidal transverse Mercator projection.\n *\n * The implementation uses the Kruger series to sixth order in the third\n * flattening, as described by Karney (2011), \"Transverse Mercator with an\n * accuracy of a few nanometers\". The error stays below one millimetre within\n * several thousand kilometres of the central meridian, which covers every UTM\n * zone with a wide margin.\n *\n * Eastings increase toward the east and northings toward the north, both in\n * metres. Geodetic coordinates use geodetic latitude and longitude east of the\n * reference meridian.\n */\nexport class TransverseMercatorProjection {\n /** Reference ellipsoid of the projection. */\n public readonly ellipsoid: Ellipsoid;\n /** Longitude of the central meridian in radians. */\n public readonly centralMeridianRadians: number;\n /** Scale factor on the central meridian. */\n public readonly scaleFactor: number;\n /** False easting in metres. */\n public readonly falseEasting: number;\n /** False northing in metres. */\n public readonly falseNorthing: number;\n\n private readonly eccentricity: number;\n /** Rectifying radius multiplied by the central scale factor, in metres. */\n private readonly scaledRectifyingRadius: number;\n private readonly alpha: readonly number[];\n private readonly beta: readonly number[];\n\n /**\n * Creates a transverse Mercator projection.\n *\n * @param options - Projection parameters.\n * @throws RangeError When a parameter is not finite or the scale factor is not positive.\n */\n public constructor(options: ITransverseMercatorOptions) {\n this.ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84;\n this.centralMeridianRadians = options.centralMeridianRadians;\n this.scaleFactor = options.scaleFactor ?? 1;\n this.falseEasting = options.falseEasting ?? 0;\n this.falseNorthing = options.falseNorthing ?? 0;\n validateFinite(this.centralMeridianRadians, \"Central meridian\");\n validateFinite(this.falseEasting, \"False easting\");\n validateFinite(this.falseNorthing, \"False northing\");\n if (!Number.isFinite(this.scaleFactor) || this.scaleFactor <= 0)\n throw new RangeError(\"Scale factor must be a positive finite number.\");\n\n const flattening = this.ellipsoid.flattening;\n const n = flattening / (2 - flattening);\n const n2 = n * n;\n const n3 = n2 * n;\n const n4 = n3 * n;\n const n5 = n4 * n;\n const n6 = n5 * n;\n\n this.eccentricity = this.ellipsoid.eccentricity;\n const rectifyingRadius = (this.ellipsoid.semiMajorAxis / (1 + n)) * (1 + n2 / 4 + n4 / 64 + n6 / 256);\n this.scaledRectifyingRadius = this.scaleFactor * rectifyingRadius;\n\n this.alpha = [\n n / 2 - (2 / 3) * n2 + (5 / 16) * n3 + (41 / 180) * n4 - (127 / 288) * n5 + (7891 / 37800) * n6,\n (13 / 48) * n2 - (3 / 5) * n3 + (557 / 1440) * n4 + (281 / 630) * n5 - (1983433 / 1935360) * n6,\n (61 / 240) * n3 - (103 / 140) * n4 + (15061 / 26880) * n5 + (167603 / 181440) * n6,\n (49561 / 161280) * n4 - (179 / 168) * n5 + (6601661 / 7257600) * n6,\n (34729 / 80640) * n5 - (3418889 / 1995840) * n6,\n (212378941 / 319334400) * n6,\n ];\n this.beta = [\n n / 2 - (2 / 3) * n2 + (37 / 96) * n3 - (1 / 360) * n4 - (81 / 512) * n5 + (96199 / 604800) * n6,\n (1 / 48) * n2 + (1 / 15) * n3 - (437 / 1440) * n4 + (46 / 105) * n5 - (1118711 / 3870720) * n6,\n (17 / 480) * n3 - (37 / 840) * n4 - (209 / 4480) * n5 + (5569 / 90720) * n6,\n (4397 / 161280) * n4 - (11 / 504) * n5 - (830251 / 7257600) * n6,\n (4583 / 161280) * n5 - (108847 / 3991680) * n6,\n (20648693 / 638668800) * n6,\n ];\n }\n\n /**\n * Projects geodetic coordinates in radians.\n *\n * @param latitudeRadians - Geodetic latitude in radians, within `[-PI/2, PI/2]`.\n * @param longitudeRadians - Longitude in radians east of the reference meridian.\n * @param target - Optional mutable output object, used to avoid an allocation.\n * @returns The target populated with easting and northing in metres.\n * @throws RangeError When an input is not finite or the latitude is out of range.\n */\n public geodeticRadiansToProjected(\n latitudeRadians: number,\n longitudeRadians: number,\n target: IProjectedCoordinates = { easting: 0, northing: 0 },\n ): IProjectedCoordinates {\n validateFinite(latitudeRadians, \"Latitude\");\n validateFinite(longitudeRadians, \"Longitude\");\n if (Math.abs(latitudeRadians) > Math.PI / 2) throw new RangeError(\"Latitude must be within [-PI/2, PI/2] radians.\");\n\n const deltaLongitude = normalizeLongitudeRadians(longitudeRadians - this.centralMeridianRadians);\n const cosLongitude = Math.cos(deltaLongitude);\n const sinLongitude = Math.sin(deltaLongitude);\n\n const tau = Math.tan(latitudeRadians);\n const tauPrime = conformalTangent(tau, this.eccentricity);\n const xiPrime = Math.atan2(tauPrime, cosLongitude);\n const etaPrime = Math.asinh(sinLongitude / Math.hypot(tauPrime, cosLongitude));\n\n let xi = xiPrime;\n let eta = etaPrime;\n for (let j = 1; j <= 6; j++) {\n const coefficient = this.alpha[j - 1]!;\n xi += coefficient * Math.sin(2 * j * xiPrime) * Math.cosh(2 * j * etaPrime);\n eta += coefficient * Math.cos(2 * j * xiPrime) * Math.sinh(2 * j * etaPrime);\n }\n\n target.easting = this.falseEasting + this.scaledRectifyingRadius * eta;\n target.northing = this.falseNorthing + this.scaledRectifyingRadius * xi;\n return target;\n }\n\n /**\n * Projects geodetic coordinates in degrees.\n *\n * @param latitudeDegrees - Geodetic latitude in degrees, within `[-90, 90]`.\n * @param longitudeDegrees - Longitude in degrees east of the reference meridian.\n * @param target - Optional mutable output object, used to avoid an allocation.\n * @returns The target populated with easting and northing in metres.\n */\n public geodeticDegreesToProjected(\n latitudeDegrees: number,\n longitudeDegrees: number,\n target?: IProjectedCoordinates,\n ): IProjectedCoordinates {\n return this.geodeticRadiansToProjected(latitudeDegrees * DEGREES_TO_RADIANS, longitudeDegrees * DEGREES_TO_RADIANS, target);\n }\n\n /**\n * Converts projected coordinates to geodetic coordinates in radians.\n *\n * @param easting - Easting in metres, including the false easting.\n * @param northing - Northing in metres, including the false northing.\n * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.\n * @param target - Optional mutable output object, used to avoid an allocation.\n * @returns The target populated with geodetic latitude and longitude in radians, longitude normalized to `[-PI, PI)`.\n * @throws RangeError When an input is not finite.\n */\n public projectedToGeodeticRadians(\n easting: number,\n northing: number,\n height = 0,\n target: IGeodeticCoordinates = { latitude: 0, longitude: 0, height: 0 },\n ): IGeodeticCoordinates {\n validateFinite(easting, \"Easting\");\n validateFinite(northing, \"Northing\");\n validateFinite(height, \"Height\");\n\n const eta = (easting - this.falseEasting) / this.scaledRectifyingRadius;\n const xi = (northing - this.falseNorthing) / this.scaledRectifyingRadius;\n\n let xiPrime = xi;\n let etaPrime = eta;\n for (let j = 1; j <= 6; j++) {\n const coefficient = this.beta[j - 1]!;\n xiPrime -= coefficient * Math.sin(2 * j * xi) * Math.cosh(2 * j * eta);\n etaPrime -= coefficient * Math.cos(2 * j * xi) * Math.sinh(2 * j * eta);\n }\n\n const sinhEtaPrime = Math.sinh(etaPrime);\n const sinXiPrime = Math.sin(xiPrime);\n const cosXiPrime = Math.cos(xiPrime);\n const tauPrime = sinXiPrime / Math.hypot(sinhEtaPrime, cosXiPrime);\n\n const oneMinusE2 = 1 - this.eccentricity * this.eccentricity;\n let tau = tauPrime;\n for (let iteration = 0; iteration < MAX_ITERATIONS; iteration++) {\n const tauIPrime = conformalTangent(tau, this.eccentricity);\n const delta =\n ((tauPrime - tauIPrime) / Math.hypot(1, tauIPrime)) * ((1 + oneMinusE2 * tau * tau) / (oneMinusE2 * Math.hypot(1, tau)));\n tau += delta;\n if (Math.abs(delta) <= TAU_TOLERANCE * Math.max(1, Math.abs(tau))) break;\n }\n\n target.latitude = Math.atan(tau);\n target.longitude = normalizeLongitudeRadians(this.centralMeridianRadians + Math.atan2(sinhEtaPrime, cosXiPrime));\n target.height = height;\n return target;\n }\n\n /**\n * Converts projected coordinates to geodetic coordinates in degrees.\n *\n * @param easting - Easting in metres, including the false easting.\n * @param northing - Northing in metres, including the false northing.\n * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.\n * @param target - Optional mutable output object, used to avoid an allocation.\n * @returns The target populated with geodetic latitude and longitude in degrees, longitude normalized to `[-180, 180)`.\n */\n public projectedToGeodeticDegrees(easting: number, northing: number, height = 0, target?: IGeodeticCoordinates): IGeodeticCoordinates {\n const result = this.projectedToGeodeticRadians(easting, northing, height, target);\n result.latitude *= RADIANS_TO_DEGREES;\n result.longitude *= RADIANS_TO_DEGREES;\n return result;\n }\n}\n","import { DEGREES_TO_RADIANS, normalizeLongitudeDegrees } from \"./angles\";\nimport { Ellipsoid } from \"./ellipsoid\";\nimport { TransverseMercatorProjection } from \"./transverse-mercator\";\n\n/** Hemisphere of a UTM zone. `N` uses a false northing of 0 m and `S` a false northing of 10,000,000 m. */\nexport type UtmHemisphere = \"N\" | \"S\";\n\n/** Scale factor on the central meridian of every UTM zone. */\nexport const UTM_SCALE_FACTOR = 0.9996;\n\n/** False easting of every UTM zone in metres. */\nexport const UTM_FALSE_EASTING = 500000;\n\n/** False northing of southern UTM zones in metres. */\nexport const UTM_SOUTH_FALSE_NORTHING = 10000000;\n\n/**\n * Universal Transverse Mercator projection for one zone and hemisphere.\n *\n * Zone `z` is centred on longitude `-183 + 6z` degrees. The ellipsoid must be\n * the one of the horizontal datum: WGS84 for WGS 84, GRS80 for NAD83 and\n * ETRS89. This class does not perform datum transformations.\n */\nexport class UtmProjection extends TransverseMercatorProjection {\n /**\n * Creates the projection of a UTM zone.\n *\n * @param zone - UTM zone number from 1 to 60.\n * @param hemisphere - `N` for the northern hemisphere or `S` for the southern hemisphere.\n * @param ellipsoid - Ellipsoid of the horizontal datum. Defaults to WGS84.\n * @throws RangeError When the zone or hemisphere is invalid.\n */\n public constructor(\n public readonly zone: number,\n public readonly hemisphere: UtmHemisphere,\n ellipsoid: Ellipsoid = Ellipsoid.WGS84,\n ) {\n if (!Number.isInteger(zone) || zone < 1 || zone > 60) throw new RangeError(\"UTM zone must be an integer from 1 to 60.\");\n if (hemisphere !== \"N\" && hemisphere !== \"S\") throw new RangeError(\"UTM hemisphere must be N or S.\");\n super({\n ellipsoid,\n centralMeridianRadians: utmCentralMeridianDegrees(zone) * DEGREES_TO_RADIANS,\n scaleFactor: UTM_SCALE_FACTOR,\n falseEasting: UTM_FALSE_EASTING,\n falseNorthing: hemisphere === \"S\" ? UTM_SOUTH_FALSE_NORTHING : 0,\n });\n }\n}\n\n/**\n * Returns the central meridian of a UTM zone.\n *\n * @param zone - UTM zone number from 1 to 60.\n * @returns Central meridian longitude in degrees.\n */\nexport function utmCentralMeridianDegrees(zone: number): number {\n return -183 + 6 * zone;\n}\n\n/**\n * Returns the standard UTM zone containing a geodetic position.\n *\n * Applies the Norway and Svalbard exceptions of the UTM grid.\n *\n * @param latitudeDegrees - Geodetic latitude in degrees.\n * @param longitudeDegrees - Longitude in degrees east of the reference meridian.\n * @returns UTM zone number from 1 to 60.\n */\nexport function utmZoneFromDegrees(latitudeDegrees: number, longitudeDegrees: number): number {\n const longitude = normalizeLongitudeDegrees(longitudeDegrees);\n if (latitudeDegrees >= 56 && latitudeDegrees < 64 && longitude >= 3 && longitude < 12) return 32;\n if (latitudeDegrees >= 72 && latitudeDegrees < 84 && longitude >= 0 && longitude < 42) {\n if (longitude < 9) return 31;\n if (longitude < 21) return 33;\n if (longitude < 33) return 35;\n return 37;\n }\n return Math.floor((longitude + 180) / 6) + 1;\n}\n"]}
package/dist/system.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './ellipsoid.js';
2
- export { G as GeodeticSystem, L as LocalTangentPlane } from './geodetic-system-DRpWY8qG.js';
2
+ export { G as GeodeticSystem, L as LocalTangentPlane } from './geodetic-system-BKhOCDNU.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spacexr/geodesy",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Renderer-neutral ellipsoid, geodetic, ECEF and local tangent frame primitives for SpaceXR.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./angles";
2
2
  export * from "./ellipsoid";
3
3
  export * from "./geodetic-system";
4
+ export * from "./transverse-mercator";
4
5
  export * from "./types";
6
+ export * from "./utm";
@@ -0,0 +1,238 @@
1
+ import { DEGREES_TO_RADIANS, RADIANS_TO_DEGREES, normalizeLongitudeRadians } from "./angles";
2
+ import { Ellipsoid } from "./ellipsoid";
3
+ import type { IGeodeticCoordinates, IProjectedCoordinates } from "./types";
4
+
5
+ /** Convergence threshold of the inverse conformal latitude iteration, applied to the latitude tangent. */
6
+ const TAU_TOLERANCE = 1e-12;
7
+ /** Upper bound on inverse iterations. Convergence normally takes two or three steps. */
8
+ const MAX_ITERATIONS = 10;
9
+
10
+ /**
11
+ * Options describing a transverse Mercator projection.
12
+ */
13
+ export interface ITransverseMercatorOptions {
14
+ /** Reference ellipsoid. Defaults to WGS84. */
15
+ ellipsoid?: Ellipsoid;
16
+ /** Longitude of the central meridian in radians east of the reference meridian. */
17
+ centralMeridianRadians: number;
18
+ /** Scale factor on the central meridian. Defaults to 1. */
19
+ scaleFactor?: number;
20
+ /** Value added to every easting, in metres. Defaults to 0. */
21
+ falseEasting?: number;
22
+ /** Value added to every northing, in metres. Defaults to 0. */
23
+ falseNorthing?: number;
24
+ }
25
+
26
+ function validateFinite(value: number, name: string): void {
27
+ if (!Number.isFinite(value)) throw new RangeError(`${name} must be a finite number.`);
28
+ }
29
+
30
+ /** Conformal latitude tangent from the geodetic latitude tangent. */
31
+ function conformalTangent(tau: number, eccentricity: number): number {
32
+ const sigma = Math.sinh(eccentricity * Math.atanh((eccentricity * tau) / Math.hypot(1, tau)));
33
+ return tau * Math.hypot(1, sigma) - sigma * Math.hypot(1, tau);
34
+ }
35
+
36
+ /**
37
+ * Ellipsoidal transverse Mercator projection.
38
+ *
39
+ * The implementation uses the Kruger series to sixth order in the third
40
+ * flattening, as described by Karney (2011), "Transverse Mercator with an
41
+ * accuracy of a few nanometers". The error stays below one millimetre within
42
+ * several thousand kilometres of the central meridian, which covers every UTM
43
+ * zone with a wide margin.
44
+ *
45
+ * Eastings increase toward the east and northings toward the north, both in
46
+ * metres. Geodetic coordinates use geodetic latitude and longitude east of the
47
+ * reference meridian.
48
+ */
49
+ export class TransverseMercatorProjection {
50
+ /** Reference ellipsoid of the projection. */
51
+ public readonly ellipsoid: Ellipsoid;
52
+ /** Longitude of the central meridian in radians. */
53
+ public readonly centralMeridianRadians: number;
54
+ /** Scale factor on the central meridian. */
55
+ public readonly scaleFactor: number;
56
+ /** False easting in metres. */
57
+ public readonly falseEasting: number;
58
+ /** False northing in metres. */
59
+ public readonly falseNorthing: number;
60
+
61
+ private readonly eccentricity: number;
62
+ /** Rectifying radius multiplied by the central scale factor, in metres. */
63
+ private readonly scaledRectifyingRadius: number;
64
+ private readonly alpha: readonly number[];
65
+ private readonly beta: readonly number[];
66
+
67
+ /**
68
+ * Creates a transverse Mercator projection.
69
+ *
70
+ * @param options - Projection parameters.
71
+ * @throws RangeError When a parameter is not finite or the scale factor is not positive.
72
+ */
73
+ public constructor(options: ITransverseMercatorOptions) {
74
+ this.ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84;
75
+ this.centralMeridianRadians = options.centralMeridianRadians;
76
+ this.scaleFactor = options.scaleFactor ?? 1;
77
+ this.falseEasting = options.falseEasting ?? 0;
78
+ this.falseNorthing = options.falseNorthing ?? 0;
79
+ validateFinite(this.centralMeridianRadians, "Central meridian");
80
+ validateFinite(this.falseEasting, "False easting");
81
+ validateFinite(this.falseNorthing, "False northing");
82
+ if (!Number.isFinite(this.scaleFactor) || this.scaleFactor <= 0)
83
+ throw new RangeError("Scale factor must be a positive finite number.");
84
+
85
+ const flattening = this.ellipsoid.flattening;
86
+ const n = flattening / (2 - flattening);
87
+ const n2 = n * n;
88
+ const n3 = n2 * n;
89
+ const n4 = n3 * n;
90
+ const n5 = n4 * n;
91
+ const n6 = n5 * n;
92
+
93
+ this.eccentricity = this.ellipsoid.eccentricity;
94
+ const rectifyingRadius = (this.ellipsoid.semiMajorAxis / (1 + n)) * (1 + n2 / 4 + n4 / 64 + n6 / 256);
95
+ this.scaledRectifyingRadius = this.scaleFactor * rectifyingRadius;
96
+
97
+ this.alpha = [
98
+ n / 2 - (2 / 3) * n2 + (5 / 16) * n3 + (41 / 180) * n4 - (127 / 288) * n5 + (7891 / 37800) * n6,
99
+ (13 / 48) * n2 - (3 / 5) * n3 + (557 / 1440) * n4 + (281 / 630) * n5 - (1983433 / 1935360) * n6,
100
+ (61 / 240) * n3 - (103 / 140) * n4 + (15061 / 26880) * n5 + (167603 / 181440) * n6,
101
+ (49561 / 161280) * n4 - (179 / 168) * n5 + (6601661 / 7257600) * n6,
102
+ (34729 / 80640) * n5 - (3418889 / 1995840) * n6,
103
+ (212378941 / 319334400) * n6,
104
+ ];
105
+ this.beta = [
106
+ n / 2 - (2 / 3) * n2 + (37 / 96) * n3 - (1 / 360) * n4 - (81 / 512) * n5 + (96199 / 604800) * n6,
107
+ (1 / 48) * n2 + (1 / 15) * n3 - (437 / 1440) * n4 + (46 / 105) * n5 - (1118711 / 3870720) * n6,
108
+ (17 / 480) * n3 - (37 / 840) * n4 - (209 / 4480) * n5 + (5569 / 90720) * n6,
109
+ (4397 / 161280) * n4 - (11 / 504) * n5 - (830251 / 7257600) * n6,
110
+ (4583 / 161280) * n5 - (108847 / 3991680) * n6,
111
+ (20648693 / 638668800) * n6,
112
+ ];
113
+ }
114
+
115
+ /**
116
+ * Projects geodetic coordinates in radians.
117
+ *
118
+ * @param latitudeRadians - Geodetic latitude in radians, within `[-PI/2, PI/2]`.
119
+ * @param longitudeRadians - Longitude in radians east of the reference meridian.
120
+ * @param target - Optional mutable output object, used to avoid an allocation.
121
+ * @returns The target populated with easting and northing in metres.
122
+ * @throws RangeError When an input is not finite or the latitude is out of range.
123
+ */
124
+ public geodeticRadiansToProjected(
125
+ latitudeRadians: number,
126
+ longitudeRadians: number,
127
+ target: IProjectedCoordinates = { easting: 0, northing: 0 },
128
+ ): IProjectedCoordinates {
129
+ validateFinite(latitudeRadians, "Latitude");
130
+ validateFinite(longitudeRadians, "Longitude");
131
+ if (Math.abs(latitudeRadians) > Math.PI / 2) throw new RangeError("Latitude must be within [-PI/2, PI/2] radians.");
132
+
133
+ const deltaLongitude = normalizeLongitudeRadians(longitudeRadians - this.centralMeridianRadians);
134
+ const cosLongitude = Math.cos(deltaLongitude);
135
+ const sinLongitude = Math.sin(deltaLongitude);
136
+
137
+ const tau = Math.tan(latitudeRadians);
138
+ const tauPrime = conformalTangent(tau, this.eccentricity);
139
+ const xiPrime = Math.atan2(tauPrime, cosLongitude);
140
+ const etaPrime = Math.asinh(sinLongitude / Math.hypot(tauPrime, cosLongitude));
141
+
142
+ let xi = xiPrime;
143
+ let eta = etaPrime;
144
+ for (let j = 1; j <= 6; j++) {
145
+ const coefficient = this.alpha[j - 1]!;
146
+ xi += coefficient * Math.sin(2 * j * xiPrime) * Math.cosh(2 * j * etaPrime);
147
+ eta += coefficient * Math.cos(2 * j * xiPrime) * Math.sinh(2 * j * etaPrime);
148
+ }
149
+
150
+ target.easting = this.falseEasting + this.scaledRectifyingRadius * eta;
151
+ target.northing = this.falseNorthing + this.scaledRectifyingRadius * xi;
152
+ return target;
153
+ }
154
+
155
+ /**
156
+ * Projects geodetic coordinates in degrees.
157
+ *
158
+ * @param latitudeDegrees - Geodetic latitude in degrees, within `[-90, 90]`.
159
+ * @param longitudeDegrees - Longitude in degrees east of the reference meridian.
160
+ * @param target - Optional mutable output object, used to avoid an allocation.
161
+ * @returns The target populated with easting and northing in metres.
162
+ */
163
+ public geodeticDegreesToProjected(
164
+ latitudeDegrees: number,
165
+ longitudeDegrees: number,
166
+ target?: IProjectedCoordinates,
167
+ ): IProjectedCoordinates {
168
+ return this.geodeticRadiansToProjected(latitudeDegrees * DEGREES_TO_RADIANS, longitudeDegrees * DEGREES_TO_RADIANS, target);
169
+ }
170
+
171
+ /**
172
+ * Converts projected coordinates to geodetic coordinates in radians.
173
+ *
174
+ * @param easting - Easting in metres, including the false easting.
175
+ * @param northing - Northing in metres, including the false northing.
176
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
177
+ * @param target - Optional mutable output object, used to avoid an allocation.
178
+ * @returns The target populated with geodetic latitude and longitude in radians, longitude normalized to `[-PI, PI)`.
179
+ * @throws RangeError When an input is not finite.
180
+ */
181
+ public projectedToGeodeticRadians(
182
+ easting: number,
183
+ northing: number,
184
+ height = 0,
185
+ target: IGeodeticCoordinates = { latitude: 0, longitude: 0, height: 0 },
186
+ ): IGeodeticCoordinates {
187
+ validateFinite(easting, "Easting");
188
+ validateFinite(northing, "Northing");
189
+ validateFinite(height, "Height");
190
+
191
+ const eta = (easting - this.falseEasting) / this.scaledRectifyingRadius;
192
+ const xi = (northing - this.falseNorthing) / this.scaledRectifyingRadius;
193
+
194
+ let xiPrime = xi;
195
+ let etaPrime = eta;
196
+ for (let j = 1; j <= 6; j++) {
197
+ const coefficient = this.beta[j - 1]!;
198
+ xiPrime -= coefficient * Math.sin(2 * j * xi) * Math.cosh(2 * j * eta);
199
+ etaPrime -= coefficient * Math.cos(2 * j * xi) * Math.sinh(2 * j * eta);
200
+ }
201
+
202
+ const sinhEtaPrime = Math.sinh(etaPrime);
203
+ const sinXiPrime = Math.sin(xiPrime);
204
+ const cosXiPrime = Math.cos(xiPrime);
205
+ const tauPrime = sinXiPrime / Math.hypot(sinhEtaPrime, cosXiPrime);
206
+
207
+ const oneMinusE2 = 1 - this.eccentricity * this.eccentricity;
208
+ let tau = tauPrime;
209
+ for (let iteration = 0; iteration < MAX_ITERATIONS; iteration++) {
210
+ const tauIPrime = conformalTangent(tau, this.eccentricity);
211
+ const delta =
212
+ ((tauPrime - tauIPrime) / Math.hypot(1, tauIPrime)) * ((1 + oneMinusE2 * tau * tau) / (oneMinusE2 * Math.hypot(1, tau)));
213
+ tau += delta;
214
+ if (Math.abs(delta) <= TAU_TOLERANCE * Math.max(1, Math.abs(tau))) break;
215
+ }
216
+
217
+ target.latitude = Math.atan(tau);
218
+ target.longitude = normalizeLongitudeRadians(this.centralMeridianRadians + Math.atan2(sinhEtaPrime, cosXiPrime));
219
+ target.height = height;
220
+ return target;
221
+ }
222
+
223
+ /**
224
+ * Converts projected coordinates to geodetic coordinates in degrees.
225
+ *
226
+ * @param easting - Easting in metres, including the false easting.
227
+ * @param northing - Northing in metres, including the false northing.
228
+ * @param height - Ellipsoidal height in metres copied to the result. Defaults to 0.
229
+ * @param target - Optional mutable output object, used to avoid an allocation.
230
+ * @returns The target populated with geodetic latitude and longitude in degrees, longitude normalized to `[-180, 180)`.
231
+ */
232
+ public projectedToGeodeticDegrees(easting: number, northing: number, height = 0, target?: IGeodeticCoordinates): IGeodeticCoordinates {
233
+ const result = this.projectedToGeodeticRadians(easting, northing, height, target);
234
+ result.latitude *= RADIANS_TO_DEGREES;
235
+ result.longitude *= RADIANS_TO_DEGREES;
236
+ return result;
237
+ }
238
+ }
package/src/types.ts CHANGED
@@ -44,3 +44,16 @@ export interface ILocalTangentBasis {
44
44
  /** Unit vector normal to the ellipsoid and pointing up. */
45
45
  up: ICartesian3;
46
46
  }
47
+
48
+ /**
49
+ * Mutable projected map coordinate.
50
+ *
51
+ * Eastings increase toward the east and northings toward the north. Both are
52
+ * expressed in metres and include any false easting or false northing.
53
+ */
54
+ export interface IProjectedCoordinates {
55
+ /** Easting in metres. */
56
+ easting: number;
57
+ /** Northing in metres. */
58
+ northing: number;
59
+ }
package/src/utm.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { DEGREES_TO_RADIANS, normalizeLongitudeDegrees } from "./angles";
2
+ import { Ellipsoid } from "./ellipsoid";
3
+ import { TransverseMercatorProjection } from "./transverse-mercator";
4
+
5
+ /** Hemisphere of a UTM zone. `N` uses a false northing of 0 m and `S` a false northing of 10,000,000 m. */
6
+ export type UtmHemisphere = "N" | "S";
7
+
8
+ /** Scale factor on the central meridian of every UTM zone. */
9
+ export const UTM_SCALE_FACTOR = 0.9996;
10
+
11
+ /** False easting of every UTM zone in metres. */
12
+ export const UTM_FALSE_EASTING = 500000;
13
+
14
+ /** False northing of southern UTM zones in metres. */
15
+ export const UTM_SOUTH_FALSE_NORTHING = 10000000;
16
+
17
+ /**
18
+ * Universal Transverse Mercator projection for one zone and hemisphere.
19
+ *
20
+ * Zone `z` is centred on longitude `-183 + 6z` degrees. The ellipsoid must be
21
+ * the one of the horizontal datum: WGS84 for WGS 84, GRS80 for NAD83 and
22
+ * ETRS89. This class does not perform datum transformations.
23
+ */
24
+ export class UtmProjection extends TransverseMercatorProjection {
25
+ /**
26
+ * Creates the projection of a UTM zone.
27
+ *
28
+ * @param zone - UTM zone number from 1 to 60.
29
+ * @param hemisphere - `N` for the northern hemisphere or `S` for the southern hemisphere.
30
+ * @param ellipsoid - Ellipsoid of the horizontal datum. Defaults to WGS84.
31
+ * @throws RangeError When the zone or hemisphere is invalid.
32
+ */
33
+ public constructor(
34
+ public readonly zone: number,
35
+ public readonly hemisphere: UtmHemisphere,
36
+ ellipsoid: Ellipsoid = Ellipsoid.WGS84,
37
+ ) {
38
+ if (!Number.isInteger(zone) || zone < 1 || zone > 60) throw new RangeError("UTM zone must be an integer from 1 to 60.");
39
+ if (hemisphere !== "N" && hemisphere !== "S") throw new RangeError("UTM hemisphere must be N or S.");
40
+ super({
41
+ ellipsoid,
42
+ centralMeridianRadians: utmCentralMeridianDegrees(zone) * DEGREES_TO_RADIANS,
43
+ scaleFactor: UTM_SCALE_FACTOR,
44
+ falseEasting: UTM_FALSE_EASTING,
45
+ falseNorthing: hemisphere === "S" ? UTM_SOUTH_FALSE_NORTHING : 0,
46
+ });
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Returns the central meridian of a UTM zone.
52
+ *
53
+ * @param zone - UTM zone number from 1 to 60.
54
+ * @returns Central meridian longitude in degrees.
55
+ */
56
+ export function utmCentralMeridianDegrees(zone: number): number {
57
+ return -183 + 6 * zone;
58
+ }
59
+
60
+ /**
61
+ * Returns the standard UTM zone containing a geodetic position.
62
+ *
63
+ * Applies the Norway and Svalbard exceptions of the UTM grid.
64
+ *
65
+ * @param latitudeDegrees - Geodetic latitude in degrees.
66
+ * @param longitudeDegrees - Longitude in degrees east of the reference meridian.
67
+ * @returns UTM zone number from 1 to 60.
68
+ */
69
+ export function utmZoneFromDegrees(latitudeDegrees: number, longitudeDegrees: number): number {
70
+ const longitude = normalizeLongitudeDegrees(longitudeDegrees);
71
+ if (latitudeDegrees >= 56 && latitudeDegrees < 64 && longitude >= 3 && longitude < 12) return 32;
72
+ if (latitudeDegrees >= 72 && latitudeDegrees < 84 && longitude >= 0 && longitude < 42) {
73
+ if (longitude < 9) return 31;
74
+ if (longitude < 21) return 33;
75
+ if (longitude < 33) return 35;
76
+ return 37;
77
+ }
78
+ return Math.floor((longitude + 180) / 6) + 1;
79
+ }