-
Notifications
You must be signed in to change notification settings - Fork 74
/
mall_motor_vehicle.js
137 lines (111 loc) · 6.59 KB
/
mall_motor_vehicle.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var assert = require('assert'),
http = require('http'),
xml2js = require('xml2js'),
fs = require('fs'),
httpMocks = require('node-mocks-http'),
osmtogeojson = require('osmtogeojson'),
DOMParser = new require('@xmldom/xmldom').DOMParser,
parser = new DOMParser();
var server = require('../TranslationServer.js');
describe('TranslationServer', function () {
this.timeout(5000);
it('should translate Motor Vehicle Station (AQ170) from tdsv61 -> osm -> tdsv61', function() {
var data = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-10" action="modify" visible="true" lat="0.68307256979" lon="18.45073925651" />\
<node id="-11" action="modify" visible="true" lat="0.68341620728" lon="18.45091527847" />\
<node id="-12" action="modify" visible="true" lat="0.68306209303" lon="18.45157116983" />\
<node id="-13" action="modify" visible="true" lat="0.68270797876" lon="18.45141400736" />\
<way id="-19" action="modify" visible="true">\
<nd ref="-10" /><nd ref="-12" /><nd ref="-13" /><nd ref="-10" />\
<tag k="F_CODE" v="AQ170"/>\
<tag k="FFN" v="470"/>\
<tag k="FFN2" v="382"/>\
</way>\
</osm>';
var osm_xml = server.handleInputs({osm: data, method: 'POST', translation: 'TDSv61', path: '/translateFrom'});
// console.log(osm_xml);
var xml = parser.parseFromString(osm_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "OSM");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags["amenity"], "fuel");
assert.equal(tags["toilets"], "yes");
var tds_xml = server.handleInputs({osm: osm_xml, method: 'POST', translation: 'TDSv61', path: '/translateTo'});
// console.log(tds_xml);
xml = parser.parseFromString(tds_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv61");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags["F_CODE"], "AQ170");
assert.equal(tags["FFN"], "470");
assert.equal(tags["FFN2"], "382");
});
it('should translate Water Park (F_CODE=AK030 & FFN=915) from tdsv61 -> osm -> tdsv61', function() {
var data = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-10" action="modify" visible="true" lat="0.68307256979" lon="18.45073925651" />\
<node id="-11" action="modify" visible="true" lat="0.68341620728" lon="18.45091527847" />\
<node id="-12" action="modify" visible="true" lat="0.68306209303" lon="18.45157116983" />\
<node id="-13" action="modify" visible="true" lat="0.68270797876" lon="18.45141400736" />\
<way id="-19" action="modify" visible="true">\
<nd ref="-10" /><nd ref="-11" /><nd ref="-12" /><nd ref="-13" /><nd ref="-10" />\
<tag k="F_CODE" v="AK030"/>\
<tag k="FFN" v="915"/>\
</way>\
</osm>';
var osm_xml = server.handleInputs({osm: data, method: 'POST', translation: 'TDSv61', path: '/translateFrom'});
// console.log(osm_xml);
var xml = parser.parseFromString(osm_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "OSM");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags['leisure'], 'water_park');
var tds_xml = server.handleInputs({osm: osm_xml, method: 'POST', translation: 'TDSv61', path: '/translateTo'});
// console.log(tds_xml);
xml = parser.parseFromString(tds_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv61");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags["F_CODE"], 'AK030');
assert.equal(tags["FFN"], '915');
});
//Check multiple schemas and simple FCODE translations
var cases = {
AG030: {shop: 'mall'},
AD030: {power: 'substation'}
}
var schemas = [
'TDSv71',
'TDSv61',
'TDSv40',
// 'MGCP', //No AG030 in MGCP
'GGDMv30'
]
schemas.forEach(schema => {
Object.keys(cases).forEach(k => {
var fcode = k;
var tag = cases[k];
var tagKey = Object.keys(tag)[0];
var fcode_key = (schema === 'MGCP') ? 'FCODE' : 'F_CODE';
it('should translate ' + fcode + ' from ' + schema + ' -> osm -> ' + schema, function() {
var data = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-10" action="modify" visible="true" lat="0.68307256979" lon="18.45073925651" />\
<node id="-11" action="modify" visible="true" lat="0.68341620728" lon="18.45091527847" />\
<node id="-12" action="modify" visible="true" lat="0.68306209303" lon="18.45157116983" />\
<node id="-13" action="modify" visible="true" lat="0.68270797876" lon="18.45141400736" />\
<way id="-19" action="modify" visible="true">\
<nd ref="-10" /><nd ref="-11" /><nd ref="-12" /><nd ref="-13" /><nd ref="-10" />\
<tag k="' + fcode_key + '" v="' + fcode + '"/>\
</way>\
</osm>';
var osm_xml = server.handleInputs({osm: data, method: 'POST', translation: schema, path: '/translateFrom'});
// console.log(osm_xml);
var xml = parser.parseFromString(osm_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "OSM");
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags[tagKey], tag[tagKey]);
var tds_xml = server.handleInputs({osm: osm_xml, method: 'POST', translation: schema, path: '/translateTo'});
// console.log(tds_xml);
xml = parser.parseFromString(tds_xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), schema);
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags[fcode_key], fcode);
});
});
});
});