Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions PROJJSONBuilderBase.js → PROJJSONBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PROJJSONBuilderBase {
const csNode = node.find((child) => Array.isArray(child) && child[0] === 'CS');
if (csNode) {
result.coordinate_system = {
type: csNode[1],
subtype: csNode[1],
axis: this.extractAxes(node),
};
}
Expand Down Expand Up @@ -134,8 +134,9 @@ class PROJJSONBuilderBase {
}
}

const geogCsNode = node.find((child) => Array.isArray(child) && child[0] === 'CS');
result.coordinate_system = {
type: 'ellipsoidal',
subtype: geogCsNode ? geogCsNode[1] : 'ellipsoidal',
axis: this.extractAxes(node),
};

Expand Down
19 changes: 0 additions & 19 deletions PROJJSONBuilder2015.js

This file was deleted.

38 changes: 0 additions & 38 deletions PROJJSONBuilder2019.js

This file was deleted.

31 changes: 2 additions & 29 deletions buildPROJJSON.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
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';
}
import PROJJSONBuilder from './PROJJSONBuilder.js';

/**
* 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);
return PROJJSONBuilder.convert(root);
}
14 changes: 14 additions & 0 deletions test-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1648,5 +1648,19 @@
"name": "WGS 84",
"title": "EPSG:4978"
}
}, {
"code": "GEODCRS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",ELLIPSOID[\"WGS 84\",6378137,298.257223563,LENGTHUNIT[\"metre\",1]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[Cartesian,3],AXIS[\"(X)\",geocentricX,ORDER[1],LENGTHUNIT[\"metre\",1]],AXIS[\"(Y)\",geocentricY,ORDER[2],LENGTHUNIT[\"metre\",1]],AXIS[\"(Z)\",geocentricZ,ORDER[3],LENGTHUNIT[\"metre\",1]],ID[\"EPSG\",4978]]",
"value": {
"projName": "geocent",
"ellps": "WGS 84",
"a": 6378137,
"rf": 298.257223563,
"axis": "enu",
"units": "meter",
"to_meter": 1,
"srsCode": "WGS 84",
"name": "WGS 84",
"title": "EPSG:4978"
}
}
]
Loading