@ifc-lite/geo 0.0.0-stage → 0.1.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/LICENSE +373 -0
- package/README.md +294 -2
- package/dist/diagnostics.d.ts +16 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +24 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/egm96-undulation-data.d.ts +19 -0
- package/dist/egm96-undulation-data.d.ts.map +1 -0
- package/dist/egm96-undulation-data.js +18 -0
- package/dist/egm96-undulation-data.js.map +1 -0
- package/dist/egm96-undulation.d.ts +7 -0
- package/dist/egm96-undulation.d.ts.map +1 -0
- package/dist/egm96-undulation.js +72 -0
- package/dist/egm96-undulation.js.map +1 -0
- package/dist/engine-state.d.ts +62 -0
- package/dist/engine-state.d.ts.map +1 -0
- package/dist/engine-state.js +25 -0
- package/dist/engine-state.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders.d.ts +56 -0
- package/dist/loaders.d.ts.map +1 -0
- package/dist/loaders.js +73 -0
- package/dist/loaders.js.map +1 -0
- package/dist/map-unit.d.ts +21 -0
- package/dist/map-unit.d.ts.map +1 -0
- package/dist/map-unit.js +29 -0
- package/dist/map-unit.js.map +1 -0
- package/dist/precision-grid-data.d.ts +83 -0
- package/dist/precision-grid-data.d.ts.map +1 -0
- package/dist/precision-grid-data.js +44 -0
- package/dist/precision-grid-data.js.map +1 -0
- package/dist/precision-grid-table.d.ts +29 -0
- package/dist/precision-grid-table.d.ts.map +1 -0
- package/dist/precision-grid-table.js +177 -0
- package/dist/precision-grid-table.js.map +1 -0
- package/dist/precision-grids.d.ts +28 -0
- package/dist/precision-grids.d.ts.map +1 -0
- package/dist/precision-grids.js +173 -0
- package/dist/precision-grids.js.map +1 -0
- package/dist/proj4-utils.d.ts +73 -0
- package/dist/proj4-utils.d.ts.map +1 -0
- package/dist/proj4-utils.js +148 -0
- package/dist/proj4-utils.js.map +1 -0
- package/dist/proj4.d.ts +17 -0
- package/dist/proj4.d.ts.map +1 -0
- package/dist/proj4.js +20 -0
- package/dist/proj4.js.map +1 -0
- package/dist/projected-units.d.ts +17 -0
- package/dist/projected-units.d.ts.map +1 -0
- package/dist/projected-units.js +49 -0
- package/dist/projected-units.js.map +1 -0
- package/dist/reproject-point.d.ts +40 -0
- package/dist/reproject-point.d.ts.map +1 -0
- package/dist/reproject-point.js +88 -0
- package/dist/reproject-point.js.map +1 -0
- package/dist/resolve-projection.d.ts +85 -0
- package/dist/resolve-projection.d.ts.map +1 -0
- package/dist/resolve-projection.js +230 -0
- package/dist/resolve-projection.js.map +1 -0
- package/dist/sanitize-proj4.d.ts +16 -0
- package/dist/sanitize-proj4.d.ts.map +1 -0
- package/dist/sanitize-proj4.js +133 -0
- package/dist/sanitize-proj4.js.map +1 -0
- package/dist/spatial-wkt.d.ts +28 -0
- package/dist/spatial-wkt.d.ts.map +1 -0
- package/dist/spatial-wkt.js +132 -0
- package/dist/spatial-wkt.js.map +1 -0
- package/dist/transformer.d.ts +97 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +93 -0
- package/dist/transformer.js.map +1 -0
- package/dist/well-known-crs.d.ts +2 -0
- package/dist/well-known-crs.d.ts.map +1 -0
- package/dist/well-known-crs.js +25 -0
- package/dist/well-known-crs.js.map +1 -0
- package/dist/wkt-parameters.d.ts +25 -0
- package/dist/wkt-parameters.d.ts.map +1 -0
- package/dist/wkt-parameters.js +120 -0
- package/dist/wkt-parameters.js.map +1 -0
- package/dist/wkt-projection.d.ts +60 -0
- package/dist/wkt-projection.d.ts.map +1 -0
- package/dist/wkt-projection.js +174 -0
- package/dist/wkt-projection.js.map +1 -0
- package/dist/wkt.d.ts +7 -0
- package/dist/wkt.d.ts.map +1 -0
- package/dist/wkt.js +10 -0
- package/dist/wkt.js.map +1 -0
- package/package.json +69 -3
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
import proj4 from 'proj4';
|
|
5
|
+
import { reportCrsDiagnostic } from './diagnostics.js';
|
|
6
|
+
import { isWktDefinition, registeredWktDefinition, wktDefinitionInMetres } from './wkt-projection.js';
|
|
7
|
+
/** Also answers for a WKT definition registered by `resolveWktProjection`. */
|
|
8
|
+
export function isGeographicProj4(definition) {
|
|
9
|
+
if (isWktDefinition(definition))
|
|
10
|
+
return registeredWktDefinition(definition)?.projName === 'longlat';
|
|
11
|
+
return /\+proj=longlat\b/.test(definition);
|
|
12
|
+
}
|
|
13
|
+
export function utmProj4String(zone) {
|
|
14
|
+
const match = zone.match(/^(\d{1,2})([NS])$/i);
|
|
15
|
+
if (!match)
|
|
16
|
+
return null;
|
|
17
|
+
const zoneNumber = parseInt(match[1], 10);
|
|
18
|
+
if (zoneNumber < 1 || zoneNumber > 60)
|
|
19
|
+
return null;
|
|
20
|
+
return `+proj=utm +zone=${zoneNumber}${match[2].toUpperCase() === 'N' ? '' : ' +south'} +datum=WGS84 +units=m +no_defs`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Geometry and spatial references carry projected distances in metres. PROJ
|
|
24
|
+
* strings instead describe the CRS's native output unit (e.g. US survey ft).
|
|
25
|
+
* Override that unit at the metre-coordinate boundary; projection offsets
|
|
26
|
+
* +x_0/+y_0 are already metres and must remain untouched.
|
|
27
|
+
* https://proj.org/en/stable/usage/projections.html#projection-units
|
|
28
|
+
*/
|
|
29
|
+
export function projectedDefinitionInMetres(definition) {
|
|
30
|
+
if (isGeographicProj4(definition))
|
|
31
|
+
return definition;
|
|
32
|
+
if (isWktDefinition(definition))
|
|
33
|
+
return wktDefinitionInMetres(definition);
|
|
34
|
+
return `${definition.replace(/(?:^|\s)\+(?:units|to_meter)=\S+/g, '').trim()} +units=m`;
|
|
35
|
+
}
|
|
36
|
+
/** WGS84 semi-major axis (m) and first eccentricity squared. */
|
|
37
|
+
const WGS84_A = 6378137;
|
|
38
|
+
const WGS84_E2 = 0.0066943799901413165;
|
|
39
|
+
/**
|
|
40
|
+
* Radii of curvature of the WGS84 ellipsoid at a geodetic latitude (degrees):
|
|
41
|
+
* `meridian` (M, north-south) and `primeVertical` (N, east-west; a parallel of
|
|
42
|
+
* latitude has radius N cos(lat)).
|
|
43
|
+
*/
|
|
44
|
+
export function wgs84RadiiOfCurvature(latDeg) {
|
|
45
|
+
const s = Math.sin((latDeg * Math.PI) / 180);
|
|
46
|
+
const w = 1 - WGS84_E2 * s * s;
|
|
47
|
+
return { meridian: (WGS84_A * (1 - WGS84_E2)) / (w * Math.sqrt(w)), primeVertical: WGS84_A / Math.sqrt(w) };
|
|
48
|
+
}
|
|
49
|
+
/** True-north ENU metres (on the WGS84 ellipsoid) of a short step between two WGS84 positions. */
|
|
50
|
+
function enuStep(lon1, lat1, lon2, lat2) {
|
|
51
|
+
const { meridian, primeVertical } = wgs84RadiiOfCurvature((lat1 + lat2) / 2);
|
|
52
|
+
let dLon = lon2 - lon1;
|
|
53
|
+
if (dLon > 180)
|
|
54
|
+
dLon -= 360;
|
|
55
|
+
else if (dLon < -180)
|
|
56
|
+
dLon += 360;
|
|
57
|
+
const rad = Math.PI / 180;
|
|
58
|
+
return {
|
|
59
|
+
east: dLon * rad * primeVertical * Math.cos(((lat1 + lat2) / 2) * rad),
|
|
60
|
+
north: (lat2 - lat1) * rad * meridian,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Half-length (projected metres) of the central-difference probe. */
|
|
64
|
+
const PROBE_STEP_M = 10;
|
|
65
|
+
/**
|
|
66
|
+
* Convergence and point scale at a projected point by central differences
|
|
67
|
+
* through proj4, measured with the WGS84 meridian (M) and prime-vertical (N)
|
|
68
|
+
* radii. Works for any projection without per-projection formulae. Throws
|
|
69
|
+
* when proj4 does; returns null for non-finite results.
|
|
70
|
+
*
|
|
71
|
+
* Accuracy: the central difference over +/-10 m leaves a truncation term of
|
|
72
|
+
* order (10 m / R)^2, about 1e-12, and the double-precision round-off on the
|
|
73
|
+
* differenced latitudes is about 1e-10. Both outputs match PROJ to 5e-11 on
|
|
74
|
+
* TM, LCC and Krovak (`__fixtures__/proj-oracle.json`, generated by
|
|
75
|
+
* `scripts/geo/generate-proj-oracle.py`).
|
|
76
|
+
*/
|
|
77
|
+
export function computeGridPointFactors(projDef, easting, northing) {
|
|
78
|
+
const def = projectedDefinitionInMetres(projDef);
|
|
79
|
+
const d = PROBE_STEP_M;
|
|
80
|
+
const [lonS, latS] = proj4(def, 'WGS84', [easting, northing - d]);
|
|
81
|
+
const [lonN, latN] = proj4(def, 'WGS84', [easting, northing + d]);
|
|
82
|
+
const [lonW, latW] = proj4(def, 'WGS84', [easting - d, northing]);
|
|
83
|
+
const [lonE, latE] = proj4(def, 'WGS84', [easting + d, northing]);
|
|
84
|
+
if (![lonS, latS, lonN, latN, lonW, latW, lonE, latE].every(Number.isFinite))
|
|
85
|
+
return null;
|
|
86
|
+
const north = enuStep(lonS, latS, lonN, latN);
|
|
87
|
+
const east = enuStep(lonW, latW, lonE, latE);
|
|
88
|
+
const northLength = Math.hypot(north.east, north.north);
|
|
89
|
+
const eastLength = Math.hypot(east.east, east.north);
|
|
90
|
+
if (!(northLength > 0) || !(eastLength > 0))
|
|
91
|
+
return null;
|
|
92
|
+
return {
|
|
93
|
+
// grid-north's bearing measured from true north is atan2(east, north) = -gamma.
|
|
94
|
+
gamma: Math.atan2(-north.east, north.north),
|
|
95
|
+
pointScale: Math.sqrt(((2 * d) / northLength) * ((2 * d) / eastLength)),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Grid (meridian) convergence at a point in a projected CRS: the angle between
|
|
100
|
+
* grid north (the projected CRS's +N axis) and true north (the geographic ENU
|
|
101
|
+
* +N axis). Returned in radians, counter-clockwise positive, such that the grid
|
|
102
|
+
* frame equals the true-ENU frame rotated by +gamma.
|
|
103
|
+
*
|
|
104
|
+
* WHY THIS EXISTS: `IfcMapConversion` aligns the model to GRID north (its
|
|
105
|
+
* XAxisAbscissa/Ordinate are expressed in the projected grid), but Cesium's
|
|
106
|
+
* `eastNorthUpToFixedFrame()` builds a TRUE-north ENU frame. Feeding the
|
|
107
|
+
* grid-aligned model straight into that frame rotates it by the convergence —
|
|
108
|
+
* up to ~3° for UTM near a zone edge, ~7-8° for oblique projections like
|
|
109
|
+
* Krovak (EPSG:2065, S-JTSK / Czech Republic). See issue #1408.
|
|
110
|
+
*
|
|
111
|
+
* Computed by finite difference through proj4 ({@link computeGridPointFactors})
|
|
112
|
+
* so it works for any projection (TM, LCC, Krovak, ...) without per-projection
|
|
113
|
+
* convergence formulae. A geographic (longlat) def has zero convergence by
|
|
114
|
+
* definition. The step is measured on the WGS84 ellipsoid: the spherical
|
|
115
|
+
* 111320 m/degree it used before turned a 2.2° UTM convergence into an angle
|
|
116
|
+
* off by 1e-4 rad (7.6 mm per 100 m).
|
|
117
|
+
*/
|
|
118
|
+
export function computeGridConvergence(projDef, easting, northing, lat) {
|
|
119
|
+
return computeGridFrame(projDef, easting, northing, lat).gamma;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* {@link computeGridPointFactors} with the placement's guards: a geographic
|
|
123
|
+
* CRS, a point within 0.1° of a pole, or a failed probe read as convergence 0
|
|
124
|
+
* and point scale 1 (the probe failure is logged, see below).
|
|
125
|
+
*/
|
|
126
|
+
export function computeGridFrame(projDef, easting, northing, lat) {
|
|
127
|
+
const neutral = { gamma: 0, pointScale: 1 };
|
|
128
|
+
// Geographic CRS: lat/lon is already true-north aligned.
|
|
129
|
+
if (isGeographicProj4(projDef))
|
|
130
|
+
return neutral;
|
|
131
|
+
// Near the poles the local east/metre scale degenerates; skip.
|
|
132
|
+
if (Math.abs(lat) >= 89.9)
|
|
133
|
+
return neutral;
|
|
134
|
+
try {
|
|
135
|
+
return computeGridPointFactors(projDef, easting, northing) ?? neutral;
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
// Zero is not a neutral answer here: it is indistinguishable from a
|
|
139
|
+
// genuinely zero convergence, so the model silently keeps its GRID
|
|
140
|
+
// alignment inside Cesium's TRUE-north ENU frame — a rotation of up to ~3°
|
|
141
|
+
// (UTM zone edge) or ~7-8° (Krovak). Called once per model, so logging it
|
|
142
|
+
// costs nothing and names the cause if it ever happens.
|
|
143
|
+
reportCrsDiagnostic(`[cesium] grid convergence unavailable for ${projDef}; the model is placed `
|
|
144
|
+
+ 'grid-aligned in a true-north frame (rotation up to a few degrees).', err);
|
|
145
|
+
return neutral;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=proj4-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proj4-utils.js","sourceRoot":"","sources":["../src/proj4-utils.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEtG,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IAAI,eAAe,CAAC,UAAU,CAAC;QAAE,OAAO,uBAAuB,CAAC,UAAU,CAAC,EAAE,QAAQ,KAAK,SAAS,CAAC;IACpG,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,UA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;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,OAAe,EAAE,QAAgB,EAAE,GAAW;IACpG,OAAO,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,QAAgB,EAAE,GAAW;IAC9F,MAAM,OAAO,GAAqB,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IAC9D,yDAAyD;IACzD,IAAI,iBAAiB,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC/C,+DAA+D;IAC/D,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAC1C,IAAI,CAAC;QACH,OAAO,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,OAAO,CAAC;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oEAAoE;QACpE,mEAAmE;QACnE,2EAA2E;QAC3E,0EAA0E;QAC1E,wDAAwD;QACxD,mBAAmB,CACjB,6CAA6C,OAAO,wBAAwB;cAC1E,oEAAoE,EACtE,GAAG,CACJ,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
|
package/dist/proj4.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ifc-lite/geo/proj4 — the definition-string layer under `resolveCrs`.
|
|
3
|
+
*
|
|
4
|
+
* These functions hand out and take proj4 definitions directly, which is what
|
|
5
|
+
* a host needs when it calls proj4 itself (the viewer's globe placement does).
|
|
6
|
+
* A definition returned for a WKT is a handle registered with the proj4
|
|
7
|
+
* instance this package imports; it is only valid in that instance. Every
|
|
8
|
+
* function here uses the default engine (`configureCrsLoaders`).
|
|
9
|
+
*/
|
|
10
|
+
export { resolveProjection, resolveProjectionId, resolveProjectionOperation, type CrsDescriptor, } from './resolve-projection.js';
|
|
11
|
+
export { coordinatesToLatLon, reprojectFromLatLon, reprojectPointToLatLon, type LatLon, } from './reproject-point.js';
|
|
12
|
+
export { resolveMapUnitToMetreScale } from './map-unit.js';
|
|
13
|
+
export { projectedUnitToMetres } from './projected-units.js';
|
|
14
|
+
export { computeGridConvergence, computeGridFrame, computeGridPointFactors, isGeographicProj4, projectedDefinitionInMetres, wgs84RadiiOfCurvature, } from './proj4-utils.js';
|
|
15
|
+
export { isWithinWktDefinitionExtent, isWktDefinition, registeredWktDefinition, wktDefinitionInMetres, } from './wkt-projection.js';
|
|
16
|
+
export { PRECISION_GRIDS, hasFailedPrecisionGrid, hasLoadedPrecisionGrid, } from './precision-grids.js';
|
|
17
|
+
//# sourceMappingURL=proj4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proj4.d.ts","sourceRoot":"","sources":["../src/proj4.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,EAC1B,KAAK,aAAa,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,MAAM,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
package/dist/proj4.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
* @ifc-lite/geo/proj4 — the definition-string layer under `resolveCrs`.
|
|
6
|
+
*
|
|
7
|
+
* These functions hand out and take proj4 definitions directly, which is what
|
|
8
|
+
* a host needs when it calls proj4 itself (the viewer's globe placement does).
|
|
9
|
+
* A definition returned for a WKT is a handle registered with the proj4
|
|
10
|
+
* instance this package imports; it is only valid in that instance. Every
|
|
11
|
+
* function here uses the default engine (`configureCrsLoaders`).
|
|
12
|
+
*/
|
|
13
|
+
export { resolveProjection, resolveProjectionId, resolveProjectionOperation, } from './resolve-projection.js';
|
|
14
|
+
export { coordinatesToLatLon, reprojectFromLatLon, reprojectPointToLatLon, } from './reproject-point.js';
|
|
15
|
+
export { resolveMapUnitToMetreScale } from './map-unit.js';
|
|
16
|
+
export { projectedUnitToMetres } from './projected-units.js';
|
|
17
|
+
export { computeGridConvergence, computeGridFrame, computeGridPointFactors, isGeographicProj4, projectedDefinitionInMetres, wgs84RadiiOfCurvature, } from './proj4-utils.js';
|
|
18
|
+
export { isWithinWktDefinitionExtent, isWktDefinition, registeredWktDefinition, wktDefinitionInMetres, } from './wkt-projection.js';
|
|
19
|
+
export { PRECISION_GRIDS, hasFailedPrecisionGrid, hasLoadedPrecisionGrid, } from './precision-grids.js';
|
|
20
|
+
//# sourceMappingURL=proj4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proj4.js","sourceRoot":"","sources":["../src/proj4.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,GAE3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GAEvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A CRS's native linear unit: its name, when known, and its length in metres. */
|
|
2
|
+
export interface LinearUnit {
|
|
3
|
+
/** `metre`, `foot`, `US survey foot`, ... `null` when the definition states only a factor. */
|
|
4
|
+
readonly name: string | null;
|
|
5
|
+
/** Metres per unit: 0.3048 for the foot, 1200/3937 for the US survey foot. */
|
|
6
|
+
readonly toMetres: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The native linear unit of a projected definition (a proj4 string or a
|
|
10
|
+
* registered WKT handle), or `null` when it names a unit this package does
|
|
11
|
+
* not know or states an unusable factor. A definition that states no unit is
|
|
12
|
+
* in metres.
|
|
13
|
+
*/
|
|
14
|
+
export declare function projectedLinearUnit(definition: string): LinearUnit | null;
|
|
15
|
+
/** Resolve proj4's native projected unit to metres; `null` for an unknown unit. */
|
|
16
|
+
export declare function projectedUnitToMetres(definition: string): number | null;
|
|
17
|
+
//# sourceMappingURL=projected-units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projected-units.d.ts","sourceRoot":"","sources":["../src/projected-units.ts"],"names":[],"mappings":"AAMA,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAeD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAmBzE;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEvE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import { isWktDefinition, registeredWktDefinition, wktDefinitionInMetres } from './wkt-projection.js';
|
|
5
|
+
/** proj4 `+units=` names this package recognises. Anything else fails closed. */
|
|
6
|
+
const PROJ_UNITS = {
|
|
7
|
+
m: { name: 'metre', toMetres: 1 },
|
|
8
|
+
ft: { name: 'foot', toMetres: 0.3048 },
|
|
9
|
+
'us-ft': { name: 'US survey foot', toMetres: 1200 / 3937 },
|
|
10
|
+
km: { name: 'kilometre', toMetres: 1000 },
|
|
11
|
+
};
|
|
12
|
+
/** The same units looked up by factor, to name a definition that states only `+to_meter`. */
|
|
13
|
+
function nameForFactor(toMetres) {
|
|
14
|
+
return Object.values(PROJ_UNITS).find((unit) => unit.toMetres === toMetres)?.name ?? null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The native linear unit of a projected definition (a proj4 string or a
|
|
18
|
+
* registered WKT handle), or `null` when it names a unit this package does
|
|
19
|
+
* not know or states an unusable factor. A definition that states no unit is
|
|
20
|
+
* in metres.
|
|
21
|
+
*/
|
|
22
|
+
export function projectedLinearUnit(definition) {
|
|
23
|
+
if (isWktDefinition(definition)) {
|
|
24
|
+
if (wktDefinitionInMetres(definition) === definition)
|
|
25
|
+
return PROJ_UNITS.m;
|
|
26
|
+
const parsed = registeredWktDefinition(definition);
|
|
27
|
+
const toMetres = parsed?.to_meter ?? 1;
|
|
28
|
+
if (!Number.isFinite(toMetres) || toMetres <= 0)
|
|
29
|
+
return null;
|
|
30
|
+
// wkt-parser lower-cases the unit name and spells metre the American way.
|
|
31
|
+
const name = typeof parsed?.units === 'string' ? (parsed.units === 'meter' ? 'metre' : parsed.units) : null;
|
|
32
|
+
return { name: name ?? nameForFactor(toMetres), toMetres };
|
|
33
|
+
}
|
|
34
|
+
const explicit = /(?:^|\s)\+to_meter=([^\s]+)/i.exec(definition)?.[1];
|
|
35
|
+
if (explicit) {
|
|
36
|
+
const ratio = /^(\d+(?:\.\d+)?)\/(\d+(?:\.\d+)?)$/.exec(explicit);
|
|
37
|
+
const toMetres = ratio ? Number(ratio[1]) / Number(ratio[2]) : Number(explicit);
|
|
38
|
+
return Number.isFinite(toMetres) && toMetres > 0 ? { name: nameForFactor(toMetres), toMetres } : null;
|
|
39
|
+
}
|
|
40
|
+
const unit = /(?:^|\s)\+units=([^\s]+)/i.exec(definition)?.[1]?.toLowerCase();
|
|
41
|
+
if (unit === undefined)
|
|
42
|
+
return PROJ_UNITS.m;
|
|
43
|
+
return Object.hasOwn(PROJ_UNITS, unit) ? PROJ_UNITS[unit] : null;
|
|
44
|
+
}
|
|
45
|
+
/** Resolve proj4's native projected unit to metres; `null` for an unknown unit. */
|
|
46
|
+
export function projectedUnitToMetres(definition) {
|
|
47
|
+
return projectedLinearUnit(definition)?.toMetres ?? null;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=projected-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projected-units.js","sourceRoot":"","sources":["../src/projected-units.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D,OAAO,EAAE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@@
|
|
|
1
|
+
import { type CrsDescriptor } from './resolve-projection.js';
|
|
2
|
+
export interface LatLon {
|
|
3
|
+
lat: number;
|
|
4
|
+
lon: number;
|
|
5
|
+
}
|
|
6
|
+
/** Inputs are degrees for geographic CRSs, metres for projected CRSs. */
|
|
7
|
+
export declare function coordinatesToLatLon(definition: string, x: number, y: number): LatLon | null;
|
|
8
|
+
/**
|
|
9
|
+
* WGS84 degrees to the CRS: degrees for a geographic CRS, metres for a
|
|
10
|
+
* projected one. The inverse of {@link coordinatesToLatLon}, with the same
|
|
11
|
+
* refusals: a position outside the extent a WKT declares is `null` in both
|
|
12
|
+
* directions.
|
|
13
|
+
*/
|
|
14
|
+
export declare function latLonToCoordinates(definition: string, lon: number, lat: number): {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
} | null;
|
|
18
|
+
/**
|
|
19
|
+
* Reproject an explicit projected point (eastings/northings in the CRS map
|
|
20
|
+
* unit) to WGS84 lat/lon. Unlike a model-centre reprojection, which derives the
|
|
21
|
+
* point from geometry, this takes coordinates already resolved in the map CRS — e.g.
|
|
22
|
+
* a picked point's E/N from the measure geo readout (issue #1657).
|
|
23
|
+
*
|
|
24
|
+
* @param eastings Easting in the CRS map unit.
|
|
25
|
+
* @param northings Northing in the CRS map unit.
|
|
26
|
+
* @param crs IfcProjectedCRS (EPSG code, mapUnitScale).
|
|
27
|
+
* @param lengthUnitScale IFC project length unit to metres (fallback when
|
|
28
|
+
* crs.mapUnitScale is absent).
|
|
29
|
+
*/
|
|
30
|
+
export declare function reprojectPointToLatLon(eastings: number, northings: number, crs: CrsDescriptor, lengthUnitScale?: number): Promise<LatLon | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Reverse-project a WGS84 point to the declared origin's map-unit coordinates.
|
|
33
|
+
* This is the inverse of reprojectPointToLatLon, independent of mesh placement
|
|
34
|
+
* (#6677). Geometry-aware inverse placement lives in the shared spatial reference.
|
|
35
|
+
*/
|
|
36
|
+
export declare function reprojectFromLatLon(latLon: LatLon, crs: CrsDescriptor, lengthUnitScale?: number): Promise<{
|
|
37
|
+
easting: number;
|
|
38
|
+
northing: number;
|
|
39
|
+
} | null>;
|
|
40
|
+
//# sourceMappingURL=reproject-point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reproject-point.d.ts","sourceRoot":"","sources":["../src/reproject-point.ts"],"names":[],"mappings":"AAWA,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAIhF,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAQD,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU3F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CASjH;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,aAAa,EAClB,eAAe,SAAI,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,aAAa,EAClB,eAAe,SAAI,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CASvD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
* Point reprojection between a resolved CRS and WGS84.
|
|
6
|
+
*/
|
|
7
|
+
import proj4 from 'proj4';
|
|
8
|
+
import { resolveMapUnitToMetreScale } from './map-unit.js';
|
|
9
|
+
import { isGeographicProj4, projectedDefinitionInMetres } from './proj4-utils.js';
|
|
10
|
+
import { resolveProjection } from './resolve-projection.js';
|
|
11
|
+
import { reportCrsDiagnostic } from './diagnostics.js';
|
|
12
|
+
import { isWithinWktDefinitionExtent } from './wkt-projection.js';
|
|
13
|
+
/** Geographic input and WGS84 output use finite longitude/latitude degrees. */
|
|
14
|
+
function validLatLon(lon, lat) {
|
|
15
|
+
return Number.isFinite(lon) && Number.isFinite(lat)
|
|
16
|
+
&& lon >= -180 && lon <= 180 && lat >= -90 && lat <= 90;
|
|
17
|
+
}
|
|
18
|
+
/** Inputs are degrees for geographic CRSs, metres for projected CRSs. */
|
|
19
|
+
export function coordinatesToLatLon(definition, x, y) {
|
|
20
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
21
|
+
return null;
|
|
22
|
+
if (isGeographicProj4(definition) && !validLatLon(x, y))
|
|
23
|
+
return null;
|
|
24
|
+
try {
|
|
25
|
+
const [lon, lat] = proj4(projectedDefinitionInMetres(definition), 'WGS84', [x, y]);
|
|
26
|
+
return validLatLon(lon, lat) && isWithinWktDefinitionExtent(definition, lon, lat) ? { lat, lon } : null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
reportCrsDiagnostic('[reproject] coordinate transformation failed', error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* WGS84 degrees to the CRS: degrees for a geographic CRS, metres for a
|
|
35
|
+
* projected one. The inverse of {@link coordinatesToLatLon}, with the same
|
|
36
|
+
* refusals: a position outside the extent a WKT declares is `null` in both
|
|
37
|
+
* directions.
|
|
38
|
+
*/
|
|
39
|
+
export function latLonToCoordinates(definition, lon, lat) {
|
|
40
|
+
if (!validLatLon(lon, lat) || !isWithinWktDefinitionExtent(definition, lon, lat))
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
const [x, y] = proj4('WGS84', projectedDefinitionInMetres(definition), [lon, lat]);
|
|
44
|
+
return Number.isFinite(x) && Number.isFinite(y) ? { x, y } : null;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
reportCrsDiagnostic('[reproject] inverse coordinate transformation failed', error);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reproject an explicit projected point (eastings/northings in the CRS map
|
|
53
|
+
* unit) to WGS84 lat/lon. Unlike a model-centre reprojection, which derives the
|
|
54
|
+
* point from geometry, this takes coordinates already resolved in the map CRS — e.g.
|
|
55
|
+
* a picked point's E/N from the measure geo readout (issue #1657).
|
|
56
|
+
*
|
|
57
|
+
* @param eastings Easting in the CRS map unit.
|
|
58
|
+
* @param northings Northing in the CRS map unit.
|
|
59
|
+
* @param crs IfcProjectedCRS (EPSG code, mapUnitScale).
|
|
60
|
+
* @param lengthUnitScale IFC project length unit to metres (fallback when
|
|
61
|
+
* crs.mapUnitScale is absent).
|
|
62
|
+
*/
|
|
63
|
+
export async function reprojectPointToLatLon(eastings, northings, crs, lengthUnitScale = 1) {
|
|
64
|
+
const projDef = await resolveProjection(crs);
|
|
65
|
+
if (!projDef)
|
|
66
|
+
return null;
|
|
67
|
+
// Geographic coordinates remain degrees; projected coordinates enter proj4 in metres.
|
|
68
|
+
const mapScale = isGeographicProj4(projDef)
|
|
69
|
+
? 1 : resolveMapUnitToMetreScale(crs.mapUnitScale, lengthUnitScale);
|
|
70
|
+
return coordinatesToLatLon(projDef, eastings * mapScale, northings * mapScale);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reverse-project a WGS84 point to the declared origin's map-unit coordinates.
|
|
74
|
+
* This is the inverse of reprojectPointToLatLon, independent of mesh placement
|
|
75
|
+
* (#6677). Geometry-aware inverse placement lives in the shared spatial reference.
|
|
76
|
+
*/
|
|
77
|
+
export async function reprojectFromLatLon(latLon, crs, lengthUnitScale = 1) {
|
|
78
|
+
const projDef = await resolveProjection(crs);
|
|
79
|
+
if (!projDef)
|
|
80
|
+
return null;
|
|
81
|
+
const projected = latLonToCoordinates(projDef, latLon.lon, latLon.lat);
|
|
82
|
+
if (!projected)
|
|
83
|
+
return null;
|
|
84
|
+
const mapScale = isGeographicProj4(projDef)
|
|
85
|
+
? 1 : resolveMapUnitToMetreScale(crs.mapUnitScale, lengthUnitScale);
|
|
86
|
+
return { easting: projected.x / mapScale, northing: projected.y / mapScale };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=reproject-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reproject-point.js","sourceRoot":"","sources":["../src/reproject-point.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAsB,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAOlE,+EAA+E;AAC/E,SAAS,WAAW,CAAC,GAAW,EAAE,GAAW;IAC3C,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;WAC9C,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,EAA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AAC,OAAO,CAAC;QACzC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,GAAG,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IACtE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,GAAG,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,GAAG,QAAQ,EAAE,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type EngineState, type ResolvedDefinition } from './engine-state.js';
|
|
2
|
+
/**
|
|
3
|
+
* The CRS metadata resolution reads. Structurally a subset of the parser's
|
|
4
|
+
* `ProjectedCRS` (`IfcProjectedCRS` / `IfcGeographicCRS`), so one of those
|
|
5
|
+
* passes as is; nothing here depends on IFC.
|
|
6
|
+
*/
|
|
7
|
+
export interface CrsDescriptor {
|
|
8
|
+
/** `EPSG:<code>`, a well-known alias (`LV95`, `RD New`, ...) or free text. */
|
|
9
|
+
name?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
mapProjection?: string;
|
|
12
|
+
/** UTM zone, e.g. `32N`. */
|
|
13
|
+
mapZone?: string;
|
|
14
|
+
/** Map unit to metres (`IfcProjectedCRS.MapUnit`); absent reads as metres. */
|
|
15
|
+
mapUnitScale?: number;
|
|
16
|
+
/** WKT1 or WKT2 definition; authoritative over `name` when present. */
|
|
17
|
+
wellKnownText?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The EPSG code a CRS resolves through, when it names one: the identifier in
|
|
21
|
+
* its WKT, an `EPSG:<code>` name, or a well-known alias. `null` for a CRS
|
|
22
|
+
* defined by its WKT alone or by UTM metadata.
|
|
23
|
+
*/
|
|
24
|
+
export declare function declaredEpsgCode(crs: CrsDescriptor): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a proj4 definition for the given CRS metadata, through the default
|
|
27
|
+
* engine. See {@link resolveDefinition} for the order.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveProjection(crs: CrsDescriptor): Promise<string | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve a proj4 definition, and how its datum shift is obtained, for the
|
|
32
|
+
* given CRS metadata.
|
|
33
|
+
*
|
|
34
|
+
* An `IfcWellKnownText` definition is authoritative over the name (which may
|
|
35
|
+
* then be a placeholder such as "WKT"): an EPSG identifier it names resolves
|
|
36
|
+
* through the order below, otherwise the WKT itself is the definition. A WKT
|
|
37
|
+
* that cannot be read falls back to the name; one that was read without a
|
|
38
|
+
* parameter its projection needs resolves to `null`.
|
|
39
|
+
*
|
|
40
|
+
* Resolution order:
|
|
41
|
+
* 1. Cache hit
|
|
42
|
+
* 2. Precision grid (NTv2/GeoTIFF) for codes where +towgs84 is too coarse
|
|
43
|
+
* (RD/NL, OSGB/UK, BD72/BE) — loaded once through the engine's grid
|
|
44
|
+
* loader, gives sub-decimeter accuracy. Falls through to (3) when no
|
|
45
|
+
* loader is installed or the load fails.
|
|
46
|
+
* 3. Bundled EPSG index (7000+ codes with proj4 strings)
|
|
47
|
+
* 4. UTM zone heuristic (from CRS metadata — mapZone, name, description, mapProjection)
|
|
48
|
+
* 5. The engine's EPSG definition loader (epsg.io when the host installs
|
|
49
|
+
* `epsgIoDefinitionLoader`; skipped when none is installed)
|
|
50
|
+
*
|
|
51
|
+
* The datum-shift verdict travels with the definition it describes, so a
|
|
52
|
+
* concurrent resolution that loads a grid cannot change what an earlier
|
|
53
|
+
* result says about itself.
|
|
54
|
+
*/
|
|
55
|
+
export declare function resolveDefinition(crs: CrsDescriptor, state: EngineState): Promise<ResolvedDefinition | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve an adapter-supplied canonical CRS identifier. Federation uses this
|
|
58
|
+
* entry point rather than reconstructing an IFC-shaped `ProjectedCRS`: only
|
|
59
|
+
* an explicit `EPSG:<code>` identifier is accepted here, so a display label
|
|
60
|
+
* can never turn into a placement decision by accident.
|
|
61
|
+
*/
|
|
62
|
+
export interface ResolveProjectionIdOptions {
|
|
63
|
+
/** Permit a documented browser approximation when its exact datum grid is unavailable. */
|
|
64
|
+
allowApproximate?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export type ProjectionOperation = {
|
|
67
|
+
kind: 'exact';
|
|
68
|
+
definition: string;
|
|
69
|
+
provenance: 'cached-grid' | 'bundled' | 'network';
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'approximate';
|
|
72
|
+
definition: string;
|
|
73
|
+
provenance: 'helmert-fallback';
|
|
74
|
+
} | {
|
|
75
|
+
kind: 'refused';
|
|
76
|
+
reason: 'required-grid-unavailable' | 'approximation-not-authorized' | 'unresolvable';
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Resolve a placement operation with its accuracy provenance. Unlike map
|
|
80
|
+
* display, federation has no safe implicit approximation: callers must opt in
|
|
81
|
+
* to the documented Helmert fallback, and a grid with no fallback is refused.
|
|
82
|
+
*/
|
|
83
|
+
export declare function resolveProjectionOperation(id: string, options?: ResolveProjectionIdOptions): Promise<ProjectionOperation>;
|
|
84
|
+
export declare function resolveProjectionId(id: string, options?: ResolveProjectionIdOptions): Promise<string | null>;
|
|
85
|
+
//# sourceMappingURL=resolve-projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-projection.d.ts","sourceRoot":"","sources":["../src/resolve-projection.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAsB,KAAK,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAOlG;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,aAAa,CAAC,EAAE,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