Skip to content

Commit

Permalink
recursively cleanWKT
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Oct 11, 2024
1 parent 35c4d13 commit 80c9080
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ function d2r(input) {
}

function cleanWKT(wkt) {
Object.keys(wkt).forEach(key => {
var keys = Object.keys(wkt);
keys.forEach(key => {
if (['PROJECTEDCRS', 'PROJCRS', 'GEOGCS', 'GEOCCS', 'PROJCS', 'LOCAL_CS', 'GEODCRS',
'GEODETICCRS', 'VERT_CS', 'VERTCRS', 'VERTICALCRS', 'COMPD_CS', 'COMPOUNDCRS',
'ENGINEERINGCRS', 'ENGCRS', 'FITTED_CS'].includes(key)) {
cleanWKT(wkt[key]);
'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'].includes(key)) {
setPropertiesFromWkt(wkt[key]);
};
})
if (typeof wkt[key] === 'object') {
cleanWKT(wkt[key]);
}
});
}

function setPropertiesFromWkt(wkt) {
if (wkt.AUTHORITY) {
var authority = Object.keys(wkt.AUTHORITY)[0];
if (authority && authority in wkt.AUTHORITY) {
Expand Down Expand Up @@ -207,12 +213,9 @@ function cleanWKT(wkt) {
}
export default function(wkt) {
var lisp = parser(wkt);
var type = lisp.shift();
var name = lisp.shift();
lisp.unshift(['name', name]);
lisp.unshift(['type', type]);
var type = lisp[0];
var obj = {};
sExpr(lisp, obj);
cleanWKT(obj);
return obj;
return obj[type];
}

0 comments on commit 80c9080

Please sign in to comment.