Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override locality and localadmin values from admin lookup #93

Merged
merged 3 commits into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/streams/overrideLookedUpLocalityAndLocaladmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var through2 = require('through2');

// helper function that removes all values at a certain layer and
// reassigns the name and id from the source record
//
// This is important for geonames because what we consider a locality in geonames
// may not be (and probably isn't) the same locality in WOF. For example,
// the geonames locality `Sunnyside` in Lancaster, PA is not in the WOF data so
// when adminlookup happens, it's lat/lon is located in the Lancaster, PA
// WOF locality. This is self-contradictory because now a city is located within
// another city. This logic forces `locality` and `localadmin` records to be
// in agreement since we store the record itself in it's parentage.
function reassignParent(document, layer) {
document.clearParent(layer);
document.addParent(layer, document.getName('default'), document.getId());
}

module.exports.create = function create() {
return through2.obj(function(document, enc, next) {
if (document.getLayer() === 'locality') {
reassignParent(document, 'locality');
}
else if (document.getLayer() === 'localadmin') {
reassignParent(document, 'localadmin');
}

next(null, document);
});
};
2 changes: 2 additions & 0 deletions lib/tasks/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var featureCodeFilterStream = require('../streams/featureCodeFilterStream');
var adminLookupStream = require('../streams/adminLookupStream');
var layerMappingStream = require( '../streams/layerMappingStream');
var peliasDocGenerator = require( '../streams/peliasDocGenerator');
var overrideLookedUpLocalityAndLocaladmin = require('../streams/overrideLookedUpLocalityAndLocaladmin');

module.exports = function( sourceStream, endStream, config ){
endStream = endStream || dbclient();
Expand All @@ -17,6 +18,7 @@ module.exports = function( sourceStream, endStream, config ){
.pipe( layerMappingStream.create() )
.pipe( peliasDocGenerator.create() )
.pipe( adminLookupStream.create(config.imports.geonames.adminLookup) )
.pipe( overrideLookedUpLocalityAndLocaladmin.create() )
.pipe(model.createDocumentMapperStream())
.pipe( endStream );
};
Loading