@ifc-lite/geo 0.0.0-stage → 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.
Files changed (91) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +301 -2
  3. package/dist/diagnostics.d.ts +16 -0
  4. package/dist/diagnostics.d.ts.map +1 -0
  5. package/dist/diagnostics.js +24 -0
  6. package/dist/diagnostics.js.map +1 -0
  7. package/dist/egm96-undulation-data.d.ts +19 -0
  8. package/dist/egm96-undulation-data.d.ts.map +1 -0
  9. package/dist/egm96-undulation-data.js +18 -0
  10. package/dist/egm96-undulation-data.js.map +1 -0
  11. package/dist/egm96-undulation.d.ts +7 -0
  12. package/dist/egm96-undulation.d.ts.map +1 -0
  13. package/dist/egm96-undulation.js +72 -0
  14. package/dist/egm96-undulation.js.map +1 -0
  15. package/dist/engine-state.d.ts +62 -0
  16. package/dist/engine-state.d.ts.map +1 -0
  17. package/dist/engine-state.js +25 -0
  18. package/dist/engine-state.js.map +1 -0
  19. package/dist/index.d.ts +18 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +20 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/loaders.d.ts +56 -0
  24. package/dist/loaders.d.ts.map +1 -0
  25. package/dist/loaders.js +73 -0
  26. package/dist/loaders.js.map +1 -0
  27. package/dist/map-unit.d.ts +21 -0
  28. package/dist/map-unit.d.ts.map +1 -0
  29. package/dist/map-unit.js +29 -0
  30. package/dist/map-unit.js.map +1 -0
  31. package/dist/precision-grid-data.d.ts +83 -0
  32. package/dist/precision-grid-data.d.ts.map +1 -0
  33. package/dist/precision-grid-data.js +44 -0
  34. package/dist/precision-grid-data.js.map +1 -0
  35. package/dist/precision-grid-table.d.ts +29 -0
  36. package/dist/precision-grid-table.d.ts.map +1 -0
  37. package/dist/precision-grid-table.js +177 -0
  38. package/dist/precision-grid-table.js.map +1 -0
  39. package/dist/precision-grids.d.ts +28 -0
  40. package/dist/precision-grids.d.ts.map +1 -0
  41. package/dist/precision-grids.js +173 -0
  42. package/dist/precision-grids.js.map +1 -0
  43. package/dist/proj4-utils.d.ts +73 -0
  44. package/dist/proj4-utils.d.ts.map +1 -0
  45. package/dist/proj4-utils.js +148 -0
  46. package/dist/proj4-utils.js.map +1 -0
  47. package/dist/proj4.d.ts +17 -0
  48. package/dist/proj4.d.ts.map +1 -0
  49. package/dist/proj4.js +20 -0
  50. package/dist/proj4.js.map +1 -0
  51. package/dist/projected-units.d.ts +17 -0
  52. package/dist/projected-units.d.ts.map +1 -0
  53. package/dist/projected-units.js +49 -0
  54. package/dist/projected-units.js.map +1 -0
  55. package/dist/reproject-point.d.ts +40 -0
  56. package/dist/reproject-point.d.ts.map +1 -0
  57. package/dist/reproject-point.js +88 -0
  58. package/dist/reproject-point.js.map +1 -0
  59. package/dist/resolve-projection.d.ts +85 -0
  60. package/dist/resolve-projection.d.ts.map +1 -0
  61. package/dist/resolve-projection.js +230 -0
  62. package/dist/resolve-projection.js.map +1 -0
  63. package/dist/sanitize-proj4.d.ts +16 -0
  64. package/dist/sanitize-proj4.d.ts.map +1 -0
  65. package/dist/sanitize-proj4.js +133 -0
  66. package/dist/sanitize-proj4.js.map +1 -0
  67. package/dist/spatial-wkt.d.ts +28 -0
  68. package/dist/spatial-wkt.d.ts.map +1 -0
  69. package/dist/spatial-wkt.js +132 -0
  70. package/dist/spatial-wkt.js.map +1 -0
  71. package/dist/transformer.d.ts +97 -0
  72. package/dist/transformer.d.ts.map +1 -0
  73. package/dist/transformer.js +93 -0
  74. package/dist/transformer.js.map +1 -0
  75. package/dist/well-known-crs.d.ts +2 -0
  76. package/dist/well-known-crs.d.ts.map +1 -0
  77. package/dist/well-known-crs.js +25 -0
  78. package/dist/well-known-crs.js.map +1 -0
  79. package/dist/wkt-parameters.d.ts +25 -0
  80. package/dist/wkt-parameters.d.ts.map +1 -0
  81. package/dist/wkt-parameters.js +120 -0
  82. package/dist/wkt-parameters.js.map +1 -0
  83. package/dist/wkt-projection.d.ts +60 -0
  84. package/dist/wkt-projection.d.ts.map +1 -0
  85. package/dist/wkt-projection.js +174 -0
  86. package/dist/wkt-projection.js.map +1 -0
  87. package/dist/wkt.d.ts +7 -0
  88. package/dist/wkt.d.ts.map +1 -0
  89. package/dist/wkt.js +10 -0
  90. package/dist/wkt.js.map +1 -0
  91. package/package.json +69 -3
@@ -0,0 +1,230 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ /**
5
+ * CRS resolution: from the CRS metadata an IFC file (or any other source)
6
+ * carries to a proj4 definition.
7
+ *
8
+ * proj4 definitions are resolved from:
9
+ * 1. The bundled EPSG index (@ifc-lite/data) — covers all 7000+ codes
10
+ * 2. Programmatically constructed (UTM zones, well-known codes)
11
+ * 3. The engine's EPSG definition loader as last resort (`configureCrsLoaders`)
12
+ */
13
+ import { lookupEpsgByCode } from '@ifc-lite/data';
14
+ import { reportCrsDiagnostic } from './diagnostics.js';
15
+ import { defaultEngineState } from './engine-state.js';
16
+ import { PRECISION_GRIDS, resolvePrecisionDef } from './precision-grids.js';
17
+ import { isGeographicProj4, projectedDefinitionInMetres, utmProj4String } from './proj4-utils.js';
18
+ import { sanitizeProj4 } from './sanitize-proj4.js';
19
+ import { wellKnownCrsCode } from './well-known-crs.js';
20
+ import { resolveWktProjection, withWktExtent } from './wkt-projection.js';
21
+ /**
22
+ * Extract EPSG numeric code from a CRS name like "EPSG:32632" or "EPSG 2056".
23
+ */
24
+ function extractEpsgCode(crs) {
25
+ const match = crs.name?.match(/EPSG[:\s]*(\d+)/i);
26
+ return match ? match[1] : null;
27
+ }
28
+ /**
29
+ * The EPSG code a CRS resolves through, when it names one: the identifier in
30
+ * its WKT, an `EPSG:<code>` name, or a well-known alias. `null` for a CRS
31
+ * defined by its WKT alone or by UTM metadata.
32
+ */
33
+ export function declaredEpsgCode(crs) {
34
+ const wkt = crs.wellKnownText ? resolveWktProjection(crs.wellKnownText) : null;
35
+ if (wkt)
36
+ return wkt.kind === 'epsg' ? wkt.code : null;
37
+ return extractEpsgCode(crs) ?? wellKnownCrsCode(crs.name ?? '') ?? null;
38
+ }
39
+ /** Skip blank or invalid zone metadata before trying the next source. */
40
+ function utmDefinitionFromMetadata(crs) {
41
+ const candidates = [crs.mapZone, ...[crs.name, crs.description, crs.mapProjection]
42
+ .map(value => value?.match(/UTM\s+zone\s+(\d{1,2}[NS])/i)?.[1])];
43
+ for (const zone of candidates) {
44
+ const definition = zone ? utmProj4String(zone) : null;
45
+ if (definition)
46
+ return definition;
47
+ }
48
+ return null;
49
+ }
50
+ /** A definition that uses the CRS's own operation. */
51
+ function asDefined(definition) {
52
+ return { definition, datumShift: 'as-defined' };
53
+ }
54
+ /**
55
+ * Resolve a proj4 definition for the given CRS metadata, through the default
56
+ * engine. See {@link resolveDefinition} for the order.
57
+ */
58
+ export async function resolveProjection(crs) {
59
+ return (await resolveDefinition(crs, defaultEngineState()))?.definition ?? null;
60
+ }
61
+ /**
62
+ * Resolve a proj4 definition, and how its datum shift is obtained, for the
63
+ * given CRS metadata.
64
+ *
65
+ * An `IfcWellKnownText` definition is authoritative over the name (which may
66
+ * then be a placeholder such as "WKT"): an EPSG identifier it names resolves
67
+ * through the order below, otherwise the WKT itself is the definition. A WKT
68
+ * that cannot be read falls back to the name; one that was read without a
69
+ * parameter its projection needs resolves to `null`.
70
+ *
71
+ * Resolution order:
72
+ * 1. Cache hit
73
+ * 2. Precision grid (NTv2/GeoTIFF) for codes where +towgs84 is too coarse
74
+ * (RD/NL, OSGB/UK, BD72/BE) — loaded once through the engine's grid
75
+ * loader, gives sub-decimeter accuracy. Falls through to (3) when no
76
+ * loader is installed or the load fails.
77
+ * 3. Bundled EPSG index (7000+ codes with proj4 strings)
78
+ * 4. UTM zone heuristic (from CRS metadata — mapZone, name, description, mapProjection)
79
+ * 5. The engine's EPSG definition loader (epsg.io when the host installs
80
+ * `epsgIoDefinitionLoader`; skipped when none is installed)
81
+ *
82
+ * The datum-shift verdict travels with the definition it describes, so a
83
+ * concurrent resolution that loads a grid cannot change what an earlier
84
+ * result says about itself.
85
+ */
86
+ export async function resolveDefinition(crs, state) {
87
+ if (crs.wellKnownText) {
88
+ const wkt = resolveWktProjection(crs.wellKnownText);
89
+ if (wkt?.kind === 'definition')
90
+ return asDefined(wkt.definition);
91
+ // A WKT the reader lost a parameter of is refused outright: falling back
92
+ // to the name would put this custom CRS on the registry projection's
93
+ // meridian. A WKT that cannot be read at all still falls back below.
94
+ if (wkt?.kind === 'refused')
95
+ return null;
96
+ const named = { ...crs, wellKnownText: undefined };
97
+ const resolved = await resolveDefinition(wkt?.kind === 'epsg' ? { ...named, name: `EPSG:${wkt.code}` } : named, state);
98
+ if (!resolved || wkt?.kind !== 'epsg')
99
+ return resolved;
100
+ // The WKT's own datum shift and declared extent still apply to the registry
101
+ // projection. A shift the WKT states is its author's operation, so it is
102
+ // as defined even where the registry's own would be an approximation.
103
+ return wkt.towgs84
104
+ ? asDefined(withWktExtent(crs.wellKnownText, `${resolved.definition.replace(/\s\+(?:towgs84|nadgrids)=\S+/g, '')} +towgs84=${wkt.towgs84}`))
105
+ : { ...resolved, definition: withWktExtent(crs.wellKnownText, resolved.definition) };
106
+ }
107
+ const explicitCode = extractEpsgCode(crs);
108
+ const aliasCode = explicitCode ? undefined : wellKnownCrsCode(crs.name ?? '');
109
+ // A datum-only geographic label may accompany an explicit UTM zone. Keep
110
+ // that metadata interpretation local; caching it under EPSG:4326 would
111
+ // corrupt subsequent geographic resolutions and make results load-order dependent.
112
+ if (aliasCode && ['4326', '4269', '4267', '4258'].includes(aliasCode)) {
113
+ const utm = utmDefinitionFromMetadata(crs);
114
+ if (utm) {
115
+ // Retain the declared datum rather than changing NAD27/NAD83/ETRS89
116
+ // coordinates into WGS84 UTM. Cache only the native geographic CRS.
117
+ const geographic = await resolveDefinition({ name: `EPSG:${aliasCode}` }, state);
118
+ if (!geographic || !isGeographicProj4(geographic.definition))
119
+ return null;
120
+ const zoneParameters = utm.match(/\+zone=\d+(?: \+south)?/)?.[0];
121
+ if (!zoneParameters)
122
+ return null;
123
+ return {
124
+ ...geographic,
125
+ definition: projectedDefinitionInMetres(geographic.definition.replace(/\+proj=longlat\b/, `+proj=utm ${zoneParameters}`)),
126
+ };
127
+ }
128
+ }
129
+ const code = explicitCode ?? aliasCode ?? null;
130
+ const cache = state.definitions;
131
+ // 1. Check cache
132
+ // A cached approximate/refused fallback is not terminal for a CRS with a
133
+ // precision grid: a later online attempt may populate the grid cache. Exact
134
+ // cached definitions remain fast and deterministic.
135
+ const cached = code ? cache.get(code) : undefined;
136
+ if (cached && (!PRECISION_GRIDS[code] || cached.datumShift === 'as-defined'))
137
+ return cached;
138
+ // 2. Precision grid (NTv2/GeoTIFF). For Bessel-based national grids
139
+ // (RD/NL, BD72/BE, OSGB/UK), the +towgs84 approximation that the bundled
140
+ // entries carry is off by 80-200 m. proj4js can consume PROJ's GeoTIFF
141
+ // datum-shift grids — load and register, then use a +nadgrids-based
142
+ // proj4 string for sub-decimeter accuracy.
143
+ // A listed precision grid is a required operation for placement: without
144
+ // it, the bundled Helmert below may still serve a map preview, but is
145
+ // never an exact result and `resolveProjectionOperation` refuses it by default.
146
+ let gridRequired = false;
147
+ if (code && PRECISION_GRIDS[code]) {
148
+ gridRequired = true;
149
+ try {
150
+ const precisionDef = await resolvePrecisionDef(code, state);
151
+ if (precisionDef) {
152
+ const exact = asDefined(precisionDef);
153
+ cache.set(code, exact);
154
+ return exact;
155
+ }
156
+ }
157
+ catch (error) {
158
+ reportCrsDiagnostic(`[reproject] precision grid resolution failed for EPSG:${code}, falling back`, error);
159
+ }
160
+ }
161
+ /** A grid-listed CRS without its grid is at best an approximation. */
162
+ const withoutGrid = (resolved) => gridRequired && resolved.datumShift === 'as-defined' ? { ...resolved, datumShift: 'helmert-approximation' } : resolved;
163
+ // 3. Bundled EPSG index (primary source — all 7000+ codes)
164
+ if (code) {
165
+ try {
166
+ const entry = await lookupEpsgByCode(code);
167
+ if (entry?.proj4) {
168
+ const sanitized = withoutGrid(sanitizeProj4(entry.proj4, code, entry.datum));
169
+ cache.set(code, sanitized);
170
+ return sanitized;
171
+ }
172
+ }
173
+ catch (error) {
174
+ reportCrsDiagnostic(`[reproject] EPSG index lookup failed for EPSG:${code}`, error);
175
+ }
176
+ }
177
+ // 4. UTM zone heuristic — check mapZone, name, description, AND mapProjection
178
+ const utm = utmDefinitionFromMetadata(crs);
179
+ if (utm) {
180
+ const resolved = withoutGrid(asDefined(utm));
181
+ if (code)
182
+ cache.set(code, resolved);
183
+ return resolved;
184
+ }
185
+ // 5. Last resort — the engine's EPSG definition loader (epsg.io in the viewer)
186
+ if (code) {
187
+ const raw = await state.loaders.epsgDefinition?.(code) ?? null;
188
+ // We don't have a bundled EpsgIndexEntry here (otherwise we'd have hit
189
+ // step 3), so there is no datum name to key a fallback shift on.
190
+ // Only positive-cache a successful result, so a transient network
191
+ // failure (offline/CDN hiccup/timeout) can be retried later instead of
192
+ // permanently poisoning this EPSG code for the rest of the session.
193
+ const fetched = raw ? withoutGrid(sanitizeProj4(raw, code, null)) : null;
194
+ if (fetched)
195
+ cache.set(code, fetched);
196
+ return fetched;
197
+ }
198
+ return null;
199
+ }
200
+ /**
201
+ * Resolve a placement operation with its accuracy provenance. Unlike map
202
+ * display, federation has no safe implicit approximation: callers must opt in
203
+ * to the documented Helmert fallback, and a grid with no fallback is refused.
204
+ */
205
+ export async function resolveProjectionOperation(id, options = {}) {
206
+ if (!/^EPSG:\d+$/i.test(id.trim()))
207
+ return { kind: 'refused', reason: 'unresolvable' };
208
+ const canonical = id.trim().toUpperCase();
209
+ const resolved = await resolveDefinition({ name: canonical }, defaultEngineState());
210
+ if (!resolved)
211
+ return { kind: 'refused', reason: 'unresolvable' };
212
+ const { definition, datumShift } = resolved;
213
+ if (datumShift === 'grid-unavailable')
214
+ return { kind: 'refused', reason: 'required-grid-unavailable' };
215
+ if (datumShift === 'helmert-approximation') {
216
+ return options.allowApproximate
217
+ ? { kind: 'approximate', definition, provenance: 'helmert-fallback' }
218
+ : { kind: 'refused', reason: 'approximation-not-authorized' };
219
+ }
220
+ return {
221
+ kind: 'exact',
222
+ definition,
223
+ provenance: definition.includes('+nadgrids=') ? 'cached-grid' : 'bundled',
224
+ };
225
+ }
226
+ export async function resolveProjectionId(id, options = {}) {
227
+ const operation = await resolveProjectionOperation(id, options);
228
+ return operation.kind === 'refused' ? null : operation.definition;
229
+ }
230
+ //# sourceMappingURL=resolve-projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-projection.js","sourceRoot":"","sources":["../src/resolve-projection.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAA6C,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAoB1E;;GAEG;AACH,SAAS,eAAe,CAAC,GAAkB;IACzC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAA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AC;AACpE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ResolvedDefinition } from './engine-state.js';
2
+ /**
3
+ * Strip +nadgrids=... from a proj4 string and add a +towgs84 approximation
4
+ * keyed by the datum name from the bundled EPSG index. Grid files cannot be
5
+ * loaded in the browser; +towgs84 is the standard fallback.
6
+ *
7
+ * Skipped (returns input verbatim) when:
8
+ * - No +nadgrids reference (or it's the no-op `@null`)
9
+ * - A +towgs84 is already present (proj4 will honour it)
10
+ *
11
+ * `datumShift` is `helmert-approximation` when a 7-parameter shift stands in
12
+ * for a grid (or for a shift the definition omits), `grid-unavailable` when a
13
+ * required grid was dropped with nothing to replace it.
14
+ */
15
+ export declare function sanitizeProj4(def: string, code?: string | null, datumName?: string | null): ResolvedDefinition;
16
+ //# sourceMappingURL=sanitize-proj4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-proj4.d.ts","sourceRoot":"","sources":["../src/sanitize-proj4.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAmE5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,kBAAkB,CAuD9G"}
@@ -0,0 +1,133 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ /**
5
+ * Datum-shift fallbacks for definitions whose canonical datum operation is a
6
+ * grid file proj4js cannot read. Each result says which fallback it took, so
7
+ * the caller holds that verdict together with the definition.
8
+ */
9
+ import { reportCrsDiagnostic } from './diagnostics.js';
10
+ // Diagnostics are reported once per code or datum per process.
11
+ const approxDatumWarningCache = new Set();
12
+ // Track datums where the bundled proj4 lacked any datum-shift parameters and we
13
+ // couldn't supply a fallback — surfaced via diagnostics, warned once per datum.
14
+ const unknownDatumWarningCache = new Set();
15
+ /**
16
+ * Datum-keyed +towgs84 approximations for CRSs whose canonical definition
17
+ * relies on browser-unavailable grid files (NTv2, NADCON, etc.). Each entry
18
+ * is the published Bursa-Wolf 7-parameter set for that specific datum, in
19
+ * the Position Vector convention proj4 expects, with rotations in arc-seconds.
20
+ *
21
+ * Keys are lowercased datum names as they appear in EpsgIndexEntry.datum. A
22
+ * lookup miss is intentional — it forces sanitizeProj4 to emit a diagnostic
23
+ * rather than silently substitute parameters for the wrong region (an earlier
24
+ * version of this table was keyed by ellipsoid alone, which caused every
25
+ * Bessel-1841 CRS — RD/NL, Hermannskogel/AT, S-JTSK/CZ — to inherit Germany's
26
+ * DHDN shift). Accuracy is typically ~1-5 m, sufficient for map display.
27
+ */
28
+ const DATUM_TOWGS84 = {
29
+ // United Kingdom — OSGB36 (Airy 1830). The bundled EPSG index (packages/data)
30
+ // reports this datum as the bare "OSGB36" for EPSG:27700 — keep both forms
31
+ // keyed since IFC files and EPSG metadata are inconsistent about which one
32
+ // they emit.
33
+ 'osgb 1936': '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489',
34
+ 'osgb36': '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489',
35
+ // North America — NAD27 (Clarke 1866)
36
+ 'north american datum 1927': '+towgs84=-8,160,176,0,0,0,0',
37
+ 'nad27': '+towgs84=-8,160,176,0,0,0,0',
38
+ // NAD83 ≈ WGS84 to within ~1 m; identity is the standard browser approximation.
39
+ 'north american datum 1983': '+towgs84=0,0,0,0,0,0,0',
40
+ 'nad83': '+towgs84=0,0,0,0,0,0,0',
41
+ // Germany — DHDN (Bessel 1841)
42
+ 'deutsches hauptdreiecksnetz': '+towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7',
43
+ 'dhdn': '+towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7',
44
+ // Netherlands — Amersfoort (Bessel 1841). The bundled EPSG:28992 already
45
+ // ships with the higher-precision Kadaster +towgs84, so this fires only
46
+ // when a derived/compound CRS lacks it (e.g. some compound RD/NAP cases).
47
+ // The compound EPSG:7415 (RD + NAP height) reports its datum as "RD" rather
48
+ // than "Amersfoort", and its bundled proj4 carries no +towgs84 at all, so it
49
+ // needs the same shift under that key for the offline (no precision-grid)
50
+ // fallback to land in the Netherlands instead of ~117 m off.
51
+ 'amersfoort': '+towgs84=565.4171,50.3319,465.5524,1.9342,-1.6677,9.1019,4.0725',
52
+ 'rd': '+towgs84=565.4171,50.3319,465.5524,1.9342,-1.6677,9.1019,4.0725',
53
+ // Austria — MGI (Bessel 1841)
54
+ 'militar-geographische institut': '+towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232',
55
+ 'mgi': '+towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232',
56
+ // Czech Republic — S-JTSK (Bessel 1841). EPSG:2065 (Ferro Krovak) — the
57
+ // exact code #1357 was filed against, and the only S-JTSK code with no
58
+ // precision-grid coverage (see precision-grids.ts) so this fallback is its
59
+ // ONLY datum shift — reports its datum as "S-JTSK (Ferro)" in the bundled
60
+ // EPSG index, not the bare "S-JTSK" below. Without this key the lookup
61
+ // silently missed (no warning either, since there's no +nadgrids to trigger
62
+ // one) and EPSG:2065 got zero datum shift.
63
+ 'system of the unified trigonometrical cadastral network': '+towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56',
64
+ 's-jtsk': '+towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56',
65
+ 's-jtsk (ferro)': '+towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56',
66
+ // New Zealand — NZGD49 (International 1924)
67
+ 'new zealand geodetic datum 1949': '+towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993',
68
+ 'nzgd49': '+towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993',
69
+ // Australia — AGD84 (Australian National Spheroid)
70
+ 'australian geodetic datum 1984': '+towgs84=-117.763,-51.51,139.061,0.292,0.443,0.277,-0.191',
71
+ 'agd84': '+towgs84=-117.763,-51.51,139.061,0.292,0.443,0.277,-0.191',
72
+ };
73
+ /**
74
+ * Strip +nadgrids=... from a proj4 string and add a +towgs84 approximation
75
+ * keyed by the datum name from the bundled EPSG index. Grid files cannot be
76
+ * loaded in the browser; +towgs84 is the standard fallback.
77
+ *
78
+ * Skipped (returns input verbatim) when:
79
+ * - No +nadgrids reference (or it's the no-op `@null`)
80
+ * - A +towgs84 is already present (proj4 will honour it)
81
+ *
82
+ * `datumShift` is `helmert-approximation` when a 7-parameter shift stands in
83
+ * for a grid (or for a shift the definition omits), `grid-unavailable` when a
84
+ * required grid was dropped with nothing to replace it.
85
+ */
86
+ export function sanitizeProj4(def, code, datumName) {
87
+ const stripNadgrids = (s) => s.replace(/\+nadgrids=\S+/g, '').replace(/\s+/g, ' ').trim();
88
+ const hasNadgrids = def.includes('+nadgrids') && !def.includes('+nadgrids=@null');
89
+ const hasTowgs84 = /\+towgs84=/.test(def);
90
+ // An embedded Helmert is an explicit approximation only when it replaces a
91
+ // required grid. The old code stripped the grid and then represented this
92
+ // result as an ordinary definition, allowing federation to claim exact CRS
93
+ // placement while silently losing metres of accuracy.
94
+ if (hasTowgs84) {
95
+ return hasNadgrids
96
+ ? { definition: stripNadgrids(def), datumShift: 'helmert-approximation' }
97
+ : { definition: def, datumShift: 'as-defined' };
98
+ }
99
+ const datumKey = datumName?.trim().toLowerCase() ?? '';
100
+ const towgs84 = datumKey ? DATUM_TOWGS84[datumKey] : undefined;
101
+ if (!towgs84) {
102
+ // No known fallback shift. For a grid-referencing def, warn + strip the
103
+ // unusable reference. For a plain def we leave it untouched (its datum may
104
+ // already be WGS84-aligned, or simply unknown to us).
105
+ if (hasNadgrids && datumKey && !unknownDatumWarningCache.has(datumKey)) {
106
+ unknownDatumWarningCache.add(datumKey);
107
+ reportCrsDiagnostic(`[reproject] EPSG:${code ?? '?'} ("${datumName}") needs browser-unavailable `
108
+ + 'datum grids and has no known +towgs84 fallback for its datum. '
109
+ + 'Positions will be aligned to the source CRS but may be tens of metres '
110
+ + 'off relative to WGS84/basemaps. Consider adding the datum to '
111
+ + 'DATUM_TOWGS84 in packages/geo/src/sanitize-proj4.ts.');
112
+ }
113
+ return hasNadgrids
114
+ ? { definition: stripNadgrids(def), datumShift: 'grid-unavailable' }
115
+ : { definition: def, datumShift: 'as-defined' };
116
+ }
117
+ // We have a +towgs84 for this datum and the def carries none. Apply it. This
118
+ // covers a +nadgrids grid we can't load (strip + approximate) AND a bundled
119
+ // def that simply omits the shift for an offset datum — e.g. Ferro Krovak
120
+ // (EPSG:2065) / S-JTSK, where without it proj4 performs no datum shift at
121
+ // all and the model lands hundreds of metres off the basemap. (#1357)
122
+ if (code && !approxDatumWarningCache.has(code)) {
123
+ approxDatumWarningCache.add(code);
124
+ reportCrsDiagnostic(`[reproject] EPSG:${code} ("${datumName}") uses an approximate +towgs84 `
125
+ + 'datum shift (browser-unavailable precision grid). '
126
+ + 'Expect metre-level XY differences for some locations.');
127
+ }
128
+ return {
129
+ definition: `${hasNadgrids ? stripNadgrids(def) : def.replace(/\s+/g, ' ').trim()} ${towgs84}`,
130
+ datumShift: 'helmert-approximation',
131
+ };
132
+ }
133
+ //# sourceMappingURL=sanitize-proj4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-proj4.js","sourceRoot":"","sources":["../src/sanitize-proj4.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvD,+DAA+D;AAC/D,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAAU,CAAC;AAClD,gFAAgF;AAChF,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAU,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAA2B;IAC5C,8EAA8E;IAC9E,2EAA2E;IAC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IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,mBAAmB,CACjB,oBAAoB,IAAI,MAAM,SAAS,kCAAkC;cACvE,oDAAoD;cACpD,uDAAuD,CAC1D,CAAC;IACJ,CAAC;IAED,OAAO;QACL,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,OAAO,EAAE;QAC9F,UAAU,EAAE,uBAAuB;KACpC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** Explicit CRS identifiers read from WKT1/WKT2 without guessing a CRS. */
2
+ export interface WktCrsIdentifiers {
3
+ horizontalId?: string;
4
+ verticalId?: string;
5
+ }
6
+ export type WktAxisDirection = 'east' | 'west' | 'north' | 'south' | 'up' | 'down';
7
+ export interface WktSpatialMetadata extends WktCrsIdentifiers {
8
+ axes?: readonly [WktAxisDirection, WktAxisDirection, WktAxisDirection];
9
+ horizontalUnitToMetres?: number;
10
+ verticalUnitToMetres?: number;
11
+ }
12
+ export declare function extractWktSpatialMetadata(wkt: string): WktSpatialMetadata;
13
+ export declare function extractWktCrsIdentifiers(wkt: string): WktCrsIdentifiers;
14
+ /**
15
+ * The horizontal CRS a WKT describes, as WKT text: a COMPOUNDCRS/COMPD_CS's
16
+ * BOUNDCRS/PROJCRS/GEOGCRS child (or an adjacent top-level one), else the root itself.
17
+ * Lets a projection library that reads only single CRSs take a compound one.
18
+ */
19
+ export declare function extractWktHorizontalCrs(wkt: string): string | undefined;
20
+ /** WKT2 extent `BBOX[south, west, north, east]` (degrees), owned by the root CRS or its USAGE. */
21
+ export interface WktBoundingBox {
22
+ south: number;
23
+ west: number;
24
+ north: number;
25
+ east: number;
26
+ }
27
+ export declare function extractWktBoundingBox(wkt: string): WktBoundingBox | undefined;
28
+ //# sourceMappingURL=spatial-wkt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spatial-wkt.d.ts","sourceRoot":"","sources":["../src/spatial-wkt.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAAG,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE;AACjF,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AACnF,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;IACvE,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAsED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAwBzE;AACD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAGvE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOvE;AAED,kGAAkG;AAClG,MAAM,WAAW,cAAc;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAC5F,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAS7E"}
@@ -0,0 +1,132 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ /** Balanced lexical nodes; metadata is read only from direct owned children. */
5
+ function nodes(text) {
6
+ const result = [];
7
+ for (let index = 0; index < text.length;) {
8
+ const match = /([A-Za-z_][A-Za-z_0-9]*)\s*\[/.exec(text.slice(index));
9
+ if (!match)
10
+ break;
11
+ const start = index + match.index, bodyStart = start + match[0].length;
12
+ let depth = 1, quote = false, cursor = bodyStart;
13
+ for (; cursor < text.length && depth > 0; cursor += 1) {
14
+ const char = text[cursor];
15
+ if (char === '"')
16
+ quote = !quote;
17
+ else if (!quote && char === '[')
18
+ depth += 1;
19
+ else if (!quote && char === ']')
20
+ depth -= 1;
21
+ }
22
+ if (depth !== 0)
23
+ break;
24
+ result.push({ name: match[1].toUpperCase(), body: text.slice(bodyStart, cursor - 1) });
25
+ index = cursor;
26
+ }
27
+ return result;
28
+ }
29
+ function direct(body, names) {
30
+ const allowed = new Set(names);
31
+ return nodes(body).find((node) => allowed.has(node.name));
32
+ }
33
+ function root(wkt) { return nodes(wkt)[0]; }
34
+ function epsg(node) {
35
+ const owned = node && direct(node.body, ['ID', 'AUTHORITY']);
36
+ const code = owned?.body.match(/^\s*["']EPSG["']\s*,\s*["']?(\d+)/i)?.[1];
37
+ return code ? `EPSG:${code}` : undefined;
38
+ }
39
+ function axes(node) {
40
+ return node ? nodes(node.body).filter((child) => child.name === 'AXIS')
41
+ .map((child) => /^[^,]*,\s*(east|west|north|south|up|down)\b/i.exec(child.body)?.[1]?.toLowerCase())
42
+ .filter((value) => value !== undefined) : [];
43
+ }
44
+ function unitFactor(node) {
45
+ const number = Number(node && /,\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/i.exec(node.body)?.[1]);
46
+ return Number.isFinite(number) && number > 0 ? number : undefined;
47
+ }
48
+ /**
49
+ * WKT2 allows LENGTHUNIT to belong to each AXIS rather than to the CRS. Keep
50
+ * every owned candidate: picking the first silently turns a conflicting CRS
51
+ * declaration into metres (or whichever axis happened to be first).
52
+ */
53
+ function unit(node) {
54
+ if (!node)
55
+ return undefined;
56
+ // WKT1 GEOGCS owns an angular UNIT. It must never be interpreted as a
57
+ // metres-per-coordinate factor for a point cloud.
58
+ const names = node.name === 'GEOGCS' || node.name === 'GEOGCRS'
59
+ ? ['LENGTHUNIT']
60
+ : ['LENGTHUNIT', 'UNIT'];
61
+ const candidates = [
62
+ ...nodes(node.body)
63
+ .filter((child) => names.includes(child.name))
64
+ .map(unitFactor),
65
+ ...nodes(node.body)
66
+ .filter((child) => child.name === 'AXIS')
67
+ .flatMap((axis) => nodes(axis.body)
68
+ .filter((child) => names.includes(child.name))
69
+ .map(unitFactor)),
70
+ ];
71
+ if (candidates.length === 0 || candidates.some((value) => value === undefined))
72
+ return undefined;
73
+ const first = candidates[0];
74
+ return candidates.every((value) => value === first) ? first : undefined;
75
+ }
76
+ export function extractWktSpatialMetadata(wkt) {
77
+ const document = root(wkt);
78
+ if (!document)
79
+ return {};
80
+ const compound = ['COMPOUNDCRS', 'COMPD_CS'].includes(document.name) ? document : undefined;
81
+ const scope = compound?.body ?? wkt;
82
+ // E57 coordinateMetadata commonly stores adjacent top-level PROJCRS and
83
+ // VERTCRS nodes rather than wrapping them in COMPOUNDCRS.
84
+ const horizontal = direct(scope, ['PROJCRS', 'PROJCS', 'GEOGCRS', 'GEOGCS']);
85
+ const vertical = direct(scope, ['VERTCRS', 'VERT_CS']);
86
+ const horizontalAxes = axes(horizontal).filter((value) => value !== 'up' && value !== 'down');
87
+ // LAS has a third Z ordinate; when WKT describes only its horizontal CRS,
88
+ // retain its documented positive-height convention rather than borrowing a
89
+ // nested GEOGCS axis. A declared VERTCRS still owns the direction.
90
+ const verticalAxis = axes(vertical ?? horizontal).find((value) => value === 'up' || value === 'down')
91
+ ?? (!vertical ? 'up' : undefined);
92
+ const frame = horizontalAxes.length === 2 && new Set(horizontalAxes).size === 2 && verticalAxis
93
+ ? [horizontalAxes[0], horizontalAxes[1], verticalAxis] : undefined;
94
+ const horizontalId = epsg(horizontal), verticalId = epsg(vertical);
95
+ const horizontalUnitToMetres = unit(horizontal), verticalUnitToMetres = unit(vertical);
96
+ return {
97
+ ...(horizontalId ? { horizontalId } : {}), ...(verticalId ? { verticalId } : {}),
98
+ ...(frame ? { axes: frame } : {}), ...(horizontalUnitToMetres ? { horizontalUnitToMetres } : {}),
99
+ ...(verticalUnitToMetres ? { verticalUnitToMetres } : {}),
100
+ };
101
+ }
102
+ export function extractWktCrsIdentifiers(wkt) {
103
+ const { horizontalId, verticalId } = extractWktSpatialMetadata(wkt);
104
+ return { ...(horizontalId ? { horizontalId } : {}), ...(verticalId ? { verticalId } : {}) };
105
+ }
106
+ /**
107
+ * The horizontal CRS a WKT describes, as WKT text: a COMPOUNDCRS/COMPD_CS's
108
+ * BOUNDCRS/PROJCRS/GEOGCRS child (or an adjacent top-level one), else the root itself.
109
+ * Lets a projection library that reads only single CRSs take a compound one.
110
+ */
111
+ export function extractWktHorizontalCrs(wkt) {
112
+ const document = root(wkt);
113
+ if (!document)
114
+ return undefined;
115
+ const compound = ['COMPOUNDCRS', 'COMPD_CS'].includes(document.name) ? document : undefined;
116
+ // A BOUNDCRS is kept whole: its ABRIDGEDTRANSFORMATION is the datum shift.
117
+ const horizontal = direct(compound?.body ?? wkt, ['BOUNDCRS', 'PROJCRS', 'PROJCS', 'GEOGCRS', 'GEOGCS', 'PROJECTEDCRS', 'GEODCRS']);
118
+ return horizontal ? `${horizontal.name}[${horizontal.body}]` : undefined;
119
+ }
120
+ export function extractWktBoundingBox(wkt) {
121
+ const document = root(wkt);
122
+ if (!document)
123
+ return undefined;
124
+ const owner = direct(document.body, ['USAGE'])?.body ?? document.body;
125
+ const box = direct(owner, ['BBOX']);
126
+ const values = box?.body.split(',').map((value) => Number(value.trim()));
127
+ if (!values || values.length !== 4 || !values.every(Number.isFinite))
128
+ return undefined;
129
+ const [south, west, north, east] = values;
130
+ return south <= north ? { south, west, north, east } : undefined;
131
+ }
132
+ //# sourceMappingURL=spatial-wkt.js.map
@@ -0,0 +1 @@
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