diff --git a/data/specialCases.json b/data/specialCases.json new file mode 100644 index 00000000..df97ea4d --- /dev/null +++ b/data/specialCases.json @@ -0,0 +1,7 @@ +{ + "5110302": "borough", + "5125771": "borough", + "5133273": "borough", + "5110266": "borough", + "5139568": "borough" +} diff --git a/lib/streams/layerMappingStream.js b/lib/streams/layerMappingStream.js index 05354797..7fbd7317 100644 --- a/lib/streams/layerMappingStream.js +++ b/lib/streams/layerMappingStream.js @@ -1,4 +1,5 @@ var through2 = require('through2'); +var specialID = require('../../data/specialCases'); function featureCodeToLayerDefault(featureCode) { switch (featureCode) { @@ -83,9 +84,13 @@ function featureCodeToLayer(featureCode, countryCode) { } } +function mapIDtoLayer(id){ + return specialID[id]; +} + function create() { return through2.obj(function(data, enc, next) { - data.layer = featureCodeToLayer(data.feature_code, data.country_code); + data.layer = mapIDtoLayer(data._id) || featureCodeToLayer(data.feature_code, data.country_code); next(null, data); }); diff --git a/test/streams/layerMappingStreamTest.js b/test/streams/layerMappingStreamTest.js index 81a1ce42..e13814e9 100644 --- a/test/streams/layerMappingStreamTest.js +++ b/test/streams/layerMappingStreamTest.js @@ -80,3 +80,26 @@ tape('layerMappingStream', function(test) { }); }); }); + +tape('IDtoLayer', function(test){ + test.test('special cases: the nyc boroughs', function(t){ + var input = [ + {_id: 5110302, feature_code: 'PPLA2'}, + {_id: 5125771, feature_code: 'PPLA2'}, + {_id: 5133273, feature_code: 'PPLA2'}, + {_id: 5110266, feature_code: 'PPLA2'}, + {_id: 5139568, feature_code: 'PPLA2'}, + {_id: 5112223, feature_code: 'PPLA'}]; + var stream = layerMappingStream.create(); + + test_stream(input,stream,function(err, results){ + var actual = results.map(function(doc){ + return doc.layer; + }); + var expected = ['borough','borough','borough','borough','borough','locality']; + + test.deepEqual(actual,expected,'special case: NYC handled'); + t.end(); + }); + }); +});