-
Notifications
You must be signed in to change notification settings - Fork 74
/
powerline.js
84 lines (68 loc) · 3.75 KB
/
powerline.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
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('Power Lines', function () {
this.timeout(5000);
// Strings used to build OSM XML features
var startNode = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-13" lat="0.68270797876" lon="18.45141400736" >';
var startWay = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-10" lat="0.68307256979" lon="18.45073925651" /> <node id="-13" lat="0.68270797876" lon="18.45141400736" />\
<way id="-19" >\
<nd ref="-10" /> <nd ref="-13" />';
var startArea = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-10" lat="0.68307256979" lon="18.45073925651" /> <node id="-11" lat="0.68341620728" lon="18.45091527847" />\
<node id="-12" lat="0.68306209303" lon="18.45157116983" /> <node id="-13" lat="0.68270797876" lon="18.45141400736" />\
<way id="-19" >\
<nd ref="-10" /> <nd ref="-11" /> <nd ref="-12" /> <nd ref="-13" /> <nd ref="-10" />';
var endNode = '</node></osm>';
var endWay = '</way></osm>'; // NOTE: This is also for Areas as well
var schemas = [
'TDSv71',
'TDSv70',
'TDSv61',
'TDSv40',
// 'MGCP', // Different F_CODE and uuid
'GGDMv30'
];
schemas.forEach(schema => {
var fcode_key = (schema === 'MGCP') ? 'FCODE' : 'F_CODE';
it('should handle translation of power line feature from ' + schema + ' -> osm -> ' + schema, function() {
var data = startWay + '<tag k="power" v="line"/><tag k="uuid" v="{d7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1}"/>' + endWay;
var trans_xml = server.handleInputs({osm: data, method: 'POST', translation: schema, path: '/translateTo'})
// console.log(trans_xml);
var xml = parser.parseFromString(trans_xml);
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags[fcode_key], 'AT005');
assert.equal(tags['CAB'], '6');
assert.equal(tags['UFI'], 'd7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1');
var osm_xml = server.handleInputs({osm: trans_xml, method: 'POST', translation: schema, path: '/translateFrom'});
// console.log(osm_xml);
xml = parser.parseFromString(osm_xml);
tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags['power'], 'line');
assert.equal(tags['uuid'], '{d7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1}');
});
});
it('should handle translation of power line feature from MGCP -> osm -> MGCP', function() {
var data = startWay + '<tag k="power" v="line"/><tag k="uuid" v="{d7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1}"/>' + endWay;
var trans_xml = server.handleInputs({osm: data, method: 'POST', translation: 'MGCP', path: '/translateTo'})
// console.log(trans_xml);
var xml = parser.parseFromString(trans_xml);
var tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags['FCODE'], 'AT030');
assert.equal(tags['UID'], 'd7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1'.toUpperCase());
var osm_xml = server.handleInputs({osm: trans_xml, method: 'POST', translation: 'MGCP', path: '/translateFrom'});
// console.log(osm_xml);
xml = parser.parseFromString(osm_xml);
tags = osmtogeojson(xml).features[0].properties;
assert.equal(tags['power'], 'line');
assert.equal(tags['uuid'], '{d7cdbdfe-88c6-4d8a-979d-ad88cfc65ef1}');
});
});