Skip to content

Commit f0a0353

Browse files
authored
Merge pull request #93 from pelias/override-locality-and-localadmin
override `locality` and `localadmin` values from admin lookup
2 parents 8291467 + 5912340 commit f0a0353

File tree

5 files changed

+2695
-236
lines changed

5 files changed

+2695
-236
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var through2 = require('through2');
2+
3+
// helper function that removes all values at a certain layer and
4+
// reassigns the name and id from the source record
5+
//
6+
// This is important for geonames because what we consider a locality in geonames
7+
// may not be (and probably isn't) the same locality in WOF. For example,
8+
// the geonames locality `Sunnyside` in Lancaster, PA is not in the WOF data so
9+
// when adminlookup happens, it's lat/lon is located in the Lancaster, PA
10+
// WOF locality. This is self-contradictory because now a city is located within
11+
// another city. This logic forces `locality` and `localadmin` records to be
12+
// in agreement since we store the record itself in it's parentage.
13+
function reassignParent(document, layer) {
14+
document.clearParent(layer);
15+
document.addParent(layer, document.getName('default'), document.getId());
16+
}
17+
18+
module.exports.create = function create() {
19+
return through2.obj(function(document, enc, next) {
20+
if (document.getLayer() === 'locality') {
21+
reassignParent(document, 'locality');
22+
}
23+
else if (document.getLayer() === 'localadmin') {
24+
reassignParent(document, 'localadmin');
25+
}
26+
27+
next(null, document);
28+
});
29+
};

lib/tasks/import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var featureCodeFilterStream = require('../streams/featureCodeFilterStream');
77
var adminLookupStream = require('../streams/adminLookupStream');
88
var layerMappingStream = require( '../streams/layerMappingStream');
99
var peliasDocGenerator = require( '../streams/peliasDocGenerator');
10+
var overrideLookedUpLocalityAndLocaladmin = require('../streams/overrideLookedUpLocalityAndLocaladmin');
1011

1112
module.exports = function( sourceStream, endStream, config ){
1213
endStream = endStream || dbclient();
@@ -17,6 +18,7 @@ module.exports = function( sourceStream, endStream, config ){
1718
.pipe( layerMappingStream.create() )
1819
.pipe( peliasDocGenerator.create() )
1920
.pipe( adminLookupStream.create(config.imports.geonames.adminLookup) )
21+
.pipe( overrideLookedUpLocalityAndLocaladmin.create() )
2022
.pipe(model.createDocumentMapperStream())
2123
.pipe( endStream );
2224
};

0 commit comments

Comments
 (0)