-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathetds40.js
108 lines (94 loc) · 4.21 KB
/
etds40.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* This file is part of Hootenanny.
*
* Hootenanny is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --------------------------------------------------------------------
*
* The following copyright notices are generated automatically. If you
* have a new notice to add, please use the format:
* " * @copyright Copyright ..."
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2014 Maxar (http://www.maxar.com/)
*/
/*
OSM+ to "English" TDS conversion script
*/
etds40 = {
// This function converts the OSM+ to TDS and then translates the TDS into "English"
toEnglish : function(tags, elementType, geometryType)
{
var tdsData = [];
tdsData = tds40.toOgr(tags, elementType, geometryType)
// Debug: Commenting this out to cut down the number of Hoot core calls
// if (config.getOgrDebugDumptags() == 'true')
// {
// for (var i = 0, fLen = tdsData.length; i < fLen; i++)
// {
// print('eTableName ' + i + ': ' + tdsData[i]['tableName'] + ' FCode: ' + tdsData[i]['attrs']['F_CODE'] + ' Geom: ' + geometryType);
// var kList = Object.keys(tdsData[i]['attrs']).sort()
// for (var j = 0, kLen = kList.length; j < kLen; j++) print('eOut Attrs:' + kList[j] + ': :' + tdsData[i]['attrs'][kList[j]] + ':');
// }
// print('');
// }
var eAttrs = {}; // The final English output
eAttrs['Feature Code'] = 'Not found';
// Defensive: This will either be populated or we threw an error earlier
if (tdsData.length > 0)
{
for (var fNum = 0, fLen = tdsData.length; fNum < fLen; fNum++)
{
var tFCODE = tdsData[fNum]['attrs']['F_CODE'];
delete tdsData[fNum]['attrs']['F_CODE'];
// Translate the single values
for (var val in tdsData[fNum]['attrs'])
{
if (val in etds40.rules.engSingle)
{
if (tdsData[fNum]['attrs'][val] !== undefined)
{
eAttrs[etds40.rules.engSingle[val]] = tdsData[fNum]['attrs'][val];
}
// Cleanup used attrs so we don't translate them again
delete tdsData[fNum]['attrs'][val];
}
}
// Apply the English one2one rules
translate.applyOne2One(tdsData[fNum]['attrs'], eAttrs, etds40.rules.engEnum, {'k':'v'},[]);
// Find an FCODE
if (tFCODE in etds40.rules.fcodeLookup)
{
if (eAttrs['Feature Code'] !== 'Not found')
{
eAttrs['Feature Code'] = eAttrs['Feature Code'] + ' & ' + tFCODE + ':' + etds40.rules.fcodeLookup[tFCODE]['desc'];
}
else
{
eAttrs['Feature Code'] = tFCODE + ':' + etds40.rules.fcodeLookup[tFCODE]['desc'];
}
}
} // End for tdsData
}
// if (config.getOgrDebugDumptags() == 'true')
// {
// var kList = Object.keys(eAttrs).sort()
// for (var j = 0, kLen = kList.length; j < kLen; j++) print('Final Attrs:' + kList[j] + ': :' + eAttrs[kList[j]] + ':');
// print('');
// }
// Return the English results. The "tableName" is not set
return {attrs: eAttrs, tableName: ''};
} // End of toEnglish
} // End of etds40