Skip to content

Commit 80c9080

Browse files
committed
recursively cleanWKT
1 parent 35c4d13 commit 80c9080

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ function d2r(input) {
2020
}
2121

2222
function cleanWKT(wkt) {
23-
Object.keys(wkt).forEach(key => {
23+
var keys = Object.keys(wkt);
24+
keys.forEach(key => {
2425
if (['PROJECTEDCRS', 'PROJCRS', 'GEOGCS', 'GEOCCS', 'PROJCS', 'LOCAL_CS', 'GEODCRS',
25-
'GEODETICCRS', 'VERT_CS', 'VERTCRS', 'VERTICALCRS', 'COMPD_CS', 'COMPOUNDCRS',
26-
'ENGINEERINGCRS', 'ENGCRS', 'FITTED_CS'].includes(key)) {
27-
cleanWKT(wkt[key]);
26+
'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'].includes(key)) {
27+
setPropertiesFromWkt(wkt[key]);
2828
};
29-
})
29+
if (typeof wkt[key] === 'object') {
30+
cleanWKT(wkt[key]);
31+
}
32+
});
33+
}
34+
35+
function setPropertiesFromWkt(wkt) {
3036
if (wkt.AUTHORITY) {
3137
var authority = Object.keys(wkt.AUTHORITY)[0];
3238
if (authority && authority in wkt.AUTHORITY) {
@@ -207,12 +213,9 @@ function cleanWKT(wkt) {
207213
}
208214
export default function(wkt) {
209215
var lisp = parser(wkt);
210-
var type = lisp.shift();
211-
var name = lisp.shift();
212-
lisp.unshift(['name', name]);
213-
lisp.unshift(['type', type]);
216+
var type = lisp[0];
214217
var obj = {};
215218
sExpr(lisp, obj);
216219
cleanWKT(obj);
217-
return obj;
220+
return obj[type];
218221
}

0 commit comments

Comments
 (0)