-
Notifications
You must be signed in to change notification settings - Fork 74
/
preserve_OTH.js
74 lines (58 loc) · 3.16 KB
/
preserve_OTH.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
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 () {
it('should translate OTH from tdsv61 -> osm -> tdsv61', function() {
var data = '<osm version="0.6" upload="true" generator="hootenanny">\
<node id="-19" lon="9.304397440128325" lat="41.65083522130027" version="0">\
<tag k="FCSUBTYPE" v="100080"/>\
<tag k="UFI" v="0d8b2563-81cf-44d4-8ef7-52c0e862651f"/>\
<tag k="F_CODE" v="AL010"/>\
<tag k="OSMTAGS" v="{"source:imagery:datetime":"2017-11-11 10:45:15","source:imagery:sensor":"WV02","source:imagery:id":"756b80e1f695fb591caca8e7ce0f9ef5"}"/>\
<tag k="ZSAX_RS0" v="U"/>\
<tag k="OTH" v="(FFN:foo)"/>\
</node>\
</osm>';
var osm_xml = server.handleInputs({
osm: data,
method: 'POST',
translation: 'TDSv61',
path: '/translateFrom'
});
// console.log(osm_xml);
var xml = parser.parseFromString(osm_xml);
var gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "OSM");
var tags = gj.features[0].properties;
assert.equal(tags["facility"], "yes");
assert.equal(tags["note:oth"], "(FFN:foo)");
assert.equal(tags["security:classification"], "UNCLASSIFIED");
assert.equal(tags["uuid"], "{0d8b2563-81cf-44d4-8ef7-52c0e862651f}");
assert.equal(tags["source:imagery:id"], "756b80e1f695fb591caca8e7ce0f9ef5");
assert.equal(tags["source:imagery:datetime"], "2017-11-11 10:45:15");
assert.equal(tags["source:imagery:sensor"], "WV02");
var tds_xml = server.handleInputs({
osm: osm_xml,
method: 'POST',
translation: 'TDSv61',
path: '/translateTo'
});
// console.log(tds_xml);
xml = parser.parseFromString(tds_xml);
gj = osmtogeojson(xml);
assert.equal(xml.getElementsByTagName("osm")[0].getAttribute("schema"), "TDSv61");
var tags = gj.features[0].properties;
assert.equal(tags["F_CODE"], "AL010");
assert.equal(tags["ZSAX_RS0"], "U");
// assert.equal(tags["ZI006_MEM"], "<OSM>{\"source:imagery:sensor\":\"WV02\",\"source:imagery:id\":\"756b80e1f695fb591caca8e7ce0f9ef5\",\"source:imagery:datetime\":\"2017-11-11 10:45:15\"}</OSM>");
assert.equal(tags["OSMTAGS"], "{\"source:imagery:datetime\":\"2017-11-11 10:45:15\",\"source:imagery:id\":\"756b80e1f695fb591caca8e7ce0f9ef5\",\"source:imagery:sensor\":\"WV02\"}");
assert.equal(tags["OTH"], "(FFN:foo)");
assert.equal(tags["UFI"], "0d8b2563-81cf-44d4-8ef7-52c0e862651f");
});
});