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

Adding address unit property to import stream #368

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"pelias-config": "2.13.0",
"pelias-dbclient": "2.2.5",
"pelias-logger": "0.3.0",
"pelias-model": "5.2.0",
"pelias-model": "sweco-semhul/model#adding-address-unit",
"pelias-wof-admin-lookup": "4.1.2",
"through2": "^2.0.0",
"through2-sink": "^1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion schema/address_osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
**/

var OSM_SCHEMA = {
'postal_code': 'zip'
'postal_code': 'zip',
'addr:unit': 'unit'
};

module.exports = OSM_SCHEMA;
11 changes: 9 additions & 2 deletions stream/address_extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,16 @@ module.exports = function(){
peliasLogger.debug('[address_extractor] found multiple house numbers: ', streetnumbers);
}

// If unit is set to an address add it to default name since streetno and street will be the same
var name = [ streetno, doc.address_parts.street ];
if( doc.address_parts.hasOwnProperty('unit') ) {
name.push( doc.address_parts.unit );
}
name = name.join(' ');

// copy data to new document
record = new Document( 'openstreetmap', 'address', newid.join(':') )
.setName( 'default', streetno + ' ' + doc.address_parts.street )
.setName( 'default', name )
.setCentroid( doc.getCentroid() );

setProperties( record, doc );
Expand Down Expand Up @@ -112,7 +119,7 @@ module.exports = function(){
};

// properties to map from the osm record to the pelias doc
var addrProps = [ 'name', 'number', 'street', 'zip' ];
var addrProps = [ 'name', 'unit', 'number', 'street', 'zip' ];

// call document setters and ignore non-fatal errors
function setProperties( record, doc ){
Expand Down
3 changes: 2 additions & 1 deletion test/stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ module.exports.tests.lowercase_keys = function(test, common) {
module.exports.tests.osm_schema = function(test, common) {
test('maps - osm schema', function(t) {
var doc = new Document('a','b',1);
doc.setMeta('tags', { postal_code: 'AAA' });
doc.setMeta('tags', { postal_code: 'AAA', 'addr:unit': 'BBB' });
var stream = mapper();
stream.pipe( through.obj( function( doc, enc, next ){
t.equal(doc.getAddress('zip'), 'AAA', 'correctly mapped');
t.equal(doc.getAddress('unit'), 'BBB', 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
Expand Down