-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuildPROJJSON.js
More file actions
37 lines (32 loc) · 1.28 KB
/
buildPROJJSON.js
File metadata and controls
37 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import PROJJSONBuilder2015 from './PROJJSONBuilder2015.js';
import PROJJSONBuilder2019 from './PROJJSONBuilder2019.js';
/**
* Detects the WKT2 version based on the structure of the WKT.
* @param {Array} root The root WKT array node.
* @returns {string} The detected version ("2015" or "2019").
*/
function detectWKT2Version(root) {
// Check for WKT2-2019-specific nodes
if (root.find((child) => Array.isArray(child) && child[0] === 'USAGE')) {
return '2019'; // `USAGE` is specific to WKT2-2019
}
// Check for WKT2-2015-specific nodes
if (root.find((child) => Array.isArray(child) && child[0] === 'CS')) {
return '2015'; // `CS` is valid in both, but default to 2015 unless `USAGE` is present
}
if (root[0] === 'BOUNDCRS' || root[0] === 'PROJCRS' || root[0] === 'GEOGCRS') {
return '2015'; // These are valid in both, but default to 2015
}
// Default to WKT2-2015 if no specific indicators are found
return '2015';
}
/**
* Builds a PROJJSON object from a WKT array structure.
* @param {Array} root The root WKT array node.
* @returns {Object} The PROJJSON object.
*/
export function buildPROJJSON(root) {
const version = detectWKT2Version(root);
const builder = version === '2019' ? PROJJSONBuilder2019 : PROJJSONBuilder2015;
return builder.convert(root);
}